From 9c8d5aebbf0e9d52d0418ea6ebdf60f2bb76951f Mon Sep 17 00:00:00 2001 From: unknown <736250432@qq.com> Date: Tue, 10 Oct 2023 16:08:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E5=86=8C=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/IndexController.php | 7 +------ app/common/enum/notice/NoticeEnum.php | 7 +++++++ app/common/validate/login/RegisterValidate.php | 17 ++++++++++++++--- 3 files changed, 22 insertions(+), 9 deletions(-) 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