thinkphp5阿里大于短信接口

function autumn_sendsms($tel,$stype){


$pd_go=true;

if($tel==''){
$msg='手机号不能为空';
$pd_go=false;
}


if($stype==''){
$msg='类型不能为空';
$pd_go=false;
}
// if($time==''){
// $msg='时间不能为空';
// $pd_go=false;
// }

if($pd_go==true){

import('alidayu.top.TopClient');
import('alidayu.top.TopLogger');
import('alidayu.top.RequestCheckUtil');
import('alidayu.top.ResultSet');
import('alidayu.top.request.AlibabaAliqinFcSmsNumSendRequest');

$product=$tel;

if($stype=='code'){
$sstype="绑定手机验证码";
$code=rand(100001,999999);
$TemplateCode='SMS_121890057';
$SmsParam='{"code":"'.$code.'","product":"'.$product.'"}';
}
// / dump($SmsParam);
//验证码${code},您正在申请${product}的用户升级认证,请在5分钟之内完成验证,感谢您的支持!


$appkey=config('alidayusms')['appkey'];
$secret=config('alidayusms')['secret'];
$signname=config('alidayusms')['signname'];
// dump($signname);
// die();
// if (request()->isAjax()) {//如果是ajax请求
// $tel = input('mobile');//手机号

$c = new TopClient;//大于客户端
$c->format = 'json';//设置返回值得类型

$c->appkey = $appkey;//阿里大于注册时给的应用appkey
$c->secretKey = $secret;//注册的app secretkey,修改成自己的

//请求对象,需要配置请求的参数
$req = new AlibabaAliqinFcSmsNumSendRequest;
$req->setExtend("");//公共回传参数,可以不传
$req->setSmsType("normal");//短信类型,传入值请填写normal

//签名,阿里大于-控制中心-验证码--配置签名 中配置的签名,必须填
$req->setSmsFreeSignName($signname);//根据前面配置短信签名里的前面做相应的修改

//你在短信中显示的验证码,这个要保存下来用于验证
//$num = rand(100000,999999);<br>               
//session('code',$num);//保存到session

//短信模板变量,传参规则{"key":"value"},key的名字须和申请模板中的变量名一致,
//传参时需传入{"code":"1234","product":"alidayu"}
$req->setSmsParam($SmsParam);//模板参数

//短信接收的手机号码,可以有多个,具体参照大于号帮助文档。
$req->setRecNum($tel);

//短信模板。阿里大于-控制中心-验证码--配置短信模板 必须填
$req->setSmsTemplateCode($TemplateCode );//根据前面配置模板是生成的模板ID修改
$resp = $c->execute($req);//发送请求

if($resp->result->success == true){
$data['code']=$code;
$data['recnum']=$tel;
$data['datetime']=time();
$data['SmsParam']=$SmsParam;
$data['smstemplatecode']=$TemplateCode;
$data['request_id']=$resp->request_id;
$data['stype']=$sstype;
$rec = Db::name('sms_records')->insertGetId($data);
}


return $resp;

// }
}

猜你喜欢

转载自www.cnblogs.com/chentailin/p/9238843.html