parent
6e90c52cb8
commit
93d5aae5ac
@ -351,10 +351,10 @@ abstract class Ca
|
||||
public function httpRequest(string $path, array $arg = []): mixed
|
||||
{
|
||||
// 请求前日志
|
||||
Log::getInstance()->info('CA接口请求开始', [
|
||||
'请求地址' => $path,
|
||||
'原始参数' => $arg,
|
||||
]);
|
||||
// Log::getInstance()->info('CA接口请求开始', [
|
||||
// '请求地址' => $path,
|
||||
// '原始参数' => $arg,
|
||||
// ]);
|
||||
|
||||
$option = [
|
||||
"headers" => [
|
||||
@ -366,36 +366,36 @@ abstract class Ca
|
||||
$arg = array_merge($arg, $option);
|
||||
|
||||
// 合并 header 后的最终请求参数日志
|
||||
Log::getInstance()->info('CA接口最终请求参数', [
|
||||
'请求地址' => $path,
|
||||
'最终参数' => $arg,
|
||||
]);
|
||||
// Log::getInstance()->info('CA接口最终请求参数', [
|
||||
// '请求地址' => $path,
|
||||
// '最终参数' => $arg,
|
||||
// ]);
|
||||
|
||||
$response = $this->client->post($path, $arg);
|
||||
|
||||
// 记录原始响应(未解析)
|
||||
Log::getInstance()->info('CA接口原始响应', [
|
||||
'请求地址' => $path,
|
||||
'HTTP状态码' => $response->getStatusCode(),
|
||||
'原始响应内容' => (string)$response->getBody(),
|
||||
]);
|
||||
// Log::getInstance()->info('CA接口原始响应', [
|
||||
// '请求地址' => $path,
|
||||
// 'HTTP状态码' => $response->getStatusCode(),
|
||||
// '原始响应内容' => (string)$response->getBody(),
|
||||
// ]);
|
||||
|
||||
if ($response->getStatusCode() != '200') {
|
||||
// 请求失败
|
||||
Log::getInstance()->error('CA接口请求失败', [
|
||||
'请求地址' => $path,
|
||||
'HTTP状态码' => $response->getStatusCode(),
|
||||
'响应内容' => $response->getBody()->getContents(),
|
||||
]);
|
||||
// Log::getInstance()->error('CA接口请求失败', [
|
||||
// '请求地址' => $path,
|
||||
// 'HTTP状态码' => $response->getStatusCode(),
|
||||
// '响应内容' => $response->getBody()->getContents(),
|
||||
// ]);
|
||||
throw new BusinessException($response->getBody()->getContents());
|
||||
}
|
||||
$body = json_decode($response->getBody(), true);
|
||||
|
||||
// 记录接口返回的完整 body
|
||||
Log::getInstance()->info('CA接口返回BODY', [
|
||||
'请求地址' => $path,
|
||||
'返回数据' => $body,
|
||||
]);
|
||||
// Log::getInstance()->info('CA接口返回BODY', [
|
||||
// '请求地址' => $path,
|
||||
// '返回数据' => $body,
|
||||
// ]);
|
||||
|
||||
if (empty($body)) {
|
||||
// 返回值为空
|
||||
@ -404,10 +404,10 @@ abstract class Ca
|
||||
|
||||
if ($body['result_code'] != 0) {
|
||||
// 业务失败
|
||||
Log::getInstance()->error('CA业务处理失败', [
|
||||
'请求地址' => $path,
|
||||
'返回数据' => $body,
|
||||
]);
|
||||
// Log::getInstance()->error('CA业务处理失败', [
|
||||
// '请求地址' => $path,
|
||||
// '返回数据' => $body,
|
||||
// ]);
|
||||
if (!empty($body['result_msg'])) {
|
||||
throw new BusinessException($body['result_msg']);
|
||||
}
|
||||
@ -415,10 +415,10 @@ abstract class Ca
|
||||
}
|
||||
|
||||
// 请求成功日志
|
||||
Log::getInstance()->info('CA接口请求成功', [
|
||||
'请求地址' => $path,
|
||||
'返回数据' => $body,
|
||||
]);
|
||||
// Log::getInstance()->info('CA接口请求成功', [
|
||||
// '请求地址' => $path,
|
||||
// '返回数据' => $body,
|
||||
// ]);
|
||||
|
||||
return $body['body'];
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@ class Prescription
|
||||
),
|
||||
];
|
||||
|
||||
Log::getInstance()->info("处方平台获取药品请求数据:" . json_encode($option,JSON_UNESCAPED_UNICODE));
|
||||
// Log::getInstance()->info("处方平台获取药品请求数据:" . json_encode($option,JSON_UNESCAPED_UNICODE));
|
||||
try {
|
||||
$response = $this->httpRequest($this->api_url . $this->version . '/drug/syncDrugCatalogue', $option);
|
||||
if (empty($response['data'])){
|
||||
@ -121,11 +121,11 @@ class Prescription
|
||||
|
||||
if (empty($response['data']['result'])){
|
||||
// 返回值为空
|
||||
Log::getInstance()->error("处方平台获取药品返回result为空:" . json_encode($response,JSON_UNESCAPED_UNICODE));
|
||||
// Log::getInstance()->error("处方平台获取药品返回result为空:" . json_encode($response,JSON_UNESCAPED_UNICODE));
|
||||
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
|
||||
}
|
||||
|
||||
Log::getInstance()->info("处方平台获取药品返回数据:" . json_encode($response,JSON_UNESCAPED_UNICODE));
|
||||
// Log::getInstance()->info("处方平台获取药品返回数据:" . json_encode($response,JSON_UNESCAPED_UNICODE));
|
||||
return $response['data']['result'];
|
||||
} catch (GuzzleException $e) {
|
||||
Log::getInstance()->error("处方平台获取药品请求异常:" . $e->getMessage());
|
||||
@ -204,14 +204,14 @@ class Prescription
|
||||
"json" => $arg
|
||||
];
|
||||
|
||||
Log::getInstance()->info("处方平台上报数据:" . json_encode($option,JSON_UNESCAPED_UNICODE));
|
||||
// Log::getInstance()->info("处方平台上报数据:" . json_encode($option,JSON_UNESCAPED_UNICODE));
|
||||
try {
|
||||
$response = $this->httpRequest($this->api_url . $this->version . '/preOrder/receivePreOrder', $option);
|
||||
if (empty($response)){
|
||||
// 返回值错误为空
|
||||
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
|
||||
}
|
||||
Log::getInstance()->info("处方平台返回数据:" . json_encode($response,JSON_UNESCAPED_UNICODE));
|
||||
// Log::getInstance()->info("处方平台返回数据:" . json_encode($response,JSON_UNESCAPED_UNICODE));
|
||||
return $response;
|
||||
} catch (GuzzleException $e) {
|
||||
throw new BusinessException($e->getMessage());
|
||||
@ -293,25 +293,25 @@ class Prescription
|
||||
// 记录请求日志(隐藏敏感信息)
|
||||
$logArg = $arg;
|
||||
|
||||
Log::getInstance()->info("处方平台HTTP请求:" . $path . ",请求参数:" . json_encode($logArg,JSON_UNESCAPED_UNICODE));
|
||||
// Log::getInstance()->info("处方平台HTTP请求:" . $path . ",请求参数:" . json_encode($logArg,JSON_UNESCAPED_UNICODE));
|
||||
|
||||
$response = $this->client->post($path, $arg);
|
||||
|
||||
if ($response->getStatusCode() != '200'){
|
||||
// 请求失败
|
||||
$errorBody = $response->getBody()->getContents();
|
||||
Log::getInstance()->error("处方平台HTTP请求失败,状态码:" . $response->getStatusCode() . ",错误信息:" . $errorBody);
|
||||
// Log::getInstance()->error("处方平台HTTP请求失败,状态码:" . $response->getStatusCode() . ",错误信息:" . $errorBody);
|
||||
throw new BusinessException($errorBody);
|
||||
}
|
||||
|
||||
$body = json_decode($response->getBody(),true);
|
||||
if (empty($body)){
|
||||
// 返回值为空
|
||||
Log::getInstance()->error("处方平台HTTP请求返回值为空,路径:" . $path);
|
||||
// Log::getInstance()->error("处方平台HTTP请求返回值为空,路径:" . $path);
|
||||
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
|
||||
}
|
||||
|
||||
Log::getInstance()->info("处方平台HTTP请求成功,路径:" . $path . ",返回数据:" . json_encode($body,JSON_UNESCAPED_UNICODE));
|
||||
// Log::getInstance()->info("处方平台HTTP请求成功,路径:" . $path . ",返回数据:" . json_encode($body,JSON_UNESCAPED_UNICODE));
|
||||
return $body;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user