短信码验证

This commit is contained in:
2025-10-13 09:44:29 +08:00
parent 4eae7d8375
commit 23acefb6b1

View File

@@ -20,6 +20,31 @@ class Sms extends Model
if (!checkMobile($mobile)) {
return ['code' => 0, 'msg' => '手机号不正确','data' =>null];
}
//今天验证码错误次数
$sms_count = db::name('sms_error')->where(['mobile' => $mobile,'createtime' => ['between', [strtotime(date('Y-m-d')), time()]]])->count();
if ($sms_count >= 5) {
//验证码错误次数过多
//封禁账号
$error_data = [
'type' => 1,
'type_text' => db::name('user')->where('mobile', $mobile)->value('id'),
'block_time' => time() + 60 * 60 * 24,
'block_note' => '账号登录异常被封禁24小时',
'createtime'=> time(),
];
db::name('block')->insert($error_data);
return ['code' => 0, 'msg' => '验证码错误次数过多,账号已被封禁,请联系管理员处理','data' =>null];
}
//验证码错误次数
$count_sms = max(5 - $sms_count, 0);
$data = [
'mobile' => $mobile,
'sms' => $code,
'createtime'=> time(),
];
db::name('sms_error')->insert($data);
$is_code = db::name('sms')->where(['mobile' => $mobile, 'event' => $type])->order('id desc')->find();
if ($is_code && $is_code['code'] == $code) {
//验证码正确
@@ -36,7 +61,7 @@ class Sms extends Model
db::name('sms')->where(['mobile' => $mobile, 'event' => $type])->delete();
return ['code' =>1, 'msg' =>'验证码正确','data' =>null];
} else {
return ['code' => 0, 'msg' => '验证码错误','data' =>null];
return ['code' => 0, 'msg' => '验证码错误'.$count_sms.'次后账号将被封禁24小时','data' =>null];
}
}