From eb3642205e7c06f9175d8750bac0fa1d8823806c Mon Sep 17 00:00:00 2001 From: wuliangbo Date: Wed, 11 Mar 2020 16:26:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Kernel/AppClient.php | 34 +++++++++++++++++++++----- src/Kernel/Traits/ResponseCastable.php | 1 - src/Payment/Pay/Client.php | 9 ++----- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/Kernel/AppClient.php b/src/Kernel/AppClient.php index 5d7fe68..fa15e5b 100755 --- a/src/Kernel/AppClient.php +++ b/src/Kernel/AppClient.php @@ -162,7 +162,7 @@ class AppClient extends BaseClient $sysParams["sign"] = $this->generateSign(array_merge($apiParams, $sysParams), $this->signType); $requestUrl = $this->buildRequestUrl($sysParams); $result = $this->httpPost($requestUrl, $apiParams); - if(isset($result[$this->ERROR_RESPONSE])){ //返回错误 + if (isset($result[$this->ERROR_RESPONSE])) { //返回错误 throw new BadRequestException( 'Get Alipay API Error:' . $result[$this->ERROR_RESPONSE]['msg'] . (isset($result[$this->ERROR_RESPONSE]['sub_code']) ? (' - ' . $result[$this->ERROR_RESPONSE]['sub_code']) : '') @@ -187,6 +187,23 @@ class AppClient extends BaseClient return new Collection($content); } + /** + * @param AppRequest $request + * @return string + * @throws InvalidConfigException + * @throws \Exception + */ + public function sdkExecute(AppRequest $request) + { + $this->setupCharsets($request); + $sysParams = $this->buildParams($request); + $apiParams = $request->getApiParas(); + $sysParams = array_merge($sysParams, $apiParams); + ksort($sysParams); + $sysParams["sign"] = $this->generateSign($sysParams, $this->signType); + return http_build_query($sysParams); + } + /** * @param AppRequest $request * @return array @@ -206,12 +223,17 @@ class AppClient extends BaseClient $sysParams["method"] = $request->getApiMethodName(); $sysParams["timestamp"] = date("Y-m-d H:i:s"); $sysParams["alipay_sdk"] = $this->alipaySdkVersion; - $sysParams["terminal_type"] = $request->getTerminalType(); - $sysParams["terminal_info"] = $request->getTerminalInfo(); - $sysParams["prod_code"] = $request->getProdCode(); + if ($request->getTerminalType()) { + $sysParams["terminal_type"] = $request->getTerminalType(); + } + if ($request->getTerminalInfo()) { + $sysParams["terminal_info"] = $request->getTerminalInfo(); + } + if ($request->getProdCode()) { + $sysParams["prod_code"] = $request->getProdCode(); + } $sysParams["notify_url"] = $request->getNotifyUrl(); $sysParams["charset"] = $this->postCharset; - if (isset($this->config['auth_token'])) { $sysParams["auth_token"] = $this->config['auth_token']; } @@ -259,7 +281,7 @@ class AppClient extends BaseClient */ public function buildRequestUrl($sysParams) { - return "?" .http_build_query($sysParams); + return "?" . http_build_query($sysParams); } /** diff --git a/src/Kernel/Traits/ResponseCastable.php b/src/Kernel/Traits/ResponseCastable.php index 942623f..6f36f18 100644 --- a/src/Kernel/Traits/ResponseCastable.php +++ b/src/Kernel/Traits/ResponseCastable.php @@ -29,7 +29,6 @@ trait ResponseCastable { $response = Response::buildFromPsrResponse($response); $response->getBody()->rewind(); - switch ($type ?? 'array') { case 'collection': return $response->toCollection(); diff --git a/src/Payment/Pay/Client.php b/src/Payment/Pay/Client.php index f17366f..a406c1d 100755 --- a/src/Payment/Pay/Client.php +++ b/src/Payment/Pay/Client.php @@ -47,14 +47,9 @@ class Client extends AppClient } /** - * app 支付 * @param array $payload - * @return \EasyAlipay\Kernel\Support\Collection - * @throws \EasyAlipay\Kernel\Exceptions\BadRequestException - * @throws \EasyAlipay\Kernel\Exceptions\InvalidArgumentException + * @return string * @throws \EasyAlipay\Kernel\Exceptions\InvalidConfigException - * @throws \EasyAlipay\Kernel\Exceptions\InvalidSignException - * @throws \GuzzleHttp\Exception\GuzzleException */ public function app(array $payload) { @@ -75,7 +70,7 @@ class Client extends AppClient } $request->setBizContent($payContentBuilder->getBizContent()); $request->setApiMethodName("alipay.trade.app.pay"); - return ($this->execute($request)); + return ($this->sdkExecute($request)); } /**