1.注册荣联云

https://www.yuntongxun.com/doc.html

2.充钱

3.新增短信模板(只有完成首冲300元才能使用)

4.待审核通过后下载官方给的Demo

5.下载Demo后在放到tp中的extend目录下

我这里把CCPRestSDK和SendTemplateSMS分别改成了REST,SendCode

(注意:这里改不改都行,随你开心)

6.更改REST (注意:我把接口配置都写在函数里了)

你们可以在application/extra中配置自己phone.php

<?php /***发送手机验证码*/return ['accountSid' => "",   //主帐号'accountToken' =>'' , //主帐号Token'appId' => "",         //应用Id           'serverIP' => 'app.cloopen.com',   //请求地址,格式如下,不需要写https://      'serverPort' => '8883',            //请求端口 'softVersion'=>'2013-12-26',       //REST版本号];

配置完phone.php后

下面这个应该都能用,复制就行了,如果不能用那么就恭喜你中奖了

<?php
/**  Copyright (c) 2014 The CCP project authors. All Rights Reserved.**  Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license*  that can be found in the LICENSE file in the root of the web site.**   http://www.yuntongxun.com**  An additional intellectual property rights grant can be found*  in the file PATENTS.  All contributing project authors may*  be found in the AUTHORS file in the root of the source tree.*/
namespace phone;class REST {private $AccountSid;private $AccountToken;private $AppId;private $SubAccountSid;private $SubAccountToken; private $ServerIP;private $ServerPort;private $SoftVersion;private $Batch;  //时间shprivate $BodyType = "xml";//包体格式,可填值:json 、xmlprivate $enabeLog = true; //日志开关。可填值:true、private $Filename="../log.txt"; //日志文件private $Handle; function __construct($ServerIP,$ServerPort,$SoftVersion)  {$this->Batch = date("YmdHis");$this->ServerIP = config('phone.serverIP');             //请求地址$this->ServerPort = config('phone.serverPort');         //请求端口 $this->SoftVersion = config('phone.softVersion');       //REST版本号$this->Handle = fopen($this->Filename, 'a');}/*** 设置主帐号* * @param AccountSid 主帐号* @param AccountToken 主帐号Token*/    function setAccount($AccountSid,$AccountToken){$this->AccountSid = config('phone.accountSid');         //你的主帐号$this->AccountToken = config('phone.accountToken');    //你的主帐号Token}/*** 设置子帐号* * @param SubAccountSid 子帐号* @param SubAccountToken 子帐号Token*/    function setSubAccount($SubAccountSid,$SubAccountToken){$this->SubAccountSid = $SubAccountSid;$this->SubAccountToken = $SubAccountToken;    }/*** 设置应用ID* * @param AppId 应用ID*/function setAppId($AppId){$this->AppId = config('phone.appId');    //你的应用ID}/*** 打印日志* * @param log 日志内容*/function showlog($log){if($this->enabeLog){fwrite($this->Handle,$log."\n");  }}/*** 发起HTTPS请求*/function curl_post($url,$data,$header,$post=1){//初始化curl$ch = curl_init();//参数设置  $res= curl_setopt ($ch, CURLOPT_URL,$url);  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);curl_setopt ($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_POST, $post);if($post)curl_setopt($ch, CURLOPT_POSTFIELDS, $data);curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch,CURLOPT_HTTPHEADER,$header);$result = curl_exec ($ch);//连接失败if($result == FALSE){if($this->BodyType=='json'){$result = "{\"statusCode\":\"172001\",\"statusMsg\":\"网络错误\"}";} else {$result = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Response><statusCode>172001</statusCode><statusMsg>网络错误</statusMsg></Response>"; }    }curl_close($ch);return $result;} /*** 创建子帐号* @param friendlyName 子帐号名称*/function createSubAccount($friendlyName){//主帐号鉴权信息验证,对必选参数进行判空。$auth=$this->accAuth();if($auth!=""){return $auth;}// 拼接请求包体if($this->BodyType=="json"){$body= "{'appId':'$this->AppId','friendlyName':'$friendlyName'}";}else{$body="<SubAccount><appId>$this->AppId</appId><friendlyName>$friendlyName</friendlyName></SubAccount>";}$this->showlog("request body = ".$body);// 大写的sig参数  $sig =  strtoupper(md5($this->AccountSid . $this->AccountToken . $this->Batch));// 生成请求URL$url="https://$this->ServerIP:$this->ServerPort/$this->SoftVersion/Accounts/$this->AccountSid/SubAccounts?sig=$sig";$this->showlog("request url = ".$url);// 生成授权:主帐号Id + 英文冒号 + 时间戳$authen = base64_encode($this->AccountSid . ":" . $this->Batch);// 生成包头 $header = array("Accept:application/$this->BodyType","Content-Type:application/$this->BodyType;charset=utf-8","Authorization:$authen");// 发请求$result = $this->curl_post($url,$body,$header);$this->showlog("response body = ".$result);if($this->BodyType=="json"){//JSON格式$datas=json_decode($result); }else{ //xml格式$datas = simplexml_load_string(trim($result," \t\n\r"));}//  if($datas == FALSE){
//            $datas = new \stdClass();
//            $datas->statusCode = '172003';
//            $datas->statusMsg = '返回包体错误';
//        }return $datas;}/*** 获取子帐号* @param startNo 开始的序号,默认从0开始* @param offset 一次查询的最大条数,最小是1条,最大是100条*/function getSubAccounts($startNo,$offset){   //主帐号鉴权信息验证,对必选参数进行判空。$auth=$this->accAuth();if($auth!=""){return $auth;}// 拼接请求包体$body="<SubAccount><appId>$this->AppId</appId><startNo>$startNo</startNo>  <offset>$offset</offset></SubAccount>";if($this->BodyType=="json"){$body= "{'appId':'$this->AppId','startNo':'$startNo','offset':'$offset'}";}else{$body="<SubAccount><appId>$this->AppId</appId><startNo>$startNo</startNo>  <offset>$offset</offset></SubAccount>";}$this->showlog("request body = ".$body);// 大写的sig参数  $sig =  strtoupper(md5($this->AccountSid . $this->AccountToken . $this->Batch));// 生成请求URL$url="https://$this->ServerIP:$this->ServerPort/$this->SoftVersion/Accounts/$this->AccountSid/GetSubAccounts?sig=$sig";$this->showlog("request url = ".$url);// 生成授权:主帐户Id + 英文冒号 + 时间戳。$authen = base64_encode($this->AccountSid . ":" . $this->Batch);// 生成包头 $header = array("Accept:application/$this->BodyType","Content-Type:application/$this->BodyType;charset=utf-8","Authorization:$authen");// 发送请求$result = $this->curl_post($url,$body,$header);$this->showlog("response body = ".$result);if($this->BodyType=="json"){//JSON格式$datas=json_decode($result); }else{ //xml格式$datas = simplexml_load_string(trim($result," \t\n\r"));}//  if($datas == FALSE){
//            $datas = new \stdClass();
//            $datas->statusCode = '172003';
//            $datas->statusMsg = '返回包体错误';
//        }return $datas;}/*** 子帐号信息查询* @param friendlyName 子帐号名称*/function querySubAccount($friendlyName){//主帐号鉴权信息验证,对必选参数进行判空。$auth=$this->accAuth();if($auth!=""){return $auth;}// 拼接请求包体if($this->BodyType=="json"){$body= "{'appId':'$this->AppId','friendlyName':'$friendlyName'}";}else{$body="<SubAccount><appId>$this->AppId</appId><friendlyName>$friendlyName</friendlyName></SubAccount>";}$this->showlog("request body = ".$body);// 大写的sig参数  $sig =  strtoupper(md5($this->AccountSid . $this->AccountToken . $this->Batch));// 生成请求URL$url="https://$this->ServerIP:$this->ServerPort/$this->SoftVersion/Accounts/$this->AccountSid/QuerySubAccountByName?sig=$sig";$this->showlog("request url = ".$url);// 生成授权:主帐户Id + 英文冒号 + 时间戳。$authen = base64_encode($this->AccountSid . ":" . $this->Batch);// 生成包头 $header = array("Accept:application/$this->BodyType","Content-Type:application/$this->BodyType;charset=utf-8","Authorization:$authen");// 发送请求$result = $this->curl_post($url,$body,$header);$this->showlog("response body = ".$result);if($this->BodyType=="json"){//JSON格式$datas=json_decode($result); }else{ //xml格式$datas = simplexml_load_string(trim($result," \t\n\r"));}//  if($datas == FALSE){
//            $datas = new \stdClass();
//            $datas->statusCode = '172003';
//            $datas->statusMsg = '返回包体错误';
//        }return $datas; }/*** 发送模板短信* @param to 短信接收彿手机号码集合,用英文逗号分开* @param datas 内容数据* @param $tempId 模板Id*/       function sendTemplateSMS($to,$datas,$tempId){//主帐号鉴权信息验证,对必选参数进行判空。$auth=$this->accAuth();if($auth!=""){return $auth;}// 拼接请求包体if($this->BodyType=="json"){$data="";for($i=0;$i<count($datas);$i++){$data = $data. "'".$datas[$i]."',"; }$body= "{'to':'$to','templateId':'$tempId','appId':'$this->AppId','datas':[".$data."]}";}else{$data="";for($i=0;$i<count($datas);$i++){$data = $data. "<data>".$datas[$i]."</data>"; }$body="<TemplateSMS><to>$to</to> <appId>$this->AppId</appId><templateId>$tempId</templateId><datas>".$data."</datas></TemplateSMS>";}$this->showlog("request body = ".$body);// 大写的sig参数 $sig =  strtoupper(md5($this->AccountSid . $this->AccountToken . $this->Batch));// 生成请求URL        $url="https://$this->ServerIP:$this->ServerPort/$this->SoftVersion/Accounts/$this->AccountSid/SMS/TemplateSMS?sig=$sig";$this->showlog("request url = ".$url);// 生成授权:主帐户Id + 英文冒号 + 时间戳。$authen = base64_encode($this->AccountSid . ":" . $this->Batch);// 生成包头  $header = array("Accept:application/$this->BodyType","Content-Type:application/$this->BodyType;charset=utf-8","Authorization:$authen");// 发送请求$result = $this->curl_post($url,$body,$header);$this->showlog("response body = ".$result);if($this->BodyType=="json"){//JSON格式$datas=json_decode($result); }else{ //xml格式$datas = simplexml_load_string(trim($result," \t\n\r"));}//  if($datas == FALSE){
//            $datas = new \stdClass();
//            $datas->statusCode = '172003';
//            $datas->statusMsg = '返回包体错误';
//        }//重新装填数据if($datas->statusCode==0){if($this->BodyType=="json"){$datas->TemplateSMS =$datas->templateSMS;unset($datas->templateSMS);   }}return $datas; } /*** 外呼通知* @param to 被叫号码* @param mediaName 语音文件名称,格式 wav。与mediaTxt不能同时为空。当不为空时mediaTxt属性失效。* @param mediaTxt 文本内容* @param displayNum 显示的主叫号码* @param playTimes 循环播放次数,1-3次,默认播放1次。* @param respUrl 外呼通知状态通知回调地址,云通讯平台将向该Url地址发送呼叫结果通知。* @param userData 用户私有数据* @param maxCallTime 最大通话时长* @param speed 发音速度* @param volume 音量* @param pitch 音调* @param bgsound 背景音编号*/function landingCall($to,$mediaName,$mediaTxt,$displayNum,$playTimes,$respUrl,$userData,$maxCallTime,$speed,$volume,$pitch,$bgsound){   //主帐号鉴权信息验证,对必选参数进行判空。$auth=$this->accAuth();if($auth!=""){return $auth;} // 拼接请求包体if($this->BodyType=="json"){$body= "{'playTimes':'$playTimes','mediaTxt':'$mediaTxt','mediaName':'$mediaName','to':'$to','appId':'$this->AppId','displayNum':'$displayNum','respUrl':'$respUrl','userData':'$userData','maxCallTime':'$maxCallTime','speed':'$speed','volume':'$volume','pitch':'$pitch','bgsound':'$bgsound'}";}else{$body="<LandingCall><to>$to</to><mediaName>$mediaName</mediaName><mediaTxt>$mediaTxt</mediaTxt> <appId>$this->AppId</appId><displayNum>$displayNum</displayNum><playTimes>$playTimes</playTimes><respUrl>$respUrl</respUrl><userData>$userData</userData><maxCallTime>$maxCallTime</maxCallTime><speed>$speed</speed><volume>$volume</volume><pitch>$pitch</pitch><bgsound>$bgsound</bgsound></LandingCall>";}$this->showlog("request body = ".$body);// 大写的sig参数$sig =  strtoupper(md5($this->AccountSid . $this->AccountToken . $this->Batch));// 生成请求URL  $url="https://$this->ServerIP:$this->ServerPort/$this->SoftVersion/Accounts/$this->AccountSid/Calls/LandingCalls?sig=$sig";$this->showlog("request url = ".$url);// 生成授权:主帐户Id + 英文冒号 + 时间戳。$authen = base64_encode($this->AccountSid . ":" . $this->Batch);// 生成包头  $header = array("Accept:application/$this->BodyType","Content-Type:application/$this->BodyType;charset=utf-8","Authorization:$authen");// 发送请求$result = $this->curl_post($url,$body,$header);$this->showlog("response body = ".$result);if($this->BodyType=="json"){//JSON格式$datas=json_decode($result); }else{ //xml格式$datas = simplexml_load_string(trim($result," \t\n\r"));}//  if($datas == FALSE){
//            $datas = new \stdClass();
//            $datas->statusCode = '172003';
//            $datas->statusMsg = '返回包体错误';
//        }return $datas;}/*** 语音验证码* @param verifyCode 验证码内容,为数字和英文字母,不区分大小写,长度4-8位* @param playTimes 播放次数,1-3次* @param to 接收号码* @param displayNum 显示的主叫号码* @param respUrl 语音验证码状态通知回调地址,云通讯平台将向该Url地址发送呼叫结果通知* @param lang 语言类型* @param userData 第三方私有数据*/function voiceVerify($verifyCode,$playTimes,$to,$displayNum,$respUrl,$lang,$userData){//主帐号鉴权信息验证,对必选参数进行判空。$auth=$this->accAuth();if($auth!=""){return $auth;}// 拼接请求包体if($this->BodyType=="json"){$body= "{'appId':'$this->AppId','verifyCode':'$verifyCode','playTimes':'$playTimes','to':'$to','respUrl':'$respUrl','displayNum':'$displayNum','lang':'$lang','userData':'$userData'}";}else{$body="<VoiceVerify><appId>$this->AppId</appId><verifyCode>$verifyCode</verifyCode><playTimes>$playTimes</playTimes><to>$to</to><respUrl>$respUrl</respUrl><displayNum>$displayNum</displayNum><lang>$lang</lang><userData>$userData</userData></VoiceVerify>";}$this->showlog("request body = ".$body);// 大写的sig参数$sig =  strtoupper(md5($this->AccountSid . $this->AccountToken . $this->Batch));// 生成请求URL  $url="https://$this->ServerIP:$this->ServerPort/$this->SoftVersion/Accounts/$this->AccountSid/Calls/VoiceVerify?sig=$sig";$this->showlog("request url = ".$url);// 生成授权:主帐户Id + 英文冒号 + 时间戳。$authen = base64_encode($this->AccountSid . ":" . $this->Batch);// 生成包头  $header = array("Accept:application/$this->BodyType","Content-Type:application/$this->BodyType;charset=utf-8","Authorization:$authen");// 发送请求$result = $this->curl_post($url,$body,$header);$this->showlog("response body = ".$result);if($this->BodyType=="json"){//JSON格式$datas=json_decode($result); }else{ //xml格式$datas = simplexml_load_string(trim($result," \t\n\r"));}//  if($datas == FALSE){
//            $datas = new \stdClass();
//            $datas->statusCode = '172003';
//            $datas->statusMsg = '返回包体错误';
//        }return $datas;}/*** IVR外呼* @param number   待呼叫号码,为Dial节点的属性* @param userdata 用户数据,在<startservice>通知中返回,只允许填写数字字符,为Dial节点的属性* @param record   是否录音,可填项为true和false,默认值为false不录音,为Dial节点的属性*/function ivrDial($number,$userdata,$record){//主帐号鉴权信息验证,对必选参数进行判空。$auth=$this->accAuth();if($auth!=""){return $auth;} // 拼接请求包体$body=" <Request><Appid>$this->AppId</Appid><Dial number='$number'  userdata='$userdata' record='$record'></Dial></Request>";$this->showlog("request body = ".$body);// 大写的sig参数$sig =  strtoupper(md5($this->AccountSid . $this->AccountToken . $this->Batch));// 生成请求URL  $url="https://$this->ServerIP:$this->ServerPort/$this->SoftVersion/Accounts/$this->AccountSid/ivr/dial?sig=$sig";$this->showlog("request url = ".$url);// 生成授权:主帐户Id + 英文冒号 + 时间戳。$authen = base64_encode($this->AccountSid . ":" . $this->Batch);// 生成包头  $header = array("Accept:application/xml","Content-Type:application/xml;charset=utf-8","Authorization:$authen");// 发送请求$result = $this->curl_post($url,$body,$header);$this->showlog("response body = ".$result);$datas = simplexml_load_string(trim($result," \t\n\r"));//  if($datas == FALSE){
//            $datas = new \stdClass();
//            $datas->statusCode = '172003';
//            $datas->statusMsg = '返回包体错误';
//        }return $datas;}/*** 话单下载* @param date     day 代表前一天的数据(从00:00 – 23:59)* @param keywords   客户的查询条件,由客户自行定义并提供给云通讯平台。默认不填忽略此参数*/function billRecords($date,$keywords){//主帐号鉴权信息验证,对必选参数进行判空。$auth=$this->accAuth();if($auth!=""){return $auth;}// 拼接请求包体if($this->BodyType=="json"){$body= "{'appId':'$this->AppId','date':'$date','keywords':'$keywords'}";}else{$body="<BillRecords><appId>$this->AppId</appId><date>$date</date><keywords>$keywords</keywords></BillRecords>";}$this->showlog("request body = ".$body);// 大写的sig参数$sig =  strtoupper(md5($this->AccountSid . $this->AccountToken . $this->Batch));// 生成请求URL  $url="https://$this->ServerIP:$this->ServerPort/$this->SoftVersion/Accounts/$this->AccountSid/BillRecords?sig=$sig";$this->showlog("request url = ".$url);// 生成授权:主帐户Id + 英文冒号 + 时间戳。$authen = base64_encode($this->AccountSid . ":" . $this->Batch);// 生成包头  $header = array("Accept:application/$this->BodyType","Content-Type:application/$this->BodyType;charset=utf-8","Authorization:$authen");// 发送请求$result = $this->curl_post($url,$body,$header);$this->showlog("response body = ".$result);if($this->BodyType=="json"){//JSON格式$datas=json_decode($result); }else{ //xml格式$datas = simplexml_load_string(trim($result," \t\n\r"));}//  if($datas == FALSE){
//            $datas = new \stdClass();
//            $datas->statusCode = '172003';
//            $datas->statusMsg = '返回包体错误';
//        }return $datas; } /*** 主帐号信息查询*/function queryAccountInfo(){//主帐号鉴权信息验证,对必选参数进行判空。$auth=$this->accAuth();if($auth!=""){return $auth;}// 大写的sig参数$sig =  strtoupper(md5($this->AccountSid . $this->AccountToken . $this->Batch));// 生成请求URL  $url="https://$this->ServerIP:$this->ServerPort/$this->SoftVersion/Accounts/$this->AccountSid/AccountInfo?sig=$sig";$this->showlog("request url = ".$url);// 生成授权:主帐户Id + 英文冒号 + 时间戳。$authen = base64_encode($this->AccountSid . ":" . $this->Batch);// 生成包头  $header = array("Accept:application/$this->BodyType","Content-Type:application/$this->BodyType;charset=utf-8","Authorization:$authen");// 发送请求$result = $this->curl_post($url,"",$header,0);$this->showlog("response body = ".$result);if($this->BodyType=="json"){//JSON格式$datas=json_decode($result); }else{ //xml格式$datas = simplexml_load_string(trim($result," \t\n\r"));}//  if($datas == FALSE){
//            $datas = new \stdClass();
//            $datas->statusCode = '172003';
//            $datas->statusMsg = '返回包体错误';
//        }return $datas;  }/*** 短信模板查询* @param date     templateId 模板ID*/function QuerySMSTemplate($templateId){//主帐号鉴权信息验证,对必选参数进行判空。$auth=$this->accAuth();if($auth!=""){return $auth;}// 拼接请求包体if($this->BodyType=="json"){$body= "{'appId':'$this->AppId','templateId':'$templateId'}";}else{$body="<Request><appId>$this->AppId</appId><templateId>$templateId</templateId>  </Request>";}$this->showlog("request body = ".$body);// 大写的sig参数$sig =  strtoupper(md5($this->AccountSid . $this->AccountToken . $this->Batch));// 生成请求URL  $url="https://$this->ServerIP:$this->ServerPort/$this->SoftVersion/Accounts/$this->AccountSid/SMS/QuerySMSTemplate?sig=$sig";$this->showlog("request url = ".$url);// 生成授权:主帐户Id + 英文冒号 + 时间戳。$authen = base64_encode($this->AccountSid . ":" . $this->Batch);// 生成包头  $header = array("Accept:application/$this->BodyType","Content-Type:application/$this->BodyType;charset=utf-8","Authorization:$authen");// 发送请求$result = $this->curl_post($url,$body,$header); $this->showlog("response body = ".$result);if($this->BodyType=="json"){//JSON格式$datas=json_decode($result); }else{ //xml格式 $datas = simplexml_load_string(trim($result," \t\n\r"));}//  if($datas == FALSE){
//            $datas = new \stdClass();
//            $datas->statusCode = '172003';
//            $datas->statusMsg = '返回包体错误';
//        }return $datas; }/*** 呼叫状态查询* @param callid     呼叫Id * @param action   查询结果通知的回调url地址 */function QueryCallState($callid,$action){//主帐号鉴权信息验证,对必选参数进行判空。$auth=$this->accAuth();if($auth!=""){return $auth;}// 拼接请求包体if($this->BodyType=="json"){$body= "{'Appid':'$this->AppId','QueryCallState':{'callid':'$callid','action':'$action'}}";}else{$body="<Request><Appid>$this->AppId</Appid><QueryCallState callid ='$callid' action='$action'/></Request>";}$this->showlog("request body = ".$body);// 大写的sig参数$sig =  strtoupper(md5($this->AccountSid . $this->AccountToken . $this->Batch));// 生成请求URL  $url="https://$this->ServerIP:$this->ServerPort/$this->SoftVersion/Accounts/$this->AccountSid/ivr/call?sig=$sig&callid=$callid";$this->showlog("request url = ".$url);// 生成授权:主帐户Id + 英文冒号 + 时间戳。$authen = base64_encode($this->AccountSid . ":" . $this->Batch);// 生成包头  $header = array("Accept:application/$this->BodyType","Content-Type:application/$this->BodyType;charset=utf-8","Authorization:$authen");// 发送请求$result = $this->curl_post($url,$body,$header);$this->showlog("response body = ".$result);if($this->BodyType=="json"){//JSON格式$datas=json_decode($result); }else{ //xml格式$datas = simplexml_load_string(trim($result," \t\n\r"));}//  if($datas == FALSE){
//            $datas = new \stdClass();
//            $datas->statusCode = '172003';
//            $datas->statusMsg = '返回包体错误';
//        }return $datas; } /*** 呼叫结果查询* @param callSid     呼叫Id*/function CallResult($callSid){//主帐号鉴权信息验证,对必选参数进行判空。$auth=$this->accAuth();if($auth!=""){return $auth;}// 大写的sig参数$sig =  strtoupper(md5($this->AccountSid . $this->AccountToken . $this->Batch));// 生成请求URL  $url="https://$this->ServerIP:$this->ServerPort/$this->SoftVersion/Accounts/$this->AccountSid/CallResult?sig=$sig&callsid=$callSid";$this->showlog("request url = ".$url);// 生成授权:主帐户Id + 英文冒号 + 时间戳。$authen = base64_encode($this->AccountSid . ":" . $this->Batch);// 生成包头  $header = array("Accept:application/$this->BodyType","Content-Type:application/$this->BodyType;charset=utf-8","Authorization:$authen");// 发送请求$result = $this->curl_post($url,"",$header,0);$this->showlog("response body = ".$result);if($this->BodyType=="json"){//JSON格式$datas=json_decode($result); }else{ //xml格式$datas = simplexml_load_string(trim($result," \t\n\r"));}//  if($datas == FALSE){
//            $datas = new \stdClass();
//            $datas->statusCode = '172003';
//            $datas->statusMsg = '返回包体错误';
//        }return $datas;  }/*** 语音文件上传* @param filename     文件名* @param body   二进制串*/function MediaFileUpload($filename,$body){                      //主帐号鉴权信息验证,对必选参数进行判空。$auth=$this->accAuth();if($auth!=""){return $auth;}// 拼接请求包体$this->showlog("request body = ".$body);// 大写的sig参数$sig =  strtoupper(md5($this->AccountSid . $this->AccountToken . $this->Batch));// 生成请求URL  $url="https://$this->ServerIP:$this->ServerPort/$this->SoftVersion/Accounts/$this->AccountSid/Calls/MediaFileUpload?sig=$sig&appid=$this->AppId&filename=$filename";$this->showlog("request url = ".$url);// 生成授权:主帐户Id + 英文冒号 + 时间戳。$authen = base64_encode($this->AccountSid . ":" . $this->Batch);// 生成包头  $header = array("Accept:application/$this->BodyType","Content-Type:application/octet-stream","Authorization:$authen");// 发送请求$result = $this->curl_post($url,$body,$header);$this->showlog("response body = ".$result);if($this->BodyType=="json"){//JSON格式$datas=json_decode($result); }else{ //xml格式$datas = simplexml_load_string(trim($result," \t\n\r"));}//  if($datas == FALSE){
//            $datas = new \stdClass();
//            $datas->statusCode = '172003';
//            $datas->statusMsg = '返回包体错误';
//        }return $datas; } /*** 子帐号鉴权*/   function subAuth(){if($this->ServerIP==""){$data = new \stdClass();$data->statusCode = '172004';$data->statusMsg = 'serverIP为空';return $data;}if($this->ServerPort<=0){$data = new \stdClass();$data->statusCode = '172005';$data->statusMsg = '端口错误(小于等于0)';return $data;}if($this->SoftVersion==""){$data = new \stdClass();$data->statusCode = '172013';$data->statusMsg = '版本号为空';return $data;} if($this->SubAccountSid==""){$data = new \stdClass();$data->statusCode = '172008';$data->statusMsg = '子帐号为空';return $data;}if($this->SubAccountToken==""){$data = new \stdClass();$data->statusCode = '172009';$data->statusMsg = '子帐号令牌为空';return $data;}if($this->AppId==""){$data = new \stdClass();$data->statusCode = '172012';$data->statusMsg = '应用ID为空';return $data;}  }/*** 主帐号鉴权*/   function accAuth(){if($this->ServerIP==""){$data = new \stdClass();$data->statusCode = '172004';$data->statusMsg = 'serverIP为空';return $data;}if($this->ServerPort<=0){$data = new \stdClass();$data->statusCode = '172005';$data->statusMsg = '端口错误(小于等于0)';return $data;}if($this->SoftVersion==""){$data = new \stdClass();$data->statusCode = '172013';$data->statusMsg = '版本号为空';return $data;} if($this->AccountSid==""){$data = new \stdClass();$data->statusCode = '172006';$data->statusMsg = '主帐号为空';return $data;}if($this->AccountToken==""){$data = new \stdClass();$data->statusCode = '172007';$data->statusMsg = '主帐号令牌为空';return $data;}if($this->AppId==""){$data = new \stdClass();$data->statusCode = '172012';$data->statusMsg = '应用ID为空';return $data;}   }
}
?>

7.调用接口

引用 use phone\SendCode;

 //短信发送接口public function fsyz(){      //ajax获取手机号$data =  input('post.');// $phone = $data['phone'];$aaa= array_keys($data);$phone = $aaa['0'];//查询数据库里是否有该用户$zlm = Db::name('timephone')->where('phone', '=', $phone)->select();//如果有返回该手机已被注册if($zlm == true){return 3;}//生成验证码$code = '';$aaa = '1234567890';$len = strlen($aaa)-1;for ($i=0;$i<6;++$i){$code .= $aaa[mt_rand(0,$len)];}$data = [];$data['phone'] =$phone; $data['code'] =$code; $data['time']= date('Y-m-d H-i-s',time()+ 60*60);$aa = new SendCode;//总共三个参数 手机号,验证码60是有效时间,短信模板id$aa->sendTemplateSMS("$phone",array($code,'60'),"1");$add =  model('Timephone')->add($data);if($add){return 1;}else{return 2;}}

ThinkPHP5.0 中使用荣联云通讯相关推荐

  1. python荣联云通讯短信平台

    荣联云通讯短信平台 注册账号 管理模块>>应用管理>>创建应用>>编辑应用>>勾选短信验证码 安装 requests 模块 pip install re ...

  2. python控制手机发短信_python-在python3中使用容联云通讯发送短信验证码

    2020-08-15更新 今天进容联云官网发现其已经更新了最新版的Python SDK,可以直接 pip install ronglian_sms_sdk 即可安装使用,具体新的使用方法可以查看官网案 ...

  3. 荣联 云通讯 发送短信通知 node

    嗯,明明有阿里短信,非要搞这个. 官网提供参考demo,只有java.php.net. Python.C#. 没有node, api能有node demo 比较少,很想回归java, 接口使用的参数: ...

  4. laravel+容联.云通讯 实现手机短信验证用户注册

    Laravel框架简介: Laravel是一套简洁.优雅的PHP Web开发框架(PHP Web Framework).它可以让你从面条一样杂乱的代码中解脱出来:它可以帮你构建一个完美的网络APP,而 ...

  5. 荣联云发送短信验证码--python3接口

    前言 近期做网页注册需要用到发送验证码功能,于是用荣联云的发送短信验证码进行测试,官网上提供的demo是python2.7的,而目前都使用的python3了,而且demo中的代码太长了,我只取demo ...

  6. android点对点 sdk,Client(SDK)_开发文档_容联云通讯

    Demo & SDK下载 云通讯平台为开发者提供多语言Demo,让您可以轻松地选择你熟悉的编程语言来体验.以下是官方提供的Demo,这些Demo都是开源的,如果你发现错误,我们欢迎你的反馈,同 ...

  7. 容联云通讯—+springboot

    小编下午无事捣鼓了一下短信通讯 小编选择了小众品牌容联云,一条消息只要0.06元,注册免费赠送8元 不说废话了开始吧, springboot整合容联云其实非常的简单,因为容联云官方已经将文档SDK都写 ...

  8. 容联云通讯短信平台JS调用

    容联云通讯官网 1.注册 注册成功之后,会赠送8元进行测试 记录账号信息用于代码中配置 添加测试号码用于测试 2.接口配置(js) var md5 = require('blueimp-md5') v ...

  9. 容联云通讯的学习笔记一

    容联云通讯demo下载 1.登陆类LoginActivity,一个界面,没有太多解释 2.初始化及登陆 ✾ 在程序入口初始化SDK并设置代理-初始化应该在程序完全启动(Android Applicat ...

最新文章

  1. Cloud Foundry 登录 Azure,一键快速部署 PaaS
  2. 预告:DIY大宝剑,大宝剑一号 ——DLGG的炽炎长剑
  3. mysql创建数据库指定字符集
  4. 转--javascript 数组
  5. 限制文本框中只能输入数字(+,-)的正则表达式写法
  6. VMware16虚拟机怎么共享文件夹?
  7. android:configChanges属性
  8. 电子邮件.NET控件MailBee.NET Objects v11.1发布丨附下载
  9. SQL Server 中字符串中包含字符串变量的表示方法
  10. 关于C和C++中的基本数据类型int、long、long long、float、double、char、string的大小及表示范围
  11. stm32 带通滤波器_带通滤波器详解_带通滤波器工作原理_带通滤波器原理图
  12. UE5 Metahuman使用Live Link Face动画不匹配的问题修复
  13. 高德地图加载不出来,有高德的logo,但地图一片空白
  14. 俄罗斯方块游戏算法分析
  15. 两台电脑无线连接的办法
  16. java web 实践项目(搭建web留言系统)
  17. List Group By 用法
  18. 神兽传说1 java_神兽传说RPG
  19. 华为认证网络工程师认证考试笔试题
  20. html中第二行标签之间间隔不一样,Word第一行字和第二行字之间的间距怎么不一样...

热门文章

  1. hashmap头插法和尾插法区别
  2. POJ 1265 Area
  3. 松鼠分松果解题 c++
  4. latex解决存在/任意/非符号如何打
  5. openCV5-Threshold and Mask
  6. java sqlserver 插入数据_java中怎样向SQLserver中插入数据
  7. 二分(二分查找,二分搜索)
  8. 极客算法训练笔记(六),十大经典排序之希尔排序,快速排序
  9. ECMAScript 2019(ES10) 的新特性总结
  10. 网络设备选型之路由器