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;

        //    }
        }

}

 

转载于:https://www.cnblogs.com/chentailin/p/9238843.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值