This commit is contained in:
parent
206a765044
commit
bd0a3512bc
@ -351,9 +351,9 @@ abstract class Ca
|
|||||||
public function httpRequest(string $path, array $arg = []): mixed
|
public function httpRequest(string $path, array $arg = []): mixed
|
||||||
{
|
{
|
||||||
// 请求前日志
|
// 请求前日志
|
||||||
Log::getInstance()->info('CA-HTTP-REQUEST-START', [
|
Log::getInstance()->info('CA接口请求开始', [
|
||||||
'url' => $path,
|
'请求地址' => $path,
|
||||||
'params' => $arg,
|
'原始参数' => $arg,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$option = [
|
$option = [
|
||||||
@ -366,30 +366,48 @@ abstract class Ca
|
|||||||
$arg = array_merge($arg, $option);
|
$arg = array_merge($arg, $option);
|
||||||
|
|
||||||
// 合并 header 后的最终请求参数日志
|
// 合并 header 后的最终请求参数日志
|
||||||
Log::getInstance()->info('CA-HTTP-REQUEST-PARAMS', [
|
Log::getInstance()->info('CA接口最终请求参数', [
|
||||||
'url' => $path,
|
'请求地址' => $path,
|
||||||
'final_params' => $arg,
|
'最终参数' => $arg,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response = $this->client->post($path, $arg);
|
$response = $this->client->post($path, $arg);
|
||||||
|
|
||||||
|
// 记录原始响应(未解析)
|
||||||
|
Log::getInstance()->info('CA接口原始响应', [
|
||||||
|
'请求地址' => $path,
|
||||||
|
'HTTP状态码' => $response->getStatusCode(),
|
||||||
|
'原始响应内容' => (string)$response->getBody(),
|
||||||
|
]);
|
||||||
|
|
||||||
if ($response->getStatusCode() != '200') {
|
if ($response->getStatusCode() != '200') {
|
||||||
// 请求失败
|
// 请求失败
|
||||||
Log::getInstance()->error('CA-HTTP-REQUEST-ERROR', [
|
Log::getInstance()->error('CA接口请求失败', [
|
||||||
'url' => $path,
|
'请求地址' => $path,
|
||||||
'status_code' => $response->getStatusCode(),
|
'HTTP状态码' => $response->getStatusCode(),
|
||||||
'response' => $response->getBody()->getContents(),
|
'响应内容' => $response->getBody()->getContents(),
|
||||||
]);
|
]);
|
||||||
throw new BusinessException($response->getBody()->getContents());
|
throw new BusinessException($response->getBody()->getContents());
|
||||||
}
|
}
|
||||||
$body = json_decode($response->getBody(), true);
|
$body = json_decode($response->getBody(), true);
|
||||||
|
|
||||||
|
// 记录接口返回的完整 body
|
||||||
|
Log::getInstance()->info('CA接口返回BODY', [
|
||||||
|
'请求地址' => $path,
|
||||||
|
'返回数据' => $body,
|
||||||
|
]);
|
||||||
|
|
||||||
if (empty($body)) {
|
if (empty($body)) {
|
||||||
// 返回值为空
|
// 返回值为空
|
||||||
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
|
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($body['result_code'] != 0) {
|
if ($body['result_code'] != 0) {
|
||||||
// 请求失败
|
// 业务失败
|
||||||
|
Log::getInstance()->error('CA业务处理失败', [
|
||||||
|
'请求地址' => $path,
|
||||||
|
'返回数据' => $body,
|
||||||
|
]);
|
||||||
if (!empty($body['result_msg'])) {
|
if (!empty($body['result_msg'])) {
|
||||||
throw new BusinessException($body['result_msg']);
|
throw new BusinessException($body['result_msg']);
|
||||||
}
|
}
|
||||||
@ -397,9 +415,9 @@ abstract class Ca
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 请求成功日志
|
// 请求成功日志
|
||||||
Log::getInstance()->info('CA-HTTP-REQUEST-SUCCESS', [
|
Log::getInstance()->info('CA接口请求成功', [
|
||||||
'url' => $path,
|
'请求地址' => $path,
|
||||||
'response' => $body,
|
'返回数据' => $body,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $body['body'];
|
return $body['body'];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user