From 23acefb6b17583709edcffc68cd31f55a289c671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Mon, 13 Oct 2025 09:44:29 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=AD=E4=BF=A1=E7=A0=81=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/model/Sms.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/application/api/model/Sms.php b/application/api/model/Sms.php index 82a9ae1..a28d0f1 100644 --- a/application/api/model/Sms.php +++ b/application/api/model/Sms.php @@ -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]; } }