From 6366979426fccd97c0cb0bd384ada3a8b9843a24 Mon Sep 17 00:00:00 2001
From: xdh <xiefantasy@qq.com>
Date: 星期四, 25 十月 2018 14:37:22 +0800
Subject: [PATCH] 2198 【主干】仙盟盟主5天没上线,盟主没有主动传位

---
 Tool/webbottle/webapp.py |   76 +++++++++++++++++++++----------------
 1 files changed, 43 insertions(+), 33 deletions(-)

diff --git a/Tool/webbottle/webapp.py b/Tool/webbottle/webapp.py
index 00b0268..a816810 100644
--- a/Tool/webbottle/webapp.py
+++ b/Tool/webbottle/webapp.py
@@ -18,11 +18,13 @@
 import jpush
 import requests
 import urllib
+from lib import ConfigIniReader
+import json
 
-app_key = u'22186239fee975f883198cf4'
-master_secret = u'cb2b72ba143a3f3fb13a6f45'
+#app_key = u'22186239fee975f883198cf4'
+#master_secret = u'cb2b72ba143a3f3fb13a6f45'
 
-_jpush = jpush.JPush(app_key, master_secret)
+#_jpush = jpush.JPush(app_key, master_secret)
 #_jpush.set_logging("DEBUG")
 
 requests.packages.urllib3.disable_warnings()
@@ -37,55 +39,63 @@
 myapp = Bottle()
 
 Def_Split_Mark = "|"
-Def_NoName = "浜�"
-NotifyFormat = "銆�%s銆�%s" # 閫氱煡鏍煎紡  銆愮帺瀹跺悕銆戜俊鎭�
+
+# 鏂囨湰鏍煎紡GBK鍙栧嚭鍑烘潵杞瑄nicode锛屾湇鍔″櫒鍙戣繃鏉ヤ篃鏄痷nicode 鎺ㄩ�佺粺涓�unicode
+Def_NoName = ConfigIniReader.GetConfig().GetValue('Def_NoName').decode("gbk")
+NotifyFormat = ConfigIniReader.GetConfig().GetValue('NotifyFormat').decode("gbk")
 
 
 # 鎺ㄩ�佹秷鎭�
-# ?RegID=111141|1414|2141&PlayerName=鐔熺粌搴︾┖闂磡鍦h癁蹇箰|sjlkd&OSName=ios&NotifyMsg=BOSS澶嶆椿
-
+# 娣锋湇浣跨敤瀵瑰簲涓嶅悓key {骞冲彴ID锛歔[鐜╁涓帹ID锛� 鐜╁鍚峕,[鐜╁涓帹ID2锛� 鐜╁鍚�2]銆傘�傘�俔}
+# {u'822055139': [[u'160a3797c8504368d60', u'\u76f8\u601d\u59ff\u6653']]}-1234567
 
 @myapp.route('/getui/index.php', method='POST')
 def JGGeTui():
     getDict = request.POST
-    notifyMsg = urllib.unquote(getDict.get("NotifyMsg",""))
-    logging.info("%s-%s-%s"%(getDict.get("RegID",""), getDict.get("PlayerName",""), notifyMsg))
-    if not getDict.get("RegID",""):
+    notifyMsg = urllib.unquote(getDict.get("NotifyMsg","")).decode("utf8")
+    playerDict = json.loads(urllib.unquote_plus(getDict.get("PlayerInfo", "")))
+    
+    logging.info("%s-%s"%(playerDict, notifyMsg))
+    if not playerDict:
         # 鍙兘鍗昞澶氭帹锛屼笉鑳藉叏閮ㄦ帹
         return
     
-    regIDs = getDict.get("RegID","").split(Def_Split_Mark)
-    playrNames = getDict.get("PlayerName","")
-    osName = getDict.get("OSName","")
-    if not osName or osName == jpush.all_:
-        osName = jpush.all_
-    else:
-        osName = getDict.get("OSName","").split(Def_Split_Mark)
+    osName = jpush.all_
         
-    
     #logging.info("%s-%s-%s"%(getDict.get("RegID",""), playrNames, notifyMsg))
     #return "璐﹀彿锛�" + getDict.get("AccountID",""), "鍏呭��", getDict.get("money","") 
     
-    if not playrNames:
-        PushOne(regIDs, notifyMsg, osName)
-    else:
-        # 涓嶆敮鎸乶otifymsg鍐呭涓嶄竴鏍风殑澶氭帹锛屽彧鑳戒竴涓�瀵瑰簲鎺ㄩ��
-        playrNames = playrNames.split(Def_Split_Mark)
-        index = 0
-        for regID in regIDs:
-            playerName = playrNames[index] if index < len(playrNames) else Def_NoName
-            playerName = urllib.unquote(playerName)
-            geTuiMsg = NotifyFormat%(playerName, notifyMsg)
-            #logging.info("PushOne%s-%s-%s"%([regID], geTuiMsg, osName))
-            PushOne([regID], geTuiMsg, osName)
-            index += 1
+    # 绾﹀畾 {appID:[鎺ㄩ�両D1锛� 鎺ㄩ�両D2...]} 涓虹兢鎺�
+    # 绾﹀畾 {appID:[[鎺ㄩ�両D1, 鐜╁鍚嶇О1]锛� [鎺ㄩ�両D2, 鐜╁鍚嶇О2]...]} 涓轰竴涓�涓帹
+    for appID in playerDict:
+        # 鎵惧埌瀵瑰簲KEY
+        try:
+            app_key = ConfigIniReader.GetConfig().GetValue('app_key_%s'%appID)
+            master_secret = ConfigIniReader.GetConfig().GetValue('master_secret_%s'%appID)
+        except:
+            logging.warn("no key = %s"%appID)
+            continue
+        jpushObj = jpush.JPush(app_key, master_secret)
         
-def PushOne(regIDList, notifyMsg, osName=jpush.all_):
+        if type(playerDict[appID][0]) != list:  # 鍒楄〃涓殑鍏冪礌涓嶆槸鍒楄〃璇存槑鏄兢鎺�
+            PushOne(jpushObj, playerDict[appID], notifyMsg, osName)
+        else:
+            # 涓嶆敮鎸乶otifymsg鍐呭涓嶄竴鏍风殑澶氭帹锛屽彧鑳戒竴涓�瀵瑰簲鎺ㄩ��
+            for regID, playerName in playerDict[appID]:
+                playerName = playerName if playerName else Def_NoName
+                #playerName = urllib.unquote(playerName)
+                #playerName = playerName.encode('utf-8')
+                geTuiMsg = NotifyFormat%(playerName, notifyMsg)
+                #logging.info("PushOne%s-%s-%s"%([regID], geTuiMsg, osName))
+                PushOne(jpushObj, [regID], geTuiMsg, osName)
+
+        
+def PushOne(jpushObj, regIDList, notifyMsg, osName=jpush.all_):
     # 1.鎺ㄩ�佸璞� 鍗曟帹锛堝鎺級锛�  缇ゆ帹鍙兘鎻愪氦涓績鎺�
     # 2.骞冲彴 ios  瀹夊崜  榛樿鍏ㄥ钩鍙�
     # 3.閫氱煡娑堟伅
     
-    push = _jpush.create_push()
+    push = jpushObj.create_push()
     push.audience =  {"registration_id" : regIDList}
     push.notification = jpush.notification(alert=notifyMsg)
     push.platform = osName

--
Gitblit v1.8.0