首頁 >後端開發 >php教程 >253簡訊介面PHP直接調用

253簡訊介面PHP直接調用

不言
不言原創
2018-04-26 11:18:202497瀏覽

這篇文章介紹的內容是關於253短信接口PHP直接調用,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下

<?php
//namespace Vendor\Sms;
class Sms{  
   
    
      private  $API_SEND_URL=&#39;http://smssh1.253.com/msg/send/&#39;;
      private  $API_ACCOUNT=&#39;C0543&#39;;
      private  $API_PASSWORD=&#39;ItFBqxd2ed&#39;;
     
     
     public function __construct(){    
    }  
     function sendSMS($mobile,$msg,$need_status = 1){

        //发送短信的接口参数
        $post_data = array (
            &#39;un&#39; => $this->API_ACCOUNT,
            &#39;pw&#39; =>  $this->API_PASSWORD,
            &#39;msg&#39; => $msg,
            &#39;phone&#39; => $mobile,
            &#39;rd&#39; => $need_status
        );

        $result = $this->curl_post($this->API_SEND_URL,http_build_query($post_data));

        $result=preg_split("/[,\r\n]/",$result);
        return $result;
    }

     function send_state($state){
        //返回的状态码
        $statusStr = array(
            &#39;0&#39; =>&#39;发送成功&#39;,
            &#39;101&#39;=>&#39;无此用户&#39;,
            &#39;102&#39;=>&#39;密码错&#39;,
            &#39;103&#39;=>&#39;提交过快&#39;,
            &#39;104&#39;=>&#39;系统忙&#39;,
            &#39;105&#39;=>&#39;敏感短信&#39;,
            &#39;106&#39;=>&#39;消息长度错&#39;,
            &#39;107&#39;=>&#39;错误的手机号码&#39;,
            &#39;108&#39;=>&#39;手机号码个数错&#39;,
            &#39;109&#39;=>&#39;无发送额度&#39;,
            &#39;110&#39;=>&#39;不在发送时间内&#39;,
            &#39;111&#39;=>&#39;超出该账户当月发送额度限制&#39;,
            &#39;112&#39;=>&#39;无此产品&#39;,
            &#39;113&#39;=>&#39;extno格式错&#39;,
            &#39;115&#39;=>&#39;自动审核驳回&#39;,
            &#39;116&#39;=>&#39;签名不合法,未带签名&#39;,
            &#39;117&#39;=>&#39;IP地址认证错&#39;,
            &#39;118&#39;=>&#39;用户没有相应的发送权限&#39;,
            &#39;119&#39;=>&#39;用户已过期&#39;,
            &#39;120&#39;=>&#39;内容不是白名单&#39;,
            &#39;121&#39;=>&#39;必填参数。是否需要状态报告,取值true或false&#39;,
            &#39;122&#39;=>&#39;5分钟内相同账号提交相同消息内容过多&#39;,
            &#39;123&#39;=>&#39;发送类型错误(账号发送短信接口权限)&#39;,
            &#39;124&#39;=>&#39;白模板匹配错误&#39;,
            &#39;125&#39;=>&#39;驳回模板匹配错误&#39;,
            &#39;128&#39;=>&#39;内容解码失败&#39;
        );
        return $statusStr[$state];
    }

    function curl_post($url, $post_data) {
        $ch = curl_init();
        $timeout = 300;
        curl_setopt($ch, CURLOPT_URL, $url);
        //curl_setopt($ch, CURLOPT_REFERER, "http://api.dushiyangguan.com/"); 
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER[&#39;HTTP_USER_AGENT&#39;]);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
          curl_setopt( $ch, CURLOPT_TIMEOUT,$timeout); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        // curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $res = curl_exec($ch);
        if (curl_errno($ch)) {
            echo &#39;Curl error: &#39; . curl_error($ch);
        }
        curl_close($ch);
        return $res;
    }
    
}

相關推薦:

PHP呼叫Google翻譯的程式類別

PHP呼叫其他檔案中的類別

用php呼叫so庫檔案中的程式碼

以上是253簡訊介面PHP直接調用的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn