Browse Source

付款码轮询

gorden 6 months ago
parent
commit
96a108ed74
1 changed files with 16 additions and 10 deletions
  1. 16 10
      app/admin/service/order/OrderService.php

+ 16 - 10
app/admin/service/order/OrderService.php

@@ -261,7 +261,7 @@ class OrderService
      */
     public static function findWxpay($orderId, $nbr = 0)
     {
-        if ($nbr >= 10) {
+        if ($nbr >= 6) {
             throw new BusinessException("订单查询失败");
         }
         try {
@@ -274,32 +274,38 @@ class OrderService
         if (!empty($result['return_code']) && $result['return_code'] == 'SUCCESS' && !empty($result['result_code']) && $result['result_code'] == 'SUCCESS') {
             return $result;
         } else {
-            sleep(6);
+            sleep(5);
             self::findWxpay($orderId, $nbr + 1);
         }
     }
 
+    /**
+     * @Desc 查询支付宝订单
+     * @Author Gorden
+     * @Date 2024/8/16 15:16
+     *
+     * @param $orderId
+     * @param $nbr
+     * @return mixed|void
+     * @throws BusinessException
+     */
     public static function findAlipay($orderId, $nbr = 0)
     {
-        dump("进来了");
-        if ($nbr >= 10) {
+        if ($nbr >= 6) {
             throw new BusinessException("订单查询失败");
         }
         try {
             $result = Pay::alipay(config('payment.alipay'))->find($orderId);
             $result = json_decode(json_encode($result), true);
-            dump($result);
         } catch (\Exception $e) {
-            dump($e->getMessage());
             throw new BusinessException("订单查询失败");
         }
 
-        if (!empty($result['return_code']) && $result['return_code'] == 'SUCCESS' && !empty($result['result_code']) && $result['result_code'] == 'SUCCESS') {
+        if (!empty($result['code']) && $result['code'] == '10000' && !empty($result['trade_status']) && $result['trade_status'] == 'TRADE_SUCCESS') {
             return $result;
         } else {
-            dump("睡:".$nbr);
-            sleep(6);
-            self::findWxpay($orderId, $nbr + 1);
+            sleep(5);
+            self::findAlipay($orderId, $nbr + 1);
         }
     }