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

This commit is contained in:
haomingming 2025-12-01 11:03:20 +08:00
parent 52c258f464
commit 12a4846d0e

View File

@ -106,23 +106,29 @@ class Prescription
), ),
]; ];
Log::getInstance()->info("处方平台获取药品请求数据:" . json_encode($option,JSON_UNESCAPED_UNICODE));
try { try {
$response = $this->httpRequest($this->api_url . $this->version . '/drug/syncDrugCatalogue', $option); $response = $this->httpRequest($this->api_url . $this->version . '/drug/syncDrugCatalogue', $option);
if (empty($response['data'])){ if (empty($response['data'])){
// 返回值为空 // 返回值为空
if (!empty($response['message'])){ if (!empty($response['message'])){
Log::getInstance()->error("处方平台获取药品返回数据为空:" . json_encode($response,JSON_UNESCAPED_UNICODE));
throw new BusinessException($response['message']); throw new BusinessException($response['message']);
} }
Log::getInstance()->error("处方平台获取药品返回数据为空,无错误信息");
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
} }
if (empty($response['data']['result'])){ if (empty($response['data']['result'])){
// 返回值为空 // 返回值为空
Log::getInstance()->error("处方平台获取药品返回result为空" . json_encode($response,JSON_UNESCAPED_UNICODE));
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
} }
Log::getInstance()->info("处方平台获取药品返回数据:" . json_encode($response,JSON_UNESCAPED_UNICODE));
return $response['data']['result']; return $response['data']['result'];
} catch (GuzzleException $e) { } catch (GuzzleException $e) {
Log::getInstance()->error("处方平台获取药品请求异常:" . $e->getMessage());
throw new BusinessException($e->getMessage()); throw new BusinessException($e->getMessage());
} }
} }
@ -283,19 +289,30 @@ class Prescription
$arg = array_merge($arg,$option); $arg = array_merge($arg,$option);
} }
// 记录请求日志(隐藏敏感信息)
$logArg = $arg;
if (isset($logArg['headers']['Authorization'])) {
$logArg['headers']['Authorization'] = 'Bearer ***';
}
Log::getInstance()->info("处方平台HTTP请求" . $path . ",请求参数:" . json_encode($logArg,JSON_UNESCAPED_UNICODE));
$response = $this->client->post($path, $arg); $response = $this->client->post($path, $arg);
if ($response->getStatusCode() != '200'){ if ($response->getStatusCode() != '200'){
// 请求失败 // 请求失败
throw new BusinessException($response->getBody()->getContents()); $errorBody = $response->getBody()->getContents();
Log::getInstance()->error("处方平台HTTP请求失败状态码" . $response->getStatusCode() . ",错误信息:" . $errorBody);
throw new BusinessException($errorBody);
} }
$body = json_decode($response->getBody(),true); $body = json_decode($response->getBody(),true);
if (empty($body)){ if (empty($body)){
// 返回值为空 // 返回值为空
Log::getInstance()->error("处方平台HTTP请求返回值为空路径" . $path);
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
} }
Log::getInstance()->info("处方平台HTTP请求成功路径" . $path . ",返回数据:" . json_encode($body,JSON_UNESCAPED_UNICODE));
return $body; return $body;
} }
} }