加日志
Some checks are pending
Build Docker / build (push) Waiting to run

This commit is contained in:
haomingming 2025-12-01 16:20:07 +08:00
parent a33fe1033d
commit 206a765044

View File

@ -350,6 +350,12 @@ abstract class Ca
*/
public function httpRequest(string $path, array $arg = []): mixed
{
// 请求前日志
Log::getInstance()->info('CA-HTTP-REQUEST-START', [
'url' => $path,
'params' => $arg,
]);
$option = [
"headers" => [
"app_id" => $this->app_id,
@ -359,10 +365,21 @@ abstract class Ca
$arg = array_merge($arg, $option);
// 合并 header 后的最终请求参数日志
Log::getInstance()->info('CA-HTTP-REQUEST-PARAMS', [
'url' => $path,
'final_params' => $arg,
]);
$response = $this->client->post($path, $arg);
if ($response->getStatusCode() != '200') {
// 请求失败
Log::getInstance()->error('CA-HTTP-REQUEST-ERROR', [
'url' => $path,
'status_code' => $response->getStatusCode(),
'response' => $response->getBody()->getContents(),
]);
throw new BusinessException($response->getBody()->getContents());
}
$body = json_decode($response->getBody(), true);
@ -379,6 +396,12 @@ abstract class Ca
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
}
// 请求成功日志
Log::getInstance()->info('CA-HTTP-REQUEST-SUCCESS', [
'url' => $path,
'response' => $body,
]);
return $body['body'];
}