diff --git a/app/Service/v3/CcbPaymentService.php b/app/Service/v3/CcbPaymentService.php index 9bae09e..75d1dd6 100644 --- a/app/Service/v3/CcbPaymentService.php +++ b/app/Service/v3/CcbPaymentService.php @@ -5,16 +5,16 @@ namespace App\Service\v3; use App\Commons\Log; use App\Constants\v3\ErrorCode; use App\Constants\v3\LogLabel; -use App\Constants\v3\OrderState; use App\Exception\BusinessException; use App\Exception\ErrorCodeException; use App\Model\v3\CcbPayment; use App\Model\v3\OrderMain; -use App\Model\v3\Store; use App\Model\v3\User; +use App\TaskWorker\SSDBTask; use Hyperf\Di\Annotation\Inject; use Hyperf\Guzzle\ClientFactory; use Hyperf\Logger\LoggerFactory; +use Hyperf\Utils\ApplicationContext; class CcbPaymentService { @@ -189,7 +189,9 @@ class CcbPaymentService if (is_array($item)) { foreach ($item as $child) { $value = $this->createSign($child); - $result[] = ['', $value]; + if ($value !== '') { + $result[] = ['', $value]; + } } } else { $value = trim($item); @@ -202,9 +204,7 @@ class CcbPaymentService $str = ''; foreach ($result as [$key, $value]) { - if ($value) { - $str .= $key ? "$key=$value&" : "$value&"; - } + $str .= $key ? "$key=$value&" : "$value&"; } return rtrim($str, '&'); @@ -246,12 +246,12 @@ class CcbPaymentService if (!isset($result['Svc_Rsp_St']) || $result['Svc_Rsp_St'] != '00') { $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'])) { $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) { @@ -373,7 +373,20 @@ class CcbPaymentService 'Vno' => '4', ]; - return $this->apiRequest($uri, $params); + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + + $key = 'ccb_'.__FUNCTION__.'_'.$Main_Ordr_No.$Py_Trn_No; + + if ($ssdb->exec('setnx',$key, 1)) { + try { + return $this->apiRequest($uri, $params); + } finally { + $ssdb->exec('expire', $key, 2); + } + } else { + sleep(1); + return $this->gatherEnquireOrder($Main_Ordr_No, $Py_Trn_No); + } } /**