2
0
Tree 3 هفته پیش
والد
کامیت
752b84f320

+ 16 - 0
app/Http/Controllers/Api/AiPayController.php

@@ -8,6 +8,7 @@ use App\Inter\PayMentInterFace;
 use App\Notification\TelegramBot;
 use App\Services\AiPay;
 use App\Util;
+use App\Utility\SetNXLock;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Redis;
 
@@ -61,6 +62,19 @@ class AiPayController implements PayMentInterFace
             return 'fail';
         }
 
+        $order_sn = $post['mchOrderNo'] ?? '';
+        if (empty($order_sn)) {
+            Util::WriteLog('AiPay', '缺少订单号');
+            return 'fail';
+        }
+
+        // 代收回调加锁,防止并发重复处理
+        $lockKey = 'pay_notify_AiPay_' . $order_sn;
+        if (!SetNXLock::getExclusiveLock($lockKey, 60)) {
+            Util::WriteLog('AiPay', '代收回调并发,订单已处理或处理中: ' . $order_sn);
+            return 'success';
+        }
+
         $logic = new AiPayLogic();
         try {
             return $logic->notify($post);
@@ -68,6 +82,8 @@ class AiPayController implements PayMentInterFace
             Redis::set('PayErro_AiPay', 1, 'EX', 600);
             //TelegramBot::getDefault()->sendProgramNotify('AiPay notify exception', json_encode($post), $exception);
             return '{"success":false,"message":"internal error"}';
+        } finally {
+            SetNXLock::release($lockKey);
         }
     }
 

+ 16 - 0
app/Http/Controllers/Api/CoinPayController.php

@@ -8,6 +8,7 @@ use App\Inter\PayMentInterFace;
 use App\Notification\TelegramBot;
 use App\Services\CoinPay;
 use App\Util;
+use App\Utility\SetNXLock;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Redis;
 
@@ -61,12 +62,27 @@ class CoinPayController implements PayMentInterFace
             return 'fail';
         }
 
+        $order_sn = $post['merchantOrderNo'] ?? '';
+        if (empty($order_sn)) {
+            Util::WriteLog('CoinPay', '缺少订单号');
+            return 'fail';
+        }
+
+        // 代收回调加锁,防止并发重复处理
+        $lockKey = 'pay_notify_CoinPay_' . $order_sn;
+        if (!SetNXLock::getExclusiveLock($lockKey, 60)) {
+            Util::WriteLog('CoinPay', '代收回调并发,订单已处理或处理中: ' . $order_sn);
+            return 'SUCCESS';
+        }
+
         $logic = new CoinPayLogic();
         try {
             return $logic->notify($post);
         } catch (\Throwable $exception) {
             Redis::set('PayErro_CoinPay', 1, 'EX', 600);
             return '{"success":false,"message":"internal error"}';
+        } finally {
+            SetNXLock::release($lockKey);
         }
     }
 

+ 10 - 0
app/Http/Controllers/Api/PagYeepPayController.php

@@ -10,6 +10,7 @@ use App\Services\PagYeepPay;
 use App\Services\PayConfig;
 use App\Services\PayUtils;
 use App\Util;
+use App\Utility\SetNXLock;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Redis;
@@ -87,6 +88,13 @@ class PagYeepPayController implements PayMentInterFace
             return 'SC000000';
         }
 
+        // 代收回调加锁,防止并发重复处理
+        $lockKey = 'pay_notify_PagYeepPay_' . $order_sn;
+        if (!SetNXLock::getExclusiveLock($lockKey, 60)) {
+            Util::WriteLog('PagYeepPay', '代收回调并发,订单已处理或处理中: ' . $order_sn);
+            return 'SC000000';
+        }
+
         $logic = new PagYeepPayLogic();
         try {
             $redis = Redis::connection();
@@ -101,6 +109,8 @@ class PagYeepPayController implements PayMentInterFace
             TelegramBot::getDefault()->sendProgramNotify("PagYeepPay 订单回调执行 异常 ", json_encode($post), $exception);
             Util::WriteLog("PagYeepPay_error", $exception->getMessage());
             return 'SC000000';
+        } finally {
+            SetNXLock::release($lockKey);
         }
     }
 

+ 10 - 0
app/Http/Controllers/Api/WDPayController.php

@@ -10,6 +10,7 @@ use App\Services\WDPay;
 use App\Services\PayConfig;
 use App\Services\PayUtils;
 use App\Util;
+use App\Utility\SetNXLock;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Redis;
@@ -95,6 +96,13 @@ class WDPayController implements PayMentInterFace
             return response()->json(['success' => false, 'message' => 'Missing customerOrderNo']);
         }
 
+        // 代收回调加锁,防止并发重复处理
+        $lockKey = 'pay_notify_WDPay_' . $order_sn;
+        if (!SetNXLock::getExclusiveLock($lockKey, 60)) {
+            Util::WriteLog('WDPay', '代收回调并发,订单已处理或处理中: ' . $order_sn);
+            return '{"msg":"success","code":200}';
+        }
+
         $logic = new WDPayLogic();
         try {
             $redis = Redis::connection();
@@ -109,6 +117,8 @@ class WDPayController implements PayMentInterFace
             TelegramBot::getDefault()->sendProgramNotify("WDPay 订单回调执行 异常 ", json_encode($post), $exception);
             Util::WriteLog("WDPay_error", $exception->getMessage());
             return response()->json(['success' => false, 'message' => 'Process failed']);
+        } finally {
+            SetNXLock::release($lockKey);
         }
     }
 

+ 15 - 0
app/Http/Controllers/Api/WiwiPayController.php

@@ -10,6 +10,7 @@ use App\Services\WiwiPay;
 use App\Services\PayConfig;
 use App\Services\PayUtils;
 use App\Util;
+use App\Utility\SetNXLock;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Redis;
@@ -79,6 +80,18 @@ class WiwiPayController implements PayMentInterFace
         }
 
         $order_sn = @$post['mchOrderNo'];
+        if (empty($order_sn)) {
+            Util::WriteLog('WiwiPay', '缺少订单号');
+            return 'fail';
+        }
+
+        // 代收回调加锁,防止并发重复处理
+        $lockKey = 'pay_notify_WiwiPay_' . $order_sn;
+        if (!SetNXLock::getExclusiveLock($lockKey, 60)) {
+            Util::WriteLog('WiwiPay', '代收回调并发,订单已处理或处理中: ' . $order_sn);
+            return 'success';
+        }
+
         $logic = new WiwiPayLogic();
         try {
             $redis = Redis::connection();
@@ -91,6 +104,8 @@ class WiwiPayController implements PayMentInterFace
             TelegramBot::getDefault()->sendProgramNotify("WiwiPay 订单回调执行 异常 ", json_encode($post), $exception);
             Util::WriteLog("WiwiPay_error", $post);
             return '{"success":false,"message":"商户自定义出错信息"}';
+        } finally {
+            SetNXLock::release($lockKey);
         }
     }