|
|
@ -200,32 +200,32 @@ class CCBPayment |
|
|
|
|
|
|
|
|
$options = ['json' => $params]; |
|
|
$options = ['json' => $params]; |
|
|
|
|
|
|
|
|
if (env('CCB_HTTP_PROXY')) { |
|
|
|
|
|
$options['proxy'] = env('CCB_HTTP_PROXY'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$startTime = microtime(true); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
$response = $this->clientFactory->create(['timeout' => 120])->post($uri, $options); |
|
|
|
|
|
|
|
|
$response = $this->clientFactory->create(['timeout' => 60])->post($uri, $options); |
|
|
} catch (\Exception $e) { |
|
|
} catch (\Exception $e) { |
|
|
$this->saveApiLog($uri, $params, $e->getMessage()); |
|
|
|
|
|
|
|
|
$this->saveApiLog(0, $uri, $params, $e->getMessage()); |
|
|
throw new BusinessException(500, '请求异常'); |
|
|
throw new BusinessException(500, '请求异常'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$useTime = round((microtime(true) - $startTime) * 1000, 2); |
|
|
|
|
|
|
|
|
$content = $response->getBody()->getContents(); |
|
|
$content = $response->getBody()->getContents(); |
|
|
$result = json_decode($content, true); |
|
|
$result = json_decode($content, true); |
|
|
|
|
|
|
|
|
if (!isset($result['Svc_Rsp_St']) || $result['Svc_Rsp_St'] != '00') { |
|
|
if (!isset($result['Svc_Rsp_St']) || $result['Svc_Rsp_St'] != '00') { |
|
|
$this->saveApiLog($uri, $params, $content); |
|
|
|
|
|
|
|
|
$this->saveApiLog($useTime, $uri, $params, $content); |
|
|
throw new BusinessException(500, ($result['Rsp_Inf'] ?? 'CCB请求失败')); |
|
|
throw new BusinessException(500, ($result['Rsp_Inf'] ?? 'CCB请求失败')); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!isset($result['Sign_Inf']) || !$this->verifySign($this->createSign($result), $result['Sign_Inf'])) { |
|
|
if (!isset($result['Sign_Inf']) || !$this->verifySign($this->createSign($result), $result['Sign_Inf'])) { |
|
|
$this->saveApiLog($uri, $params, $content); |
|
|
|
|
|
|
|
|
$this->saveApiLog($useTime, $uri, $params, $content); |
|
|
throw new BusinessException(500, ($result['Rsp_Inf'] ?? 'CCB验签失败')); |
|
|
throw new BusinessException(500, ($result['Rsp_Inf'] ?? 'CCB验签失败')); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($this->isDebug) { |
|
|
if ($this->isDebug) { |
|
|
$this->saveApiLog($uri, $params, $content); |
|
|
|
|
|
|
|
|
$this->saveApiLog($useTime, $uri, $params, $content); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $result; |
|
|
return $result; |
|
|
@ -233,17 +233,19 @@ class CCBPayment |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 保存API请求日志 |
|
|
* 保存API请求日志 |
|
|
|
|
|
* @param $useTime |
|
|
* @param $uri |
|
|
* @param $uri |
|
|
* @param $params |
|
|
* @param $params |
|
|
* @param $content |
|
|
* @param $content |
|
|
* @return void |
|
|
* @return void |
|
|
*/ |
|
|
*/ |
|
|
private function saveApiLog($uri, $params, $content) |
|
|
|
|
|
|
|
|
private function saveApiLog($useTime, $uri, $params, $content) |
|
|
{ |
|
|
{ |
|
|
$this->logger->info( |
|
|
$this->logger->info( |
|
|
sprintf( |
|
|
sprintf( |
|
|
"%s\nUrl:%s\nParams:\n%s\nContent:\n%s\n", |
|
|
|
|
|
|
|
|
"%s\nTime: %.2f ms\nUrl: %s\nParams:\n%s\nContent:\n%s\n", |
|
|
'CCB API Log', |
|
|
'CCB API Log', |
|
|
|
|
|
$useTime, |
|
|
$uri, |
|
|
$uri, |
|
|
json_encode($params, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), |
|
|
json_encode($params, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), |
|
|
$content |
|
|
$content |
|
|
|