Commit 3346a624 by lujunyi

短信次数

parent 21e8eb54
...@@ -113,11 +113,21 @@ public function getLoginSmsCode(Request $request) ...@@ -113,11 +113,21 @@ public function getLoginSmsCode(Request $request)
return response()->json(['error' => '该药店手机号未注册,请联系管理员~']); return response()->json(['error' => '该药店手机号未注册,请联系管理员~']);
} }
// 检查当天发送次数
$today = date('Y-m-d');
$smsCountKey = "sms_count_{$phone}_{$today}";
$smsCount = cache()->get($smsCountKey, 0);
if ($smsCount >= 10) {
return response()->json(['error' => '今天该手机号已达到发送次数上限']);
}
// 生成短信验证码 // 生成短信验证码
$verificationCode = rand(100000, 999999); // 生成6位随机验证码 $verificationCode = rand(100000, 999999); // 生成6位随机验证码
// 存储验证码和有效期(10分钟) // 存储验证码和有效期(10分钟)
cache()->put("sms_verification_code_{$phone}", $verificationCode, 600); // 600秒 = 10分钟 cache()->put("sms_verification_code_{$phone}", $verificationCode, 600); // 600秒 = 10分钟
// 设置当天发送次数的过期时间为当天结束
cache()->put($smsCountKey, $smsCount + 1, strtotime('tomorrow') - time()); // 设置为明天0点过期
$templateName = 'verification_code'; $templateName = 'verification_code';
$templateData = ['code' => $verificationCode]; $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