createCode(); //发送验证码到手机 TODO list($status,$msg) = $this->sendCode($code); if(! $status) return [false,'发送验证码失败!']; //成功后 缓存code 60s Cache::add($cacheKey,$code,60); return [true,'']; } //确认验证码 public function sendConfirmCode($data){ if(empty($data['id'])) return [false,'ID不能为空!']; //键名 $cacheKey = self::CACHE_CONFIRM . $data['id']; //限制发送验证码 if(Cache::has($cacheKey)) return [false,'已发送验证码,请勿重复发送!']; //获取验证码 $code = $this->createCode(); //发送验证码到手机 TODO list($status,$msg) = $this->sendCode($code); if(! $status) return [false,'发送验证码失败!']; //成功后 缓存code 60s Cache::add($cacheKey,$code,60); return [true,'']; } //发送验证码 TODO public function sendCode($code){ return [true,'']; } //验证登录验证码 public function loginCodeRule($data){ if(empty($data['account'])) return [false,'账号不能为空!']; if(empty($data['code'])) return [false,'验证码不能为空!']; $cacheKey = self::CACHE_LOGIN . $data['account']; if(Cache::has($cacheKey)){ $code = Cache::get($cacheKey); if($code != $data['code']) return [false,'验证码填写错误!']; return [true, '']; } return [false, '验证码不正确!']; } //验证确认验证码 public function ConfirmCodeRule($data){ if(empty($data['code'])) return [false,'验证码不能为空!']; $cacheKey = self::CACHE_CONFIRM . $data['id']; if(Cache::has($cacheKey)){ $code = Cache::get($cacheKey); if($code != $data['code']) return [false,'验证码填写错误!']; return [true, '']; } return [false,'验证码不存在!']; } //------------------暂时用不到下面------------------------// public function sendCodeToWx($data,$token){ $cacheKey = "code_" . $token; if(! $this->isSubmitlimitation($cacheKey)) return [false,'已发送验证码,请勿重复操作!']; //生成验证码 $code = $this->createCode(); //发送验证码 list($status,$msg) = $this->sendCode($code); if($status){ Cache::add($cacheKey,$code,1); return [true,'']; }else{ return [false,$msg]; } } //微信公众号发送 // public function sendCode($code){ // $serivce = new WxService(); // list($status,$msg) = $serivce->getToken(); // if(! $status) return [false,$msg]; // // list($status,$msg) = $serivce->sendToWx($msg,$code); // return [$status,$msg]; // } public function isSubmitlimitation($cacheKey){ if(Cache::has($cacheKey)){ return false; } return true; } }