PHP 手机验证码登录

1.手机验证码登录

  /**
     * 短信宝 获取验证码
     */
    public function login(Request $request){
   
        $tel=$request->get('phoneNum');
        //限制手机号请求次数
//        Cache::put($tel,0);die;
        if (Cache::has($tel)){
   
            $num=Cache::get($tel);
        }else{
   
            $num=Cache::put($tel,0);
        }
        if ($num>30){
   
            return $this->getJsonData(10010,'一天只能请求30次',null);
        }
        $smsapi = $this->smsapi;
        $user = $this->user; //短信平台帐号
        $pass = md5($this->pass); //短信平台密码
        $rand=rand(1000,9999);
        $content="【八维】:您的验证码:".$rand;//要发送的短信内容
        $phone = $tel;//要发送短信的手机号码
        $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
        $result =file_get_contents($sendurl) ;
       if ($result!=0){
   
           Cache::increment($tel,1);
           Cache::put('code',$rand);
           return $this->getJsonData(200,'获取成功',$rand);
       }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值