From df59e70e3ced1d0956749d89f0f88fa0a6a2d7f4 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期三, 16 九月 2020 04:05:59 +0800
Subject: [PATCH] 0312 兑换激活码改多线程

---
 Tool/WebCenter/CouponCode/main.py   |    4 ++--
 Tool/WebCenter/CouponCode/webapp.py |   30 +++++++++++++++++++++++++++---
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/Tool/WebCenter/CouponCode/main.py b/Tool/WebCenter/CouponCode/main.py
index 0e8b363..9ef132d 100644
--- a/Tool/WebCenter/CouponCode/main.py
+++ b/Tool/WebCenter/CouponCode/main.py
@@ -33,8 +33,8 @@
     
     CenterPort = int(ReadConfig.ReadConfig(os.getcwd() + "\\..\\Coupon\\config.ini").GetValue("Coupon", "CodePort", 53003))
     
-    # 此处不要用多线程,不然会导致同时间复用的情况,造成刷单
-    run(host='0.0.0.0', port=CenterPort, app=webapp.myapp)
+    # 多线程 需防范频繁访问情况
+    run(host='0.0.0.0', port=CenterPort, app=webapp.myapp, server='waitress')
     return
 
 if __name__ == '__main__':
diff --git a/Tool/WebCenter/CouponCode/webapp.py b/Tool/WebCenter/CouponCode/webapp.py
index eb88dcf..d60caf8 100644
--- a/Tool/WebCenter/CouponCode/webapp.py
+++ b/Tool/WebCenter/CouponCode/webapp.py
@@ -59,6 +59,15 @@
                 
 myapp = Bottle()
 
+# 闃叉鐭椂闂村唴鐨勫娆℃棤鏁堣闂� accid锛歵ime
+AccID_Cache_Dict = {}
+
+def CleanAccID():
+    global AccID_Cache_Dict
+    
+    if len(AccID_Cache_Dict) < 100:
+        return 
+    AccID_Cache_Dict = {}
 
 
 #/api/Coupon/index.php?couponBatchId=%s&agentName=%s"
@@ -117,6 +126,7 @@
 # http://center.xxx.com:53003/Coupon/CouponCode.php
 @myapp.route('/Coupon/CouponCode.php')
 def CouponCode():
+    global AccID_Cache_Dict
     dataDict = request.GET
     
     for key, value in dataDict.items():
@@ -146,6 +156,20 @@
     
     # 杞寲涓烘父鎴忚处鍙� 
     accid = "%s@%s@s%s"%(accid.lower(), spID, sid)
+    
+    try:
+        CleanAccID()
+        #mylog.debug("AccID_Cache_Dict : %s"%str(AccID_Cache_Dict))
+        if accid not in AccID_Cache_Dict:
+            AccID_Cache_Dict[accid] = int(time.time())
+        elif time.time() - AccID_Cache_Dict[accid] < 2:
+            mylog.debug("==========bad: fast click  %s"%accid)
+            return  
+            
+        AccID_Cache_Dict[accid] = int(time.time())
+    except:
+        pass
+    
     
     dbController = CouponDB.GetDBEventCon()
     if not dbController:
@@ -385,9 +409,9 @@
         post = {}
         post['pack'] = pack_data_dict;
         post['sign'] = sign;
-        result = urllib2.urlopen(gmurl, urllib.urlencode(post), 10)
+        result = urllib2.urlopen(gmurl, urllib.urlencode(post), 3)
 
-        content = result.read()
+        #content = result.read()
         result.close()
         
         # 鎴愬姛鎻愮ず
@@ -408,7 +432,7 @@
         post['sign'] = sign;
         urllib2.urlopen(gmurl, urllib.urlencode(post), 3)
         
-        return content
+        return 0
     except Exception, e:
         mylog.debug("gm error %s"%e)
     return

--
Gitblit v1.8.0