Commit 10622308 by 赵增煜

增加短信验证码限制

parent 6303c69f
......@@ -72,6 +72,12 @@ public function smsCode(Request $request)
return response()->json(['error' => '手机号格式不正确']);
}
// TODO 增加手机验证码发送频率限制
$today = date('Y-m-d');
$smsCountKey = "sms_count_{$mobile}_{$today}";
$smsCount = cache()->get($smsCountKey, 0);
if ($smsCount >= 10) {
return $this->failed('今天该手机号已达到发送次数上限');
}
// 检查手机号在医师或者药店表中是否存在
if ($login_type == User::LOGIN_TYPE_PHARMACY) {
......@@ -91,6 +97,7 @@ public function smsCode(Request $request)
// 存储验证码和有效期(10分钟)
cache()->put("sms_verification_code_{$mobile}", $verificationCode, 600); // 600秒 = 10分钟
cache()->put($smsCountKey, $smsCount + 1, strtotime('tomorrow') - time());
$templateName = 'verification_code';
$templateData = ['code' => $verificationCode];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment