短信接口示例
主要為大家分享PHP短信接口代碼,PHP短信群發(fā)、PHP短信驗(yàn)證碼發(fā)送,感興趣的小伙伴們可以參考一下。
<?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ì)話(huà) curl_setopt($curl, CURLOPT_URL, $url); // 要訪(fǎng)問(wèn)的地址 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 對(duì)認(rèn)證證書(shū)來(lái)源的檢查 curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模擬用戶(hù)使用的瀏覽器 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ì)話(huà) return $res; // 返回?cái)?shù)據(jù),json格式 } //$account 用戶(hù)賬號(hào) //$pswd 必填參數(shù)。用戶(hù)密碼 //$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)銷(xiāo)短信 3:語(yǔ)音驗(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ù)賬號(hào) //$pswd 必填參數(shù)。用戶(hù)密碼 //$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)銷(xiāo)短信 3:語(yǔ)音驗(yàn)證碼 $send = new SendCode(); $re = $send->send('您的賬號(hào)','您的密碼','手機(jī)號(hào)','短信內(nèi)容',time(),1); print_r($re);