其他分享
首页 > 其他分享> > 短信验证码限制次数

短信验证码限制次数

作者:互联网

  public function sendCode(Request $request)
    {
        $phone = $request->get('phone');
        if(empty($phone)){
            return ['code'=>10001, 'msg' => '手机号不能为空', 'data'=> []];
        }
        $cache = Cache::get($phone.date("Y:m:d"));
        if($cache > 5){
            return ['code' => 10003, 'msg' => '每天只能发送五条短信', 'data' => []];
        }
        $captcha = (new Phone())->sendSms($phone);
        Cache::put($phone,$captcha,60*15);
        $num = $cache + 1;
        Cache::put($phone.date("Y:m:d"),$num,60*60*24);
        return ['code' => 200, 'msg' => '短信发送成功', 'data' => $captcha];
}

 

标签:code,短信,phone,captcha,Cache,验证码,60,次数,return
来源: https://www.cnblogs.com/xiaoyantongxue/p/15677290.html