feat(admin): 新增限流器 add rate limiting middleware for backend
- Add rate limiting functionality to the admin panel - Implement rate limiting middleware to control API request frequency - Update login controller to use rate limiting Add helper functions for getting IP and admin UID - Update route configuration to include rate limiting middleware - Add Redis configuration to .env file - Update composer.json to include rate limiting package dependency
This commit is contained in:
28
app/common/utils/Helper.php
Normal file
28
app/common/utils/Helper.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace app\common\utils;
|
||||
|
||||
class Helper
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取当前IP地址
|
||||
* @return string
|
||||
*/
|
||||
public static function getIp(): string
|
||||
{
|
||||
return request()->ip();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录用户ID
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getAdminUid(): int|string
|
||||
{
|
||||
return session('admin.id') ?: 0;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user