5 changed files with 78 additions and 18 deletions
@ -0,0 +1,66 @@ |
|||||
|
<?php |
||||
|
declare (strict_types = 1); |
||||
|
|
||||
|
namespace app\validate; |
||||
|
|
||||
|
use think\facade\Db; |
||||
|
use think\Validate; |
||||
|
|
||||
|
class Passport extends Validate |
||||
|
{ |
||||
|
/** |
||||
|
* 定义验证规则 |
||||
|
* 格式:'字段名' => ['规则1','规则2'...] |
||||
|
* |
||||
|
* @var array |
||||
|
*/ |
||||
|
protected $rule = [ |
||||
|
'phone|手机号' => 'require|mobile', |
||||
|
'password|密码' => 'require|min:6|max:20', |
||||
|
'sms_code|短信验证码' => 'require', |
||||
|
'account_number|账号' => 'require|min:4|max:16', |
||||
|
'user_id|用户id' => 'require|number' |
||||
|
]; |
||||
|
|
||||
|
/** |
||||
|
* 定义错误信息 |
||||
|
* 格式:'字段名.规则名' => '错误信息' |
||||
|
* |
||||
|
* @var array |
||||
|
*/ |
||||
|
protected $message = []; |
||||
|
|
||||
|
protected $scene = [ |
||||
|
'login' => ['phone','password'], |
||||
|
'register' => ['phone','password','sms_code'], |
||||
|
'retrieve' => ['phone','password','sms_code'], |
||||
|
'modifyPassword' => ['password'], |
||||
|
'sendCode' => ['phone'], |
||||
|
'adminLogin' => ['account_number','password'], |
||||
|
'agentLogin' => ['phone','password'], |
||||
|
]; |
||||
|
|
||||
|
/** |
||||
|
* 手机号短信验证 |
||||
|
* @param $mobile |
||||
|
* @param $code |
||||
|
* @return bool|string |
||||
|
* @throws \think\db\exception\DataNotFoundException |
||||
|
* @throws \think\db\exception\DbException |
||||
|
* @throws \think\db\exception\ModelNotFoundException |
||||
|
*/ |
||||
|
public function checkCode($mobile,$code) |
||||
|
{ |
||||
|
$pin_info = Db::name('pincode')->where('mobile',$mobile)->field('code,time')->find(); |
||||
|
if (empty($pin_info)) { |
||||
|
return '短信验证码错误'; |
||||
|
} |
||||
|
if ($pin_info['time'] < time() - 300) { |
||||
|
return '短信验证码已过期,请重新获取'; |
||||
|
} |
||||
|
if ($code != $pin_info['code']) { |
||||
|
return '短信验证码错误'; |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue