fly 5 سال پیش
والد
کامیت
c95c34266b

+ 0 - 1
app/Http/Controllers/QuickApp/Order/OrdersController.php

@@ -662,7 +662,6 @@ class OrdersController extends BaseController
     function wait(Request $request)
     {
         $param = $request->except('_url');
-        myLog('wxpay')->info($param);
         return view('pay.middleware')->with($param);
     }
 }

+ 1 - 0
app/Libs/AliApp/aop/AopClient.php

@@ -1,6 +1,7 @@
 <?php
 
 require_once 'AopEncrypt.php';
+require_once 'SignData.php';
 use AopEncrypt;
 
 class AopClient {

+ 29 - 14
app/Libs/Pay/Merchants/AliPay.php

@@ -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)

+ 10 - 4
app/Libs/Pay/Merchants/Official.php

@@ -51,7 +51,6 @@ class Official implements PayMerchantInterface
     public function send(array $data)
     {
         $app =  $this->app;
-        $payment = $app->payment;
         $trade_type = isset($data['trade_type']) ? $data['trade_type'] : 'JSAPI';
         $attributes = [
             'trade_type' => $trade_type,
@@ -63,9 +62,9 @@ class Official implements PayMerchantInterface
             'openid' => isset($data['openid']) ? $data['openid'] : '',
             'spbill_create_ip' => $data['create_ip'],
             'attach' => $data['remark']
-    ];
+        ];
         $order = new Wxorder($attributes);
-        $result = $payment->prepare($order);
+        $result = $app->payment->prepare($order);
         if ($result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS') {
             switch ($trade_type) {
                 case 'JSAPI':
@@ -134,7 +133,14 @@ class Official implements PayMerchantInterface
     }
 
     public function query(string $trade_no)
-    { }
+    {
+        $result =  $this->app->payment->query($trade_no);
+        if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS' && $result['trade_state'] === 'SUCCESS') {
+            return $result['transaction_id'];
+        } else {
+            return false;
+        }
+    }
 
     public function refund(array $data)
     { }