短信验证码限制次数

  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];
}

 

上一篇:阿里云服务器apache服务器局域网访问公网访问配置


下一篇:一刷156-力扣热题-32最长有效括号(h)