php調用云片網接口發送短信的實現方法
云片網發送短信
/** * [SendSms description] * @param [string] $tpl_content [發送的短信內容] * @param $send_mobile [發送的手機號碼] */ public function SendSms($tpl_content,$send_mobile) { $this->yunpian_appkey = env('yunpian_appkey');//云片賬戶appkey $this->yunpian_secret = env('yunpianSecretXYZ');//云片賬戶secret //初始化 $ch = curl_init(); $data=array('text'=>$tpl_content,'apikey'=>$this->yunpian_appkey,'mobile'=>$send_mobile); curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/single_send.json'); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8', 'Content-Type:application/x-www-form-urlencoded', 'charset=utf-8')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); $send_data = curl_exec($ch); curl_close($ch); //解析返回結果(json格式字符串) $backmassage = json_decode($send_data,true); echo '$backmassage '; //這里是寫在了job里面所以記了個日志可忽略! Log::info('smsmessagelog: '.$send_data); return [$backmassage,$send_data]; }
云片短信接口文檔:http://www.yunpian.com/api2.0/api-domestic/single_send.html
如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
【網站聲明】本站除付費源碼經過測試外,其他素材未做測試,不保證完整性,網站上部分源碼僅限學習交流,請勿用于商業用途。如損害你的權益請聯系客服QQ:2655101040 給予處理,謝謝支持。