From d2d8ca57a661abb973550f35b8112b5078c1defb Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期一, 16 十二月 2024 15:27:39 +0800
Subject: [PATCH] 10297 【越南】【英语】【砍树】【tqxbqy】轮回殿-服务端(奖励类型增加类型3 - 消耗物品,目前支持坐骑经验丹、灵宠经验丹)
---
Tool/WebCenter/CouponCode/webapp.py | 467 +++++++++++++++++++++++++++++++--------------------------
1 files changed, 255 insertions(+), 212 deletions(-)
diff --git a/Tool/WebCenter/CouponCode/webapp.py b/Tool/WebCenter/CouponCode/webapp.py
index 2468ab8..c827426 100644
--- a/Tool/WebCenter/CouponCode/webapp.py
+++ b/Tool/WebCenter/CouponCode/webapp.py
@@ -25,6 +25,7 @@
import os.path
import zipfile
import time
+import traceback
# get: request.query.username request.GET.get('username','')
# post: request.forms.get('username') request.POST.get('username')
@@ -45,17 +46,62 @@
# GM绔彛
PushPort = ConfigIO.GetValue("Coupon", "PushPort")
PushKey = ConfigIO.GetValue("Coupon", "PushKey")
+PushTimeout = ConfigIO.GetInt("Coupon", "PushTimeout", 5)
CommonCards = eval(ConfigIO.GetValue("Coupon", "CommonCards"))
-
-
-Def_CardMsg = {
- 0:"CodeRewardSys2", # 鍏戞崲鐮佹棤鏁�
- 1: "CodeRewardSys1", # 鍏戞崲鍗″鍔卞凡鍙戣嚦閭欢
- 2:"CodeRewardSys3", # 鍏戞崲鐮佸凡浣跨敤杩�
- 3:"CodeRewardSys4", # 鍚岀被鍨嬪厬鎹㈢爜鍙兘浣跨敤涓�娆�
- }
-
-
+
+g_mailJsonDict = {} # {channel:MailJson, ...}
+# 鍙戞斁濂栧姳閭欢鍐呭json锛寀tf8缂栫爜
+def GetMailJson(channel):
+ global g_mailJsonDict
+ if channel in g_mailJsonDict:
+ return g_mailJsonDict[channel]
+ jsonPath = os.getcwd() + ("\\..\\Coupon\\CodeMail_%s.json" % channel)
+ if not os.path.isfile(jsonPath):
+ jsonPath = os.getcwd() + "\\..\\Coupon\\CodeMail.json"
+ f = open(jsonPath, "r")
+ MailJson = eval(f.read())
+ f.close()
+ g_mailJsonDict[channel] = MailJson
+ return MailJson
+
+# 绀煎寘浣跨敤杩斿洖缁撴灉鐮佸畾涔�
+ErrCode_OK = 0 # 鎴愬姛锛岄潪0鐨勭爜鍧囦唬琛ㄩ敊璇�
+ErrCode_Invalid = 1 # 鍏戞崲鐮佹棤鏁�
+ErrCode_Used = 2 # 绀煎寘鐮佸凡琚娇鐢�
+ErrCode_TypeUsed = 3 # 宸茬粡浣跨敤杩囧悓绫诲瀷鐨勭ぜ鍖呯爜
+ErrCode_LVLimit = 4 # 绛夌骇涓嶈冻
+ErrCode_VIPLVLimit = 5 # VIP绛夌骇涓嶈冻
+ErrCode_ParamErr = 97 # 鍙傛暟閿欒
+ErrCode_FrequentRequest = 98 # 棰戠箒璇锋眰
+ErrCode_OtherErr = 99 # 鍏朵粬閿欒锛屾瘮濡傝繍琛岄敊璇瓑
+
+# 绀煎寘鐮佸鐞嗙粨鏋滅爜淇℃伅 {code:["鐮佷俊鎭鏄�", "缁欑帺瀹剁殑绯荤粺鎻愮ずkey"], ...}
+ErrCodeMsgInfo = {
+ ErrCode_OK:["OK", "CodeRewardSys1"],
+ ErrCode_Invalid:["code invalid", "CodeRewardSys2"],
+ ErrCode_Used:["code has been used", "CodeRewardSys3"],
+ ErrCode_TypeUsed:["You has been used this Giftcode type", "CodeRewardSys4"],
+ ErrCode_LVLimit:["level limit", "LvErr"],
+ ErrCode_VIPLVLimit:["vip level limit", "VipLevel"],
+ ErrCode_ParamErr:["parameter error", ""],
+ ErrCode_FrequentRequest:["frequent request", ""],
+ ErrCode_OtherErr:["other error", ""],
+ }
+
+def CouponCodeResponse(errcode, msgEx=""):
+ errmsg = ""
+ if errcode in ErrCodeMsgInfo:
+ errmsg = ErrCodeMsgInfo[errcode][0]
+ if msgEx:
+ errmsg = "%s : %s" % (errmsg, msgEx)
+ resData = {"errcode":errcode, "errmsg":errmsg}
+ if errcode != ErrCode_OK:
+ mylog.error("resError: %s" % str(resData))
+ else:
+ mylog.debug("resData: %s" % str(resData))
+ #mylog.info("resData: %s" % str(resData))
+ return json.dumps(resData, ensure_ascii=False)
+
myapp = Bottle()
@@ -83,9 +129,9 @@
if not couponid:
return json.dumps({"error":"param couponid"}, ensure_ascii=False)
- downFile = r".\download\%s.zip"%couponid
+ downFile = r".\download\%s.zip" % couponid
if os.path.isfile(downFile):
- return static_file("%s.zip"%couponid, r".\download", download=True)
+ return static_file("%s.zip" % couponid, r".\download", download=True)
dbController = CouponDB.GetDBEventCon()
if not dbController:
@@ -96,16 +142,16 @@
if not data:
return json.dumps({"error":"no couponid"}, ensure_ascii=False)
- fileIO = open(r".\download\%s.txt"%couponid, 'w')
+ fileIO = open(r".\download\%s.txt" % couponid, 'w')
for codeInfo in data:
fileIO.write(codeInfo["code"] + "\n")
fileIO.close()
f = zipfile.ZipFile(downFile, 'w', zipfile.ZIP_DEFLATED)
- f.write(r".\download\%s.txt"%couponid)
+ f.write(r".\download\%s.txt" % couponid)
f.close()
- return static_file("%s.zip"%couponid, r".\download", download=True)
+ return static_file("%s.zip" % couponid, r".\download", download=True)
#================瀹㈡埛绔姹傚弬鏁�===============================================================
@@ -130,32 +176,33 @@
dataDict = request.GET
for key, value in dataDict.items():
- mylog.debug("CouponCode key:%s value:%s"%(key, value))
+ mylog.debug("CouponCode key:%s value:%s" % (key, value))
agentName = dataDict.get("channel", "") # 杩愯惀鎻愪緵鐨凙PPID锛屽嵆娓犻亾
if not agentName:
- mylog.debug("no appid")
- return
+ return CouponCodeResponse(ErrCode_ParamErr, "no channel appid")
codeStr = dataDict.get("code", "")
if not codeStr:
- return
+ return CouponCodeResponse(ErrCode_ParamErr, "no code")
codeStr = codeStr.strip()
#鍙槸鐢ㄦ潵鎷兼帴璐﹀彿
spID = dataDict.get("spid", "")
-
+ if not spID:
+ return CouponCodeResponse(ErrCode_ParamErr, "no spid")
+
accid = dataDict.get("accid", "")
if not accid:
- return
+ return CouponCodeResponse(ErrCode_ParamErr, "no accid")
sid = CommFunc.ToIntDef(dataDict.get("sid", 0), 0)
if not sid:
- return
+ return CouponCodeResponse(ErrCode_ParamErr, "no sid")
pushurl = dataDict.get("pushurl", "")
if not pushurl:
- return
+ return CouponCodeResponse(ErrCode_ParamErr, "no pushurl")
# 杞寲涓烘父鎴忚处鍙�
- accid = "%s@%s@s%s"%(accid.lower(), spID, sid)
+ accid = "%s@%s@s%s" % (accid.lower(), spID, sid)
try:
CleanAccID()
@@ -163,8 +210,8 @@
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
+ mylog.debug("==========bad: fast click %s" % accid)
+ return CouponCodeResponse(ErrCode_FrequentRequest)
AccID_Cache_Dict[accid] = int(time.time())
except:
@@ -174,12 +221,11 @@
dbController = CouponDB.GetDBEventCon()
if not dbController:
# 鏃犳硶鑾峰彇鏁版嵁搴�
- mylog.debug("no dbController")
- return
-
+ return CouponCodeResponse(ErrCode_OtherErr, "no dbController")
+
#閫氳繃GM鎺ュ彛鍛婄煡鐜╁浣跨敤鎯呭喌
gmresult = {'accID':accid, 'sid':sid, 'channel':agentName}
-
+
#-----------缁熶竴鍥哄畾鐮佸鐞�----------------------
CommonCardsList = CommonCards.get(agentName, [])
if codeStr in CommonCardsList:
@@ -187,39 +233,40 @@
result, commondata = dbController.find_one(CouponDB.CouponCodeColName + "_Common", {"code":codeStr, "accid":accid})
if commondata:
# 宸蹭娇鐢�
- gmresult['status'] = 2
- mylog.debug("common status=2")
- return SendGm(gmresult, pushurl)
+ return SendGm(ErrCode_Used, gmresult, pushurl)[1]
- gmresult['status'] = 1
+ commCheckStatus = CommCheck(dataDict, codeStr)
+ if commCheckStatus != None:
+ return SendGm(commCheckStatus, gmresult, pushurl)[1]
+
gmresult['code'] = codeStr
gmresult['coupontype'] = codeStr # 缁熶竴鏍煎紡锛屾湇鍔″櫒涓嶄竴瀹氭湁鐢紝鍥哄畾鐮佹牴鎹� codeStr 鍙戝鍔�
- dbController.insert(CouponDB.CouponCodeColName + "_Common", {"code":codeStr, "accid":accid})
- mylog.debug("common ok")
- return SendGm(gmresult, pushurl)
-
+ retCode, retMsg = SendGm(ErrCode_OK, gmresult, pushurl)
+ if retCode == ErrCode_OK:
+ dbController.insert(CouponDB.CouponCodeColName + "_Common", {"code":codeStr, "accid":accid})
+ mylog.debug("common ok")
+ return retMsg
+
#-----------寰俊鍟嗗煄----------------------
if codeStr.startswith('wx'):
operateID = GetOperateID(agentName)
if not operateID:
- mylog.debug("wx no appid = %s"%agentName)
- return
+ return CouponCodeResponse(ErrCode_OtherErr, "wx no appid = %s" % agentName)
result, wxdata = dbController.find_one(CouponDB.CouponWXColName, {"code":codeStr, "operateid":operateID})
if not wxdata:
- return
+ return CouponCodeResponse(ErrCode_OtherErr, "not wxdata code(%s) operateID(%s)" % (codeStr, operateID))
if int(wxdata['status']) == 1:
- gmresult['status'] = 2
mylog.debug("wxcard used!")
- return SendGm(gmresult, pushurl)
+ return SendGm(ErrCode_Used, gmresult, pushurl)[1]
wxdata['status'] = 1
wxdata['accid'] = dataDict.get("accid", "") # 姝ゅ鐢ㄥ師濮嬭处鍙�
wxdata['usetime'] = str(datetime.datetime.today()).split(".")[0]
wxdata['appid'] = agentName
- wxdata['serverid'] = 's%s'%sid
+ wxdata['serverid'] = 's%s' % sid
wxdata['roleid'] = dataDict.get("roleid", "")
wxdata['level'] = dataDict.get("level", "")
wxdata['viplevel'] = dataDict.get("viplevel", "")
@@ -228,222 +275,214 @@
dbController.update(CouponDB.CouponWXColName, {"code":codeStr, "operateid":operateID}, wxdata)
# 閫氱煡鍚庡彴璁板綍
SendDataCollectorBillInfo(wxdata, pushurl, operateID)
- return
+ return CouponCodeResponse(ErrCode_OK)
+ return CouponCodeResponse(ErrCode_OtherErr, "SendWXBill error")
- #-----------鎵归噺鍏戞崲鐮佸鐞嗭紝鍚岀被鍨嬪彲閲嶅棰嗗彇----------------------
- if codeStr.startswith('h'):
- result, data = dbController.find_one(CouponDB.CouponCodeColName + "_" + agentName, {"code":codeStr, "channel":agentName})
-
- if not data:
- #鏃犳鍗�
- gmresult['status'] = 0
- mylog.debug("no card")
- return SendGm(gmresult, pushurl)
- if int(data['status']) == 1:
- #宸蹭娇鐢紝鍚屽崱鍙疯褰曢粯璁ゅ彲鐢紝閬垮厤鏂嚎鍙戦�佸け璐ョ殑鎯呭喌锛堟湭杩斿洖缁撴灉楠岃瘉鎯呭喌涓嬶級
- gmresult['status'] = 2
- mylog.debug("card used!")
- return SendGm(gmresult, pushurl)
-
- result, data2 = dbController.find_one(CouponDB.CouponBatchColName, {"couponid":data["couponid"]})
- if not data2:
- #姝ゆ壒娆″崱宸插垹闄�
- gmresult['status'] = 0
- mylog.debug("no couponid")
- return SendGm(gmresult, pushurl)
- if int(data2['status']) == 1:
- #鏆傚仠浣跨敤璇ユ壒娆″崱
- gmresult['status'] = 0
- mylog.debug("couponid frozed")
- return SendGm(gmresult, pushurl)
- if (data2["minserverno"] != 0 and data2["maxserverno"] != 0):
- if int(data2["minserverno"]) > sid or int(data2["maxserverno"]) < sid:
- #涓嶅湪鎸囧畾鍖�
- gmresult['status'] = 0
- mylog.debug("no sid")
- return SendGm(gmresult, pushurl)
- if data2["expiretime"] != "" and datetime.datetime.today() > GetDateTimeByStr(data2["expiretime"]):
- #宸茶繃鏈�
- gmresult['status'] = 0
- mylog.debug("time pass")
- return SendGm(gmresult, pushurl)
-
- #鍙噸澶嶉鍙栧垯涓嶉獙璇佸悓鎵规鍗�
- data['status'] = 1
- data['accid'] = accid
- data['usetime'] = str(datetime.datetime.today())
-
- dbController.update(CouponDB.CouponCodeColName + "_" + agentName, {"code":codeStr, "channel":agentName}, data)
- # 0 涓嶅彲鐢紝1.鍙敤鍙戞斁濂栧姳 锛�2.宸蹭娇鐢� 3.鍚岀被鍨嬪崱涓嶈兘浣跨敤涓ゆ
- gmresult['status'] = 1
- gmresult['code'] = codeStr
- gmresult['coupontype'] = data["coupontype"]
-
- mylog.debug("card ok!")
- return SendGm(gmresult, pushurl)
-
#-----------鎵归噺鍏戞崲鐮佸鐞嗭紝鍚岀被鍨嬪彧棰嗗彇涓�娆�----------------------
result, data = dbController.find_one(CouponDB.CouponCodeColName + "_" + agentName, {"code":codeStr, "channel":agentName})
-
+
if not data:
#鏃犳鍗�
- gmresult['status'] = 0
mylog.debug("no card")
- return SendGm(gmresult, pushurl)
+ return SendGm(ErrCode_Invalid, gmresult, pushurl)[1]
if int(data['status']) == 1:
#宸蹭娇鐢紝鍚屽崱鍙疯褰曢粯璁ゅ彲鐢紝閬垮厤鏂嚎鍙戦�佸け璐ョ殑鎯呭喌锛堟湭杩斿洖缁撴灉楠岃瘉鎯呭喌涓嬶級
- gmresult['status'] = 2
mylog.debug("card used!")
- return SendGm(gmresult, pushurl)
+ return SendGm(ErrCode_Used, gmresult, pushurl)[1]
+
+ couponType = data["coupontype"]
+ commCheckStatus = CommCheck(dataDict, data["coupontype"])
+ if commCheckStatus != None:
+ return SendGm(commCheckStatus, gmresult, pushurl)[1]
result, data2 = dbController.find_one(CouponDB.CouponBatchColName, {"couponid":data["couponid"]})
if not data2:
#姝ゆ壒娆″崱宸插垹闄�
- gmresult['status'] = 0
mylog.debug("no couponid")
- return SendGm(gmresult, pushurl)
+ return SendGm(ErrCode_Invalid, gmresult, pushurl)[1]
if int(data2['status']) == 1:
#鏆傚仠浣跨敤璇ユ壒娆″崱
- gmresult['status'] = 0
mylog.debug("couponid frozed")
- return SendGm(gmresult, pushurl)
+ return SendGm(ErrCode_Invalid, gmresult, pushurl)[1]
if (data2["minserverno"] != 0 and data2["maxserverno"] != 0):
if int(data2["minserverno"]) > sid or int(data2["maxserverno"]) < sid:
#涓嶅湪鎸囧畾鍖�
- gmresult['status'] = 0
mylog.debug("no sid")
- return SendGm(gmresult, pushurl)
+ return SendGm(ErrCode_Invalid, gmresult, pushurl)[1]
if data2["expiretime"] != "" and datetime.datetime.today() > GetDateTimeByStr(data2["expiretime"]):
#宸茶繃鏈�
- gmresult['status'] = 0
mylog.debug("time pass")
- return SendGm(gmresult, pushurl)
- #鍐嶆煡涓�娆℃槸鍚︾敤杩囨鎵规鐨勫叾浠栧崱,
- result, data3 = dbController.find_one(CouponDB.CouponCodeColName + "_" + agentName, \
- {"couponid":data["couponid"], "accid":accid})
- if data3:
- #鐢ㄨ繃鍚岀被鍗★紝宸茶褰曡繃涓嶅啀鍋氭柊璁板綍
- gmresult['status'] = 3
- gmresult['coupontype'] = data["coupontype"]
- gmresult['code'] = codeStr
- mylog.debug("use again")
- return SendGm(gmresult, pushurl)
+ return SendGm(ErrCode_Invalid, gmresult, pushurl)[1]
+ maxUseCount = 0 # -1-鏃犻檺锛�0鎴�1-榛樿1娆★紱 >1-闄愬埗娆℃暟锛� 娌℃湁閰嶇疆鐨勯粯璁�0鍗抽粯璁�1娆�
+ prefix = "" # 鍥哄畾鍓嶇紑
+ MailJson = GetMailJson(agentName)
+ if couponType in MailJson:
+ mailInfo = MailJson[couponType]
+ prefix = mailInfo.get("Prefix", "")
+ maxUseCount = CommFunc.ToIntDef(mailInfo.get("MaxUseCount", 0))
+ elif ConfigIO.HasSection(couponType):
+ if ConfigIO.HasOption(couponType, "Prefix"):
+ prefix = ConfigIO.GetValue(couponType, "Prefix")
+ maxUseCount = ConfigIO.GetInt(couponType, "MaxUseCount")
+
+ # h 寮�澶寸殑鍗$被鍨嬪彲閲嶅浣跨敤
+ #if not codeStr.startswith(prefix + 'h'):
+ #淇敼涓烘寜閰嶇疆鏈�澶ф鏁板垽鏂嵆鍙�
+ if maxUseCount in [0, 1]:
+ #鍐嶆煡涓�娆℃槸鍚︾敤杩囨鎵规鐨勫叾浠栧崱,
+ result, data3 = dbController.find_one(CouponDB.CouponCodeColName + "_" + agentName, \
+ {"coupontype":data["coupontype"], "accid":accid})
+ if data3:
+ #鐢ㄨ繃鍚岀被鍗★紝宸茶褰曡繃涓嶅啀鍋氭柊璁板綍
+ gmresult['coupontype'] = data["coupontype"]
+ gmresult['code'] = codeStr
+ mylog.debug("use again")
+ return SendGm(ErrCode_TypeUsed, gmresult, pushurl)[1]
+ elif maxUseCount > 1:
+ result, resultList = dbController.find(CouponDB.CouponCodeColName + "_" + agentName, {"coupontype":data["coupontype"], "accid":accid}, {"code":1})
+ if not result or len(resultList) >= maxUseCount:
+ gmresult['coupontype'] = data["coupontype"]
+ gmresult['code'] = codeStr
+ mylog.debug("use maxUseCount limit. %s" % maxUseCount)
+ return SendGm(ErrCode_TypeUsed, gmresult, pushurl)[1]
+
data['status'] = 1
data['accid'] = accid
data['usetime'] = str(datetime.datetime.today())
- dbController.update(CouponDB.CouponCodeColName + "_" + agentName, {"code":codeStr, "channel":agentName}, data)
- # 0 涓嶅彲鐢紝1.鍙敤鍙戞斁濂栧姳 锛�2.宸蹭娇鐢� 3.鍚岀被鍨嬪崱涓嶈兘浣跨敤涓ゆ
- gmresult['status'] = 1
gmresult['code'] = codeStr
gmresult['coupontype'] = data["coupontype"]
- mylog.debug("card ok!")
- return SendGm(gmresult, pushurl)
+ retCode, retMsg = SendGm(ErrCode_OK, gmresult, pushurl)
+ if retCode == ErrCode_OK:
+ dbController.update(CouponDB.CouponCodeColName + "_" + agentName, {"code":codeStr, "channel":agentName}, data)
+ mylog.debug("card ok!")
+ return retMsg
+def CommCheck(dataDict, coupontype):
+ ## 閫氱敤甯歌妫�鏌�
+
+ MailJson = GetMailJson(dataDict.get("channel", ""))
+ if coupontype in MailJson:
+ mailInfo = MailJson[coupontype]
+ lvLimit = mailInfo.get("LV", 0)
+ vipLVLimit = mailInfo.get("VIPLV", 0)
+ else:
+ lvLimit = ConfigIO.GetInt(coupontype, "LV")
+ vipLVLimit = ConfigIO.GetInt(coupontype, "VIPLV")
+
+ # 浣跨敤绛夌骇
+ playerLV = CommFunc.ToIntDef(dataDict.get("level", 0))
+ if lvLimit > 0 and playerLV < lvLimit:
+ mylog.debug("playerLV(%s) < lvLimit(%s)" % (playerLV, lvLimit))
+ return ErrCode_LVLimit
+
+ # vip绛夌骇鐩稿叧
+ playerVIPLV = CommFunc.ToIntDef(dataDict.get("viplevel", 0))
+ if vipLVLimit > 0 and playerVIPLV < vipLVLimit:
+ mylog.debug("playerVIPLV(%s) < vipLVLimit(%s)" % (playerVIPLV, vipLVLimit))
+ return ErrCode_VIPLVLimit
+
+ return
-
-def SendGm(gmresult, pushurl):
+def SendGm(errcode, gmresult, pushurl):
try:
# GM鎺ㄩ�佸湴鍧�
#GMToolPage = http://s1.yhlz.09ge.com:30001/Server/Tool.php
- gmurl = "http://%s:%s/Server/Tool.php"%(pushurl, PushPort)
+ # 鍏煎涓ょ鍏ュ彛锛屼竴绉嶅鎴风鍙彂鏈嶅姟鍣ㄥ煙鍚嶇殑锛屼竴绉岹M宸ュ叿鐩存帴璇诲彇鐨勬湇鍔″櫒GM宸ュ叿鍦板潃
+ if pushurl.endswith("Tool.php"):
+ gmurl = pushurl
+ else:
+ gmurl = "http://%s:%s/Server/Tool.php" % (pushurl, PushPort)
gmkey = PushKey
- if not gmkey or not gmurl:
- return
+ if not gmkey or not PushPort:
+ return ErrCode_OtherErr, CouponCodeResponse(ErrCode_OtherErr, "no PushKey or not PushPort")
+ mylog.debug("SendGm:%s" % gmurl)
- useStatus = gmresult['status']
+ notifyMsg = ""
+ if errcode in ErrCodeMsgInfo:
+ notifyMsg = ErrCodeMsgInfo[errcode][1]
+ if not notifyMsg:
+ notifyMsg = "CodeRewardSys2"
+
+ if notifyMsg:
+ gmtData = {"queryType":"accID", "playerFind":gmresult["accID"], "notifyMsg":notifyMsg}
+ SendGMTCMD(gmurl, gmtData, gmkey, "GMT_MediaCard")
+
+ if errcode != ErrCode_OK:
+ return errcode, CouponCodeResponse(errcode)
- gmresult['notifyMsg'] = Def_CardMsg.get(useStatus, "CodeRewardSys2")
-
-
- if useStatus != 1:
- #澶辫触绯荤粺鎻愮ず
- pack_data = {};
- pack_data["queryType"] = "accID"
- pack_data["playerFind"] = gmresult["accID"]
- pack_data["pack_type"] = "GMT_MediaCard"
- pack_data["notifyMsg"] = gmresult['notifyMsg']
-
- pack_data["key"] = gmkey;
- pack_data['coding'] = "utf8";
-
- #浣跨敤key鍔犲瘑
- pack_data_dict = json.dumps(pack_data)
- sign = md5.md5(pack_data_dict+gmkey).hexdigest()
- post = {}
- post['pack'] = pack_data_dict;
- post['sign'] = sign;
- urllib2.urlopen(gmurl, urllib.urlencode(post), 3)
- return
-
- mylog.debug("SendGm:%s"%gmurl)
- pack_data = {};
+ coupontype = gmresult["coupontype"]
+ MailJson = GetMailJson(gmresult["channel"])
+ if coupontype in MailJson:
+ mailInfo = MailJson[coupontype]
+ mailTitle = mailInfo.get("MailTitle", "MailTitle")
+ mailText = mailInfo.get("MailText", "")
+ mailSender = mailInfo.get("MailSender", "System")
+ mailItems = mailInfo.get("Items", [])
+ else:
+ mailTitle = ConfigIO.GetValue(gmresult["coupontype"], "MailTitle").decode("gbk")
+ mailText = ConfigIO.GetValue(gmresult["coupontype"], "MailText").decode("gbk")
+ mailSender = ConfigIO.GetValue(gmresult["coupontype"], "MailSender").decode("gbk")
+ mailItems = eval(ConfigIO.GetValue(gmresult["coupontype"], "Items"))
+ pack_data = {}
pack_data["queryType"] = "accID"
pack_data["playerList"] = gmresult["accID"]
- pack_data["Title"] = ConfigIO.GetValue(gmresult["coupontype"], "MailTitle").decode("gbk")
- pack_data["Text"] = ConfigIO.GetValue(gmresult["coupontype"], "MailText").decode("gbk")
+ pack_data["Title"] = mailTitle
+ pack_data["Text"] = mailText
pack_data["EndTime"] = str(datetime.datetime.today() + datetime.timedelta(days=15)).split('.')[0]
- pack_data["Sender"] = ConfigIO.GetValue(gmresult["coupontype"], "MailSender").decode("gbk")
-
+ pack_data["Sender"] = mailSender
- Items = eval(ConfigIO.GetValue(gmresult["coupontype"], "Items"))
+ Items = mailItems
pack_data["itemNums"] = ','.join([str(i) for i in range(len(Items))])
i = 0
for itemList in Items:
- pack_data["ItemID%s"%i] = str(itemList[0])
- pack_data["ItemCnt%s"%i] = str(itemList[1])
- pack_data["IsBind%s"%i] = str(itemList[2] if len(itemList) > 2 else 0)
+ pack_data["ItemID%s" % i] = str(itemList[0])
+ pack_data["ItemCnt%s" % i] = str(itemList[1])
+ pack_data["IsBind%s" % i] = str(itemList[2] if len(itemList) > 2 else 0)
i += 1
- pack_data["pack_type"] = "GMT_AddPersonalCompensation"
pack_data["Detail"] = "cardCode:" + gmresult["code"]
-
- pack_data["key"] = gmkey;
- pack_data['coding'] = "utf8";
-
- #浣跨敤key鍔犲瘑
- pack_data_dict = json.dumps(pack_data)
- sign = md5.md5(pack_data_dict+gmkey).hexdigest()
- post = {}
- post['pack'] = pack_data_dict;
- post['sign'] = sign;
- result = urllib2.urlopen(gmurl, urllib.urlencode(post), 3)
-
- #content = result.read()
- result.close()
- # 鎴愬姛鎻愮ず
- pack_data = {};
- pack_data["queryType"] = "accID"
- pack_data["playerFind"] = gmresult["accID"]
- pack_data["pack_type"] = "GMT_MediaCard"
- pack_data["notifyMsg"] = gmresult['notifyMsg']
+ ResultType = SendGMTCMD(gmurl, pack_data, gmkey, "GMT_AddPersonalCompensation")
+ if ResultType == 0:
+ return ErrCode_OK, CouponCodeResponse(ErrCode_OK)
+ else:
+ return ErrCode_OtherErr, CouponCodeResponse(ErrCode_OtherErr, "ResultType error is %s" % ResultType)
+ except BaseException:
+ mylog.error("SendGm error %s" % traceback.format_exc())
+ return ErrCode_OtherErr, CouponCodeResponse(ErrCode_OtherErr, "gm error")
+
+def SendGMTCMD(gmurl, gmtData, gmkey, pack_type):
+ ## 鍙戦�丟M宸ュ叿鍛戒护
+ pack_data = {}
+ if gmtData and isinstance(gmtData, dict):
+ pack_data.update(gmtData)
+ pack_data["pack_type"] = pack_type
+ pack_data["key"] = gmkey
+ pack_data['coding'] = "utf8"
- pack_data["key"] = gmkey;
- pack_data['coding'] = "utf8";
-
- #浣跨敤key鍔犲瘑
- pack_data_dict = json.dumps(pack_data)
- sign = md5.md5(pack_data_dict+gmkey).hexdigest()
- post = {}
- post['pack'] = pack_data_dict;
- post['sign'] = sign;
- urllib2.urlopen(gmurl, urllib.urlencode(post), 3)
-
- return 0
- except Exception, e:
- mylog.debug("gm error %s"%e)
- return
-
+ #浣跨敤key鍔犲瘑
+ pack_data_dict = json.dumps(pack_data)
+ sign = md5.md5(pack_data_dict + gmkey).hexdigest()
+ post = {}
+ post['pack'] = pack_data_dict;
+ post['sign'] = sign;
+ result = urllib2.urlopen(gmurl, urllib.urlencode(post), PushTimeout)
+ retContent = result.read()
+ resultDict = json.loads(retContent)
+ result.close()
+ ResultType = resultDict.get("ResultType", 5) # 5鏈煡閿欒
+ return ResultType
+
def GetDateTimeByStr(timeStr, timeFomat="%Y-%m-%d"):
try:
return datetime.datetime.strptime(timeStr, timeFomat)
except:
- mylog.debug("GetDateTimeByStr error %s"%timeStr)
+ mylog.debug("GetDateTimeByStr error %s" % timeStr)
return
@@ -461,7 +500,7 @@
# 寰俊鍏ュ彛鍏呭��
def SendWXBill(wxdata, pushurl):
try:
- billurl = "http://%s/api/exchange/index.php"%pushurl
+ billurl = "http://%s/api/exchange/index.php" % pushurl
post = {}
post['AccountID'] = wxdata['accid']
@@ -471,9 +510,9 @@
post['OrderInfo'] = wxdata['orderinfo']
post['OperatorID'] = wxdata['appid']
- key = ConfigIO.GetValue("Coupon", "key_%s"%post['OperatorID'])
+ key = ConfigIO.GetValue("Coupon", "key_%s" % post['OperatorID'])
# $sign=md5($AccountID.$OrderAmount.$BillNO.$RegionName.$key)
- mylog.debug("appid = %s key = %s"%(post['OperatorID'], key))
+ mylog.debug("appid = %s key = %s" % (post['OperatorID'], key))
sign = md5.md5(post['AccountID'] + str(post['OrderAmount']) + post['BillNO'] + post['RegionName'] + key).hexdigest()
@@ -481,12 +520,12 @@
result = urllib2.urlopen(billurl, urllib.urlencode(post), 3)
resultDict = json.loads(result.read())
- mylog.debug("resultDict = %s "%(resultDict))
+ mylog.debug("resultDict = %s " % (resultDict))
if int(resultDict["errorcode"]) > 0:
return True
except Exception, e:
- mylog.info("SendWXBill error %s"%e)
+ mylog.info("SendWXBill error %s" % e)
return False
# 閫氱煡鍚庡彴鏁版嵁涓績璁板綍
@@ -499,7 +538,7 @@
post['regionid'] = wxdata['serverid']
post['orderid'] = wxdata['orderid']
post['passport'] = wxdata['accid']
- post['roleid'] = wxdata['roleid']
+ post['roleid'] = wxdata['roleid']
post['ordertitle'] = wxdata['ordertitle'].encode("UTF8")
post['orderinfo'] = wxdata['orderinfo']
post['money'] = wxdata['money']
@@ -508,17 +547,21 @@
post['viplevel'] = wxdata['viplevel']
post['time'] = int(time.time())
- key = ConfigIO.GetValue("Coupon", "key_%s"%post['appid'])
+ key = ConfigIO.GetValue("Coupon", "key_%s" % post['appid'])
#md5(appid=$appid®ionid=$regionid&passport=$passport&&money=$money&time=$time$app_secret)
- signStr = "appid=%s®ionid=%s&passport=%s&money=%s&time=%s%s"%(\
+ signStr = "appid=%s®ionid=%s&passport=%s&money=%s&time=%s%s" % (\
post['appid'], post['regionid'], post['passport'], post['money'], post['time'], key)
sign = md5.md5(signStr).hexdigest()
#mylog.debug("SendDataCollectorBillInfo %s-%s-%s-%s"%(signStr, sign, key, post))
post['sign'] = sign
- result = urllib2.urlopen(billurl +"?" + urllib.urlencode(post), timeout =3)
+ result = urllib2.urlopen(billurl + "?" + urllib.urlencode(post), timeout=3)
#mylog.debug("SendDataCollectorBillInfo result %s"%result.read())
except Exception, e:
- mylog.debug("SendDataCollectorBillInfo error %s"%e)
+ mylog.debug("SendDataCollectorBillInfo error %s" % e)
+# 鏌ヨ瀹℃牳鏃堕棿
+@myapp.route('/auditdate.php')
+def QueryAuditdate():
+ return "2021-06-22 11:30:00"
--
Gitblit v1.8.0