feat: 验证码加限流

This commit is contained in:
2025-01-02 16:41:30 +08:00
parent c3f75fadc9
commit 06868e3a1e
3 changed files with 40 additions and 2 deletions

View File

@@ -15,7 +15,12 @@ Route::group('v1', function () {
// 用户模块
Route::group('user', function () {
// 获取验证码
Route::get('captcha', 'Captcha/index');
Route::get('captcha', 'Captcha/index')->middleware(\think\middleware\Throttle::class, [
'visit_rate' => '5/m',
'visit_fail_response' => function (\think\middleware\Throttle $throttle, \think\Request $request, int $wait_seconds) {
return \think\Response::create('您的操作过于频繁, 请在 ' . $wait_seconds . ' 秒后再试。')->code(429);
},
]);
// 登录接口
Route::post('login', 'Login/index');