Parcourir la source

ali pay new version 支付宝支付改版

onlinetest il y a 4 ans
Parent
commit
a6a33bb7c4

+ 16 - 10
app/Http/Controllers/QuickApp/Order/OrdersController.php

@@ -545,6 +545,7 @@ class OrdersController extends BaseController
     public function aliIndex(Request $request)
     {
         if ($params = $this->getPayParams($request)) {
+            $params['pay_merchant_id'] = $this->ali_pay_merchat_id;
             $params['type'] = 'App';
         } else {
             return response()->error('QAPP_PARAM_ERROR');
@@ -593,7 +594,6 @@ class OrdersController extends BaseController
         $xml = XML::parse(strval($request->getContent()));
         myLog('wxpay')->info($xml);
         if (isset($xml['attach'])) {
-
             $pay_merchant_id = (int) $xml['attach'];
             $config = PayMerchantService::findPayConfig($pay_merchant_id);
             $app = PayFactory::official($config);
@@ -619,18 +619,24 @@ class OrdersController extends BaseController
     function aliback(Request $request)
     {
         $param = $request->except('_url');
-        $app = PayFactory::aliPay();
         myLog('alipay')->info($param);
-        if ($app->notify($param)) {
-            if (OrderPaySuccess::handle($param['out_trade_no'], $param['trade_no'])) {
-                return response('success');
-            } else {
-                return response('fail');
+        $trade_no = isset($param['out_trade_no']) ? $param['out_trade_no'] : '';
+        if ($trade_no) {
+            $order = Order::where('trade_no', $trade_no)->first();  
+            $pay_merchant_id = $order ? $order->pay_merchant_id : 0;
+            $pay_merchant_id = $pay_merchant_id ? $pay_merchant_id : 132;
+            $config = PayMerchantService::findAliPayConfig($pay_merchant_id);
+            $app = PayFactory::aliPay($config);
+            if ($app->notify($param)) {
+                if (OrderPaySuccess::handle($param['out_trade_no'], $param['trade_no'])) {
+                    return response('success');
+                } else {
+                    return response('fail');
+                }
             }
-        } else {
-            myLog('alipay')->info('sign fail');
-            return response('fail');
         }
+        myLog('alipay')->info('sign fail');
+        return response('fail');
     }
 
     function wait(Request $request)

Fichier diff supprimé car celui-ci est trop grand
+ 13 - 9
app/Libs/Pay/Merchants/AliPay.php


+ 1 - 1
app/Libs/Pay/PayFactory.php

@@ -6,7 +6,7 @@ namespace App\Libs\Pay;
 /**
  * @method static \App\Libs\Pay\Merchants\UnionPay unionPay(array $data)
  * @method static \App\Libs\Pay\Merchants\Official official(array $data)
- * @method static \App\Libs\Pay\Merchants\AliPay aliPay()
+ * @method static \App\Libs\Pay\Merchants\AliPay aliPay(array $config)
  */
 class PayFactory
 {

+ 5 - 1
app/Modules/Trade/Pay/AliOrderArousePay.php

@@ -3,6 +3,7 @@
 namespace App\Modules\Trade\Pay;
 
 use App\Libs\Pay\PayFactory;
+use App\Modules\Trade\Services\PayMerchantService;
 use Exception;
 use Illuminate\Support\Facades\Log;
 
@@ -10,6 +11,7 @@ class AliOrderArousePay extends OrderArousePayAbstract
 {
     public function arouse(array $data)
     {
+        $pay_merchant_id = (int) $data['pay_merchant_id'];
         $ali_param = [
             'body' => '小说阅读',
             'subject' => '追书云',
@@ -19,9 +21,11 @@ class AliOrderArousePay extends OrderArousePayAbstract
             'product_code' => 'QUICK_WAP_WAY',
             'return_url' => '',
             'type' => $data['type'],
+            'pay_merchant_id' => $pay_merchant_id,
         ];
         try {
-            $pay = PayFactory::aliPay();
+            $config = PayMerchantService::findAliPayConfig($pay_merchant_id);
+            $pay = PayFactory::aliPay($config);
             $result = $pay->send($ali_param);
             return $result;
         } catch (Exception $e) {

+ 14 - 0
app/Modules/Trade/Services/PayMerchantService.php

@@ -29,6 +29,20 @@ class PayMerchantService
     }
 
     /**
+     * 查找微信支付配置信息
+     */
+    public static function findAliPayConfig(int $id)
+    {
+        $pay_merchant = PayMerchant::find($id);
+        $pay_config = json_decode($pay_merchant->config_info);
+        return [
+            'app_id'     => $pay_config->app_id,
+            'ali_pub_key'     => $pay_config->ali_pub_key,
+            'pri_key'    => $pay_config->pri_key,
+        ];
+    }
+
+    /**
      * 根据ID查找
      * @param $id
      * @return mixed