add request helper

This commit is contained in:
2026-03-18 08:49:10 +08:00
parent 58afb7c385
commit f3f73935e1
8 changed files with 51 additions and 54 deletions
@@ -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
*/