添加注册验证码
This commit is contained in:
parent
29c829a594
commit
9c8d5aebbf
|
@ -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', [
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
namespace app\common\validate\login;
|
||||
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\service\sms\SmsDriver;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
/**
|
||||
|
@ -18,8 +20,8 @@ class RegisterValidate extends BaseValidate
|
|||
|
||||
protected $rule = [
|
||||
'phone' => '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 '验证码错误';
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue