You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.9 KiB
67 lines
1.9 KiB
<?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',
|
|
'repassword|确认密码' => 'require|confirm:password',
|
|
'sms_code|短信验证码' => 'require',
|
|
'account_number|账号' => 'require|min:4|max:16',
|
|
'user_id|用户id' => 'require|number',
|
|
'invite_code|邀请码' => 'require'
|
|
];
|
|
|
|
/**
|
|
* 定义错误信息
|
|
* 格式:'字段名.规则名' => '错误信息'
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $message = [];
|
|
|
|
protected $scene = [
|
|
'login' => ['phone','password'],
|
|
'register' => ['phone','password','repassword'],//,'sms_code'
|
|
'retrieve' => ['phone','password','sms_code'],
|
|
'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;
|
|
}
|
|
}
|
|
|