['规则1','规则2'...] * * @var array */ protected $rule = [ 'password|密码' => 'require|min:6|max:20', 'repassword|确认密码' => 'require|confirm:password', 'phone|手机号' => 'require|mobile', 'user_id|用户id' => 'require|number' ]; /** * 定义错误信息 * 格式:'字段名.规则名' => '错误信息' * * @var array */ protected $message = []; protected $scene = [ 'modifyPassword' => ['password','repassword'], 'editUser' => ['user_id','password'], 'register' => ['phone','password'], 'delUser' => ['user_id'], ]; /** * 手机号短信验证 * @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; } }