• Laravel框架接入短信平台进行用户注册短信验证


    今天刚接触了一个短信接口平台,云通讯第三方短信提供服务商。http://www.yuntongxun.com/

    然后介绍一下怎么使用该短信平台来接入到自己的项目中。

    首先你的去注册一个账号,然后根据提供的一些信息,作为接口进行接入。

    将account sid、auth token、Rest url、等信息写入代码中。稍后会由示例代码上传的。

    然后就是实例化SMS类,调用里面的方法就好了,很多方法都已经封装好了,直接用就好了。

    public function sendSMS(Request $request){
            $m3_result = new M3Result();
            $phone = $request->input('phone','');
            if($phone == ''){
                $m3_result->status = 1;
                $m3_result->message = '手机号不能为空';
                return $m3_result->toJson();
            }
    
            $sendTemplateSMS = new SendTemplateSMS();
            $code = '';
            $charset = '1234567890';
            $_len = strlen($charset)-1;
            for($i=0;$i<6;++$i){
                $code .= $charset[mt_rand(0,$_len)];
            }
            $sendTemplateSMS->sendTemplateSMS($phone,array($code,60),1);
    
            $deadline = date("Y-m-d H:i:s",time()+60*60);
            if(TempPhone::where('phone',$phone)->first()){
                TempPhone::where('phone',$phone)->update(['code'=>$code,'deadline'=>$deadline]);
            }else{
                $tempPhone = new TempPhone();
                $tempPhone->phone=$phone;
                $tempPhone->code=$code;
                $tempPhone->deadline=$deadline;
                $tempPhone->save();
            }
    
            $m3_result->status=0;
            $m3_result->message='发送成功';
            return $m3_result->toJson();
        }
    

    这个是前台进行异步验证的

    这个是临时存储验证码的表。

    短信接口平台工具类的下载:http://download.csdn.net/detail/yxhbk/9662824

  • 相关阅读:
    vue-cli创建项目 一直downloading解决办法
    Win7点击文件夹右键可打开cmd控制台,并获取当前目录

    js apply/call/caller/callee/bind使用方法与区别分析
    click() bind() live() delegate()区别
    域名与IP对应,解决只能IP访问不能域名访问的问题
    element.style{}
    git
    new
    js 数组函数
  • 原文地址:https://www.cnblogs.com/yxhblogs/p/5995042.html
Copyright © 2020-2023  润新知