Browse Source

修改扩展

master
wuliangbo 5 years ago
parent
commit
eb3642205e
  1. 34
      src/Kernel/AppClient.php
  2. 1
      src/Kernel/Traits/ResponseCastable.php
  3. 9
      src/Payment/Pay/Client.php

34
src/Kernel/AppClient.php

@ -162,7 +162,7 @@ class AppClient extends BaseClient
$sysParams["sign"] = $this->generateSign(array_merge($apiParams, $sysParams), $this->signType); $sysParams["sign"] = $this->generateSign(array_merge($apiParams, $sysParams), $this->signType);
$requestUrl = $this->buildRequestUrl($sysParams); $requestUrl = $this->buildRequestUrl($sysParams);
$result = $this->httpPost($requestUrl, $apiParams); $result = $this->httpPost($requestUrl, $apiParams);
if(isset($result[$this->ERROR_RESPONSE])){ //返回错误 if (isset($result[$this->ERROR_RESPONSE])) { //返回错误
throw new BadRequestException( throw new BadRequestException(
'Get Alipay API Error:' . $result[$this->ERROR_RESPONSE]['msg'] . 'Get Alipay API Error:' . $result[$this->ERROR_RESPONSE]['msg'] .
(isset($result[$this->ERROR_RESPONSE]['sub_code']) ? (' - ' . $result[$this->ERROR_RESPONSE]['sub_code']) : '') (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); 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 * @param AppRequest $request
* @return array * @return array
@ -206,12 +223,17 @@ class AppClient extends BaseClient
$sysParams["method"] = $request->getApiMethodName(); $sysParams["method"] = $request->getApiMethodName();
$sysParams["timestamp"] = date("Y-m-d H:i:s"); $sysParams["timestamp"] = date("Y-m-d H:i:s");
$sysParams["alipay_sdk"] = $this->alipaySdkVersion; $sysParams["alipay_sdk"] = $this->alipaySdkVersion;
$sysParams["terminal_type"] = $request->getTerminalType(); if ($request->getTerminalType()) {
$sysParams["terminal_info"] = $request->getTerminalInfo(); $sysParams["terminal_type"] = $request->getTerminalType();
$sysParams["prod_code"] = $request->getProdCode(); }
if ($request->getTerminalInfo()) {
$sysParams["terminal_info"] = $request->getTerminalInfo();
}
if ($request->getProdCode()) {
$sysParams["prod_code"] = $request->getProdCode();
}
$sysParams["notify_url"] = $request->getNotifyUrl(); $sysParams["notify_url"] = $request->getNotifyUrl();
$sysParams["charset"] = $this->postCharset; $sysParams["charset"] = $this->postCharset;
if (isset($this->config['auth_token'])) { if (isset($this->config['auth_token'])) {
$sysParams["auth_token"] = $this->config['auth_token']; $sysParams["auth_token"] = $this->config['auth_token'];
} }
@ -259,7 +281,7 @@ class AppClient extends BaseClient
*/ */
public function buildRequestUrl($sysParams) public function buildRequestUrl($sysParams)
{ {
return "?" .http_build_query($sysParams); return "?" . http_build_query($sysParams);
} }
/** /**

1
src/Kernel/Traits/ResponseCastable.php

@ -29,7 +29,6 @@ trait ResponseCastable
{ {
$response = Response::buildFromPsrResponse($response); $response = Response::buildFromPsrResponse($response);
$response->getBody()->rewind(); $response->getBody()->rewind();
switch ($type ?? 'array') { switch ($type ?? 'array') {
case 'collection': case 'collection':
return $response->toCollection(); return $response->toCollection();

9
src/Payment/Pay/Client.php

@ -47,14 +47,9 @@ class Client extends AppClient
} }
/** /**
* app 支付
* @param array $payload * @param array $payload
* @return \EasyAlipay\Kernel\Support\Collection * @return string
* @throws \EasyAlipay\Kernel\Exceptions\BadRequestException
* @throws \EasyAlipay\Kernel\Exceptions\InvalidArgumentException
* @throws \EasyAlipay\Kernel\Exceptions\InvalidConfigException * @throws \EasyAlipay\Kernel\Exceptions\InvalidConfigException
* @throws \EasyAlipay\Kernel\Exceptions\InvalidSignException
* @throws \GuzzleHttp\Exception\GuzzleException
*/ */
public function app(array $payload) public function app(array $payload)
{ {
@ -75,7 +70,7 @@ class Client extends AppClient
} }
$request->setBizContent($payContentBuilder->getBizContent()); $request->setBizContent($payContentBuilder->getBizContent());
$request->setApiMethodName("alipay.trade.app.pay"); $request->setApiMethodName("alipay.trade.app.pay");
return ($this->execute($request)); return ($this->sdkExecute($request));
} }
/** /**

Loading…
Cancel
Save