|
@@ -5,10 +5,11 @@ namespace App\Libs\Pay\Merchants;
|
|
|
require_once dirname(__FILE__) . '../../../AliApp/aop/AopClient.php';
|
|
|
require_once dirname(__FILE__) . '../../../AliApp/aop/request/AlipayTradeWapPayRequest.php';
|
|
|
require_once dirname(__FILE__) . '../../../AliApp/aop/request/AlipayTradeAppPayRequest.php';
|
|
|
+require_once dirname(__FILE__) . '../../../AliApp/aop/request/AlipayTradeQueryRequest.php';
|
|
|
|
|
|
class AliPay implements PayMerchantInterface
|
|
|
{
|
|
|
- private $app;
|
|
|
+ private $aop;
|
|
|
|
|
|
const GATE_WAY_URL = 'https://openapi.alipay.com/gateway.do';
|
|
|
|
|
@@ -24,14 +25,14 @@ class AliPay implements PayMerchantInterface
|
|
|
|
|
|
public function __construct()
|
|
|
{
|
|
|
- $this->app = new \AopClient;
|
|
|
- $this->app->appId = self::APPID;
|
|
|
- $this->app->rsaPrivateKey = self::RSAPRIVATEKEY;
|
|
|
- $this->app->alipayrsaPublicKey = self::ALIPAYRSAPUBLICKEY;
|
|
|
- $this->app->signType = self::SIGN_TYPE;
|
|
|
- $this->app->gatewayUrl = self::GATE_WAY_URL;
|
|
|
- $this->app->postCharset = 'GBK';
|
|
|
- $this->app->format = 'json';
|
|
|
+ $this->aop = new \AopClient;
|
|
|
+ $this->aop->appId = self::APPID;
|
|
|
+ $this->aop->rsaPrivateKey = self::RSAPRIVATEKEY;
|
|
|
+ $this->aop->alipayrsaPublicKey = self::ALIPAYRSAPUBLICKEY;
|
|
|
+ $this->aop->signType = self::SIGN_TYPE;
|
|
|
+ $this->aop->gatewayUrl = self::GATE_WAY_URL;
|
|
|
+ $this->aop->postCharset = 'GBK';
|
|
|
+ $this->aop->format = 'json';
|
|
|
}
|
|
|
|
|
|
public function send(array $data)
|
|
@@ -62,7 +63,7 @@ class AliPay implements PayMerchantInterface
|
|
|
$request->setBizContent(json_encode($data));
|
|
|
$request->setNotifyUrl(env('ALI_PAY_CALL_BACK'));
|
|
|
$request->setReturnUrl($return_url);
|
|
|
- return $this->app->pageExecute($request);
|
|
|
+ return $this->aop->pageExecute($request);
|
|
|
}
|
|
|
|
|
|
private function AlipayTradeAppPayRequest(array $data)
|
|
@@ -70,18 +71,32 @@ class AliPay implements PayMerchantInterface
|
|
|
$request = new \AlipayTradeAppPayRequest();
|
|
|
$request->setBizContent(json_encode($data));
|
|
|
$request->setNotifyUrl(env('ALI_PAY_CALL_BACK'));
|
|
|
- return $this->app->sdkExecute($request);
|
|
|
+ return $this->aop->sdkExecute($request);
|
|
|
}
|
|
|
|
|
|
|
|
|
public function notify(array $data)
|
|
|
{
|
|
|
- return $this->app->rsaCheckV1($data, $this->rsaPublicKeyFilePath, self::SIGN_TYPE);
|
|
|
+ if (isset($data['sign'])) {
|
|
|
+ return $this->aop->rsaCheckV1($data, $this->rsaPublicKeyFilePath, self::SIGN_TYPE);
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public function query(string $trade_no)
|
|
|
- {
|
|
|
-
|
|
|
+ {
|
|
|
+ $this->aop->postCharset = 'utf-8';
|
|
|
+ $request = new \AlipayTradeQueryRequest();
|
|
|
+ $request->setBizContent(json_encode(['out_trade_no' => $trade_no]));
|
|
|
+ $result = $this->aop->execute($request);
|
|
|
+ $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
|
|
|
+ $resultCode = $result->$responseNode->code;
|
|
|
+ if (!empty($resultCode) && $resultCode == 10000) {
|
|
|
+ return $result->$responseNode->trade_no;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public function refund(array $data)
|