diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 5cc8dc8b..7003d5ef 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -28,14 +28,9 @@ class IndexController extends BaseApiController if(empty($params['phone']) || empty($params['scene'])){ return $this->fail('缺少必要参数'); } - if(!in_array($params['scene'],[NoticeEnum::LOGIN_CAPTCHA,NoticeEnum::BIND_MOBILE_CAPTCHA,NoticeEnum::CHANGE_MOBILE_CAPTCHA,NoticeEnum::FIND_LOGIN_PASSWORD_CAPTCHA])){ + if(!in_array($params['scene'],[NoticeEnum::LOGIN_CAPTCHA,NoticeEnum::BIND_MOBILE_CAPTCHA,NoticeEnum::CHANGE_MOBILE_CAPTCHA,NoticeEnum::FIND_LOGIN_PASSWORD_CAPTCHA,NoticeEnum::REGISTER_CAPTCHA])){ return $this->fail('短信场景错误'); } - //验证手机号 - $user = User::field('phone')->where('phone',$params['phone'])->findOrEmpty(); - if($user->isEmpty()){ - return $this->fail('手机号码错误'); - } //发送短信 try { $result = event('Notice', [ diff --git a/app/common/enum/notice/NoticeEnum.php b/app/common/enum/notice/NoticeEnum.php index 168af045..d6e030ad 100644 --- a/app/common/enum/notice/NoticeEnum.php +++ b/app/common/enum/notice/NoticeEnum.php @@ -36,6 +36,7 @@ class NoticeEnum const BIND_MOBILE_CAPTCHA = 102; const CHANGE_MOBILE_CAPTCHA = 103; const FIND_LOGIN_PASSWORD_CAPTCHA = 104; + const REGISTER_CAPTCHA = 105; /** @@ -46,6 +47,7 @@ class NoticeEnum self::BIND_MOBILE_CAPTCHA, self::CHANGE_MOBILE_CAPTCHA, self::FIND_LOGIN_PASSWORD_CAPTCHA, + self::REGISTER_CAPTCHA, ]; @@ -89,6 +91,7 @@ class NoticeEnum self::BIND_MOBILE_CAPTCHA => '绑定手机验证码', self::CHANGE_MOBILE_CAPTCHA => '变更手机验证码', self::FIND_LOGIN_PASSWORD_CAPTCHA => '找回登录密码验证码', + self::REGISTER_CAPTCHA => '注册验证码', ]; if ($flag) { @@ -117,6 +120,8 @@ class NoticeEnum 'BGSJHM' => self::CHANGE_MOBILE_CAPTCHA, // 找回登录密码 'ZHDLMM' => self::FIND_LOGIN_PASSWORD_CAPTCHA, + //注册 + 'YZMZC' => self::REGISTER_CAPTCHA, ]; return $scene[$tag] ?? ''; } @@ -137,6 +142,7 @@ class NoticeEnum self::BIND_MOBILE_CAPTCHA => '验证码:code', self::CHANGE_MOBILE_CAPTCHA => '验证码:code', self::FIND_LOGIN_PASSWORD_CAPTCHA => '验证码:code', + self::REGISTER_CAPTCHA => '验证码:code', ]; if ($flag) { @@ -182,6 +188,7 @@ class NoticeEnum self::BIND_MOBILE_CAPTCHA => '您正在绑定手机号,验证码${code},切勿将验证码泄露于他人,本条验证码有效期5分钟。', self::CHANGE_MOBILE_CAPTCHA => '您正在变更手机号,验证码${code},切勿将验证码泄露于他人,本条验证码有效期5分钟。', self::FIND_LOGIN_PASSWORD_CAPTCHA => '您正在找回登录密码,验证码${code},切勿将验证码泄露于他人,本条验证码有效期5分钟。', + self::REGISTER_CAPTCHA => '您正在注册账号,验证码${code},切勿将验证码泄露于他人,本条验证码有效期5分钟。', ]; if ($flag) { diff --git a/app/common/validate/login/RegisterValidate.php b/app/common/validate/login/RegisterValidate.php index a6549669..195cb7ea 100644 --- a/app/common/validate/login/RegisterValidate.php +++ b/app/common/validate/login/RegisterValidate.php @@ -1,6 +1,8 @@ 'require|mobile|unique:user', + 'code' => 'require|checkCode', 'password' => 'require|length:6,20', - 'password_confirm' => 'require|confirm', 'age' => 'number|gt:0', 'gender' => 'in:0,1,2', 'real_name' => 'chs|length:2,25', @@ -36,10 +38,9 @@ class RegisterValidate extends BaseValidate 'phone.require' => '请输入手机号码', 'phone.mobile' => '请输入正确的手机号码', 'phone.unique' => '该手机号码已注册', + 'code.require' => '请输入验证码', 'password.require' => '请输入密码', 'password.length' => '密码须在6-25位之间', - 'password_confirm.require' => '请输入确认密码', - 'password_confirm.confirm' => '两次输入的密码不一致', 'age.number' => '年龄必须是数字', 'age.gt' => '年龄必须大于0', 'gender.in' => '用户性别值错误', @@ -54,5 +55,15 @@ class RegisterValidate extends BaseValidate 'brigade.number' => '小组编码值错误', ]; + public function checkCode($code, $rule, $data): bool|string + { + $smsDriver = new SmsDriver(); + $result = $smsDriver->verify($data['phone'], $code, NoticeEnum::REGISTER_CAPTCHA); + if ($result) { + return true; + } + return '验证码错误'; + } + } \ No newline at end of file