diff --git a/extend/Prescription/Prescription.php b/extend/Prescription/Prescription.php index 7c40750..88d6911 100644 --- a/extend/Prescription/Prescription.php +++ b/extend/Prescription/Prescription.php @@ -106,23 +106,29 @@ class Prescription ), ]; + 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'])){ // 返回值为空 if (!empty($response['message'])){ + Log::getInstance()->error("处方平台获取药品返回数据为空:" . json_encode($response,JSON_UNESCAPED_UNICODE)); throw new BusinessException($response['message']); } + Log::getInstance()->error("处方平台获取药品返回数据为空,无错误信息"); throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); } if (empty($response['data']['result'])){ // 返回值为空 + 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)); return $response['data']['result']; } catch (GuzzleException $e) { + Log::getInstance()->error("处方平台获取药品请求异常:" . $e->getMessage()); throw new BusinessException($e->getMessage()); } } @@ -283,19 +289,30 @@ class Prescription $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); 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); if (empty($body)){ // 返回值为空 + Log::getInstance()->error("处方平台HTTP请求返回值为空,路径:" . $path); throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); } + Log::getInstance()->info("处方平台HTTP请求成功,路径:" . $path . ",返回数据:" . json_encode($body,JSON_UNESCAPED_UNICODE)); return $body; } } \ No newline at end of file