Sfoglia il codice sorgente

防止汇付并发回调导致重复发放奖励

sunxbiao 1 anno fa
parent
commit
760d8b5d9d
1 ha cambiato i file con 25 aggiunte e 0 eliminazioni
  1. 25 0
      app/controller/api/Notify.php

+ 25 - 0
app/controller/api/Notify.php

@@ -10,6 +10,7 @@ use app\common\repositories\system\merchant\MerchantRepository;
10 10
 use app\common\repositories\user\UserRepository;
11 11
 use app\controller\api\merchant\sxy\Access;
12 12
 use app\controller\api\store\service\Huafei;
13
+use think\facade\Cache;
13 14
 use think\facade\Db;
14 15
 use think\facade\Log;
15 16
 use think\facade\Request;
@@ -26,6 +27,30 @@ class Notify
26 27
         $post_data_str = isset($post['data']) ? $post['data']: '';
27 28
         $post_sign_str = isset($post['sign']) ? $post['sign']: '';
28 29
 
30
+        if (!empty($post['id'])) {
31
+            $requestId = $post['id'];
32
+            $redisKey = 'api-notify-request-id:' . $requestId;
33
+            $ttl = 60;
34
+            $redisHandler = Cache::store('redis')->handler();
35
+            $isSet = $redisHandler->set($redisKey, 1, ['nx', 'ex' => $ttl]);
36
+            if ($isSet) {
37
+                Db::name("log")->insert([
38
+                    'data' => '汇付回调处理成功 (ID: ' . $requestId . ')'
39
+                ]);
40
+            } else {
41
+                // 重复回调
42
+                Db::name("log")->insert([
43
+                    'data' => '汇付回调错误:重复回调 (ID: ' . $requestId . ')'
44
+                ]);
45
+                return app('json')->success(['result' => 'ERROR']);
46
+            }
47
+        } else {
48
+            Db::name("log")->insert([
49
+                'data' => '汇付回调错误:缺少必要参数(id)'
50
+            ]);
51
+            return app('json')->success(['result' => 'ERROR']);
52
+        }
53
+
29 54
         # 先校验签名和返回的数据的签名的数据是否一致
30 55
         $adapay_tools=new AdapayTools();
31 56
         if ($post['app_id'] == 'app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0'){