9535 【越南】服务器中心接口(媒体卡优化:增加支持平台直接调用使用媒体卡,增加使用结果返回;优化邮件内容配置,支持utf8格式配置,越南需用utf8)
2个文件已修改
1个文件已添加
263 ■■■■■ 已修改文件
Tool/WebCenter/Coupon/CodeMail.json 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tool/WebCenter/Coupon/config.ini 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tool/WebCenter/CouponCode/webapp.py 239 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tool/WebCenter/Coupon/CodeMail.json
New file
@@ -0,0 +1,17 @@
{
    "VIP666": {
        "MailSender": "Hệ thống thư",
        "MailTitle": "<gcode>VIP666 gói quà",
        "MailText": "Cảm ơn bạn đã hỗ trợ các trò chơi, xin vui lòng nhận được gói quà VIP666.",
        "Items": [[4680,1],[1128,1],[3801,1,1],[4501,2]],
        "LV":100,
        "VIPLV":5,
    },
    "g001": {
        "MailSender": "系统邮件",
        "MailTitle": "<gcode>历史累计返利活动",
        "MailText": "累积充值1000元返利,感谢您对游戏的支持,请及时领取礼包。",
        "Items": [[1015,1],[15177,2],[1128,2]]
    }
}
Tool/WebCenter/Coupon/config.ini
@@ -21,7 +21,7 @@
;固定码列表,没有则放空, 以字母z开头避免混淆; 公共固定码,所有人用同一个码,每个人只能领取一次 {APPID:[码, ...], ...}
;CommonCards = ["zj98u2j0ud1"]
CommonCards = {}
CommonCards = {"test":["VIP666", "VIP888"]}
;微信商城购物key
zyxh_wxkey = dcdce6dj
@@ -104,3 +104,8 @@
MailText=感谢您对游戏的支持,请及时领取礼包。
Items=[[2050,1],[4659,1],[2211,10],[151,1]]
[VIP888]
MailSender=系统邮件
MailTitle=<gcode>VIP888礼包
MailText=感谢您对游戏的支持,请及时领取礼包VIP888。
Items=[[4680,1],[1128,1],[3801,1,1],[4501,2]]
Tool/WebCenter/CouponCode/webapp.py
@@ -47,16 +47,45 @@
PushKey = ConfigIO.GetValue("Coupon", "PushKey")
CommonCards = eval(ConfigIO.GetValue("Coupon", "CommonCards"))
                
# 发放奖励邮件内容json,utf8编码
f = open(os.getcwd() + "\\..\\Coupon\\CodeMail.json", "r")
MailJson = eval(f.read())
f.close()
        
Def_CardMsg = {
               0:"CodeRewardSys2", #  兑换码无效
               1:"CodeRewardSys1", #   兑换卡奖励已发至邮件
               2:"CodeRewardSys3", #  兑换码已使用过
               3:"CodeRewardSys4",  # 同类型兑换码只能使用一次
               4:"LvErr", # 等级不足
               5:"VipLevel", # VIP等级不足
# 礼包使用返回结果码定义
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}
    mylog.debug("resData: %s" % str(resData))
    #mylog.info("resData: %s" % str(resData))
    return json.dumps(resData, ensure_ascii=False)
                
                
myapp = Bottle()
@@ -136,25 +165,26 @@
    
    agentName = dataDict.get("channel", "")     # 运营提供的APPID,即渠道
    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)
@@ -166,7 +196,7 @@
            AccID_Cache_Dict[accid] = int(time.time())
        elif time.time() - AccID_Cache_Dict[accid] < 2:
            mylog.debug("==========bad: fast click  %s"%accid)
            return
            return CouponCodeResponse(ErrCode_FrequentRequest)
            
        AccID_Cache_Dict[accid] = int(time.time())
    except:
@@ -176,8 +206,7 @@
    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}
@@ -189,37 +218,31 @@
        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)
        
        commCheckStatus = CommCheck(dataDict, codeStr)
        if commCheckStatus != None:
            gmresult['status'] = commCheckStatus
            return SendGm(gmresult, pushurl)
            return SendGm(commCheckStatus, gmresult, pushurl)
        
        gmresult['status'] = 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)
        return SendGm(ErrCode_OK, gmresult, pushurl)
    #-----------微信商城----------------------
    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)
        
        wxdata['status'] = 1
        wxdata['accid'] = dataDict.get("accid", "")     # 此处用原始账号
@@ -235,49 +258,43 @@
            dbController.update(CouponDB.CouponWXColName, {"code":codeStr, "operateid":operateID}, wxdata)
            # 通知后台记录
            SendDataCollectorBillInfo(wxdata, pushurl, operateID)
        return
            return CouponCodeResponse(ErrCode_OK)
        return CouponCodeResponse(ErrCode_OtherErr, "SendWXBill error")
    
    #-----------批量兑换码处理,同类型只领取一次----------------------
    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)
    if int(data['status']) == 1:
        #已使用,同卡号记录默认可用,避免断线发送失败的情况(未返回结果验证情况下)
        gmresult['status'] = 2
        mylog.debug("card used!")
        return SendGm(gmresult, pushurl)
        return SendGm(ErrCode_Used, gmresult, pushurl)
    
    commCheckStatus = CommCheck(dataDict, data["coupontype"])
    if commCheckStatus != None:
        gmresult['status'] = commCheckStatus
        return SendGm(gmresult, pushurl)
        return SendGm(commCheckStatus, 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)
        return SendGm(ErrCode_Invalid, gmresult, pushurl)
    if int(data2['status']) == 1:
        #暂停使用该批次卡
        gmresult['status'] = 0
        mylog.debug("couponid frozed")
        return SendGm(gmresult, pushurl)
        return SendGm(ErrCode_Invalid, 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)
            return SendGm(ErrCode_Invalid, gmresult, pushurl)
    if data2["expiretime"] != "" and datetime.datetime.today() > GetDateTimeByStr(data2["expiretime"]):
        #已过期
        gmresult['status'] = 0
        mylog.debug("time pass")
        return SendGm(gmresult, pushurl)
        return SendGm(ErrCode_Invalid, gmresult, pushurl)
    
    # h 开头的卡类型可重复使用
    if not codeStr.startswith('h'):
@@ -286,89 +303,95 @@
                                              {"coupontype":data["coupontype"], "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_TypeUsed, 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)
    return SendGm(ErrCode_OK, gmresult, pushurl)
def CommCheck(dataDict, coupontype):
    ## 通用常规检查
    
    # 使用等级
    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 4
        return ErrCode_LVLimit
    
    # vip等级相关
    vipLVLimit = ConfigIO.GetInt(coupontype, "VIPLV")
    playerVIPLV = CommFunc.ToIntDef(dataDict.get("viplevel", 0))
    if vipLVLimit > 0 and playerVIPLV < vipLVLimit:
        mylog.debug("playerVIPLV(%s) < vipLVLimit(%s)" % (playerVIPLV, vipLVLimit))
        return 5
        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
        # 兼容两种入口,一种客户端只发服务器域名的,一种GM工具直接读取的服务器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
        useStatus = gmresult['status']
        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 = {};
        if not gmkey or not PushPort:
            return CouponCodeResponse(ErrCode_OtherErr, "no PushKey or not PushPort")
        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 CouponCodeResponse(errcode)
        coupontype = gmresult["coupontype"]
        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:
@@ -377,11 +400,24 @@
            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";
        SendGMTCMD(gmurl, pack_data, gmkey, "GMT_AddPersonalCompensation")
        return CouponCodeResponse(ErrCode_OK)
    except Exception, e:
        mylog.debug("SendGm error %s" % e)
        return CouponCodeResponse(ErrCode_OtherErr, "gm error")
    return
def SendGMTCMD(gmurl, gmtData, gmkey, pack_type):
    ## 发送GM工具命令
    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"
    
        #使用key加密
        pack_data_dict = json.dumps(pack_data)
@@ -390,31 +426,8 @@
        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']
        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