add request helper
This commit is contained in:
@@ -4,11 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Middleware\RequestLogMiddleware;
|
||||
use App\Model\OperationLog;
|
||||
use App\Model\User;
|
||||
use App\Utils\Log;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Qbhy\HyperfAuth\AuthManager;
|
||||
use Swoole\Coroutine;
|
||||
|
||||
@@ -48,23 +46,6 @@ class OperationLogService
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 从当前请求上下文获取客户端 IP
|
||||
*/
|
||||
public static function getRequestIp(): ?string
|
||||
{
|
||||
try {
|
||||
$container = \Hyperf\Context\ApplicationContext::getContainer();
|
||||
$request = $container->get(ServerRequestInterface::class);
|
||||
return RequestLogMiddleware::getClientIp($request);
|
||||
} catch (\Throwable $e) {
|
||||
Log::get()->warning('OperationLogService: 获取客户端 IP 失败', [
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从当前认证上下文获取用户 ID
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user