接口文檔

秒賽為開發(fā)者提供了詳細(xì)的API文檔和代碼示例,幫助開發(fā)者快速接入短信平臺(tái)

PHP短信接口_PHP短信發(fā)送代碼示例

2020-03-10 14:50:11 欄目:代碼示例 查看( )
本文分享php短信接口代碼,為方便用戶接入網(wǎng)站/app/各種系統(tǒng),感興趣的小伙伴們可以參考一下。

<?php
 
class SendCode{
    private $url 'http://139.196.108.241:8080';
 
    private function post_curls($url$post)
    {
        $curl = curl_init(); // 啟動(dòng)一個(gè)CURL會(huì)話
        curl_setopt($curl, CURLOPT_URL, $url); // 要訪問的地址
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 對(duì)認(rèn)證證書來源的檢查
        curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模擬用戶使用的瀏覽器
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自動(dòng)跳轉(zhuǎn)
        curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自動(dòng)設(shè)置Referer
        curl_setopt($curl, CURLOPT_POST, 1); // 發(fā)送一個(gè)常規(guī)的Post請(qǐng)求
        curl_setopt($curl, CURLOPT_POSTFIELDS, $post); // Post提交的數(shù)據(jù)包
        curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 設(shè)置超時(shí)限制防止死循環(huán)
        curl_setopt($curl, CURLOPT_HEADER, 0); // 顯示返回的Header區(qū)域內(nèi)容
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 獲取的信息以文件流的形式返回
        $res = curl_exec($curl); // 執(zhí)行操作
        if (curl_errno($curl)) {
            echo 'Errno'.curl_error($curl);//捕抓異常
        }
        curl_close($curl); // 關(guān)閉CURL會(huì)話
        return $res// 返回?cái)?shù)據(jù),json格式
 
    }
 
    //$account 用戶賬號(hào)
    //$pswd 必填參數(shù)。用戶密碼
    //$mobile 必填參數(shù)。合法的手機(jī)號(hào)碼
    //$msg  必填參數(shù)。短信內(nèi)容
    //$ts  可選參數(shù),時(shí)間戳,格式y(tǒng)yyyMMddHHmmss
    //$state 必填參數(shù)   狀態(tài)  1:驗(yàn)證碼短信  2:營(yíng)銷短信  3:語音驗(yàn)證碼
    public function send($account,$pswd,$mobile,$msg,$ts,$state){
        if($ts != ''){
            $pswd = md5($account.$pswd.$ts);
        }
        $url '';
        switch ($state) {
            case 1:
                $url $this->url.'/Api/HttpSendSMYzm.ashx';
                break;
            case 2:
                $url $this->url.'/Api/HttpSendSMYx.ashx';
                break;
            case 3:
                $url $this->url.'/Api/HttpSendSMVoice.ashx';
                break;
            
            default:
                $url '';
                break;
        }
        $data =  array('account' => $account,'pswd'=>$pswd,'mobile'=>$mobile,'msg'=>$msg,'ts'=>$ts); 
        $huawei_res$this->post_curls($url,$data);
        $huawei_res=json_decode($huawei_res,true);
        return $huawei_res ;
 
    }
 
}
 
 
//$account 用戶賬號(hào)
//$pswd 必填參數(shù)。用戶密碼
//$mobile 必填參數(shù)。合法的手機(jī)號(hào)碼
//$msg  必填參數(shù)。短信內(nèi)容
//$ts  可選參數(shù),時(shí)間戳,格式y(tǒng)yyyMMddHHmmss
//$state 必填參數(shù)   狀態(tài)  1:驗(yàn)證碼短信  2:營(yíng)銷短信  3:語音驗(yàn)證碼
 
 
$send new SendCode();
 
$re $send->send('您的賬號(hào)','您的密碼','手機(jī)號(hào)','短信內(nèi)容',time(),1);
 
print_r($re);
微信掃一掃

認(rèn)證、簽名模板審核結(jié)果通知

賬號(hào)短信余額不足提醒

平臺(tái)促銷活動(dòng)及最新資訊

鄭重申明:①任何個(gè)人和或機(jī)構(gòu)在未經(jīng)過本人同意的情況下,不得擅自轉(zhuǎn)載或大段引用到網(wǎng)站或者第三方平臺(tái)使用,對(duì)于擅自盜用文章將通過法律訴訟途徑等一切手段來解決!②部分素材來源于互聯(lián)網(wǎng),如有侵權(quán),請(qǐng)聯(lián)系作者刪除!