|  |  |  | 
|---|
|  |  |  | from lib import mylog, CommFunc | 
|---|
|  |  |  | import os.path | 
|---|
|  |  |  | import zipfile | 
|---|
|  |  |  | import time | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # get: request.query.username request.GET.get('username','') | 
|---|
|  |  |  | # post: request.forms.get('username')  request.POST.get('username') | 
|---|
|  |  |  | 
|---|
|  |  |  | f.close() | 
|---|
|  |  |  | return static_file("%s.zip"%couponid, r".\download", download=True) | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #================客户端请求参数=============================================================== | 
|---|
|  |  |  | # channel    是    string    Appid 如jsgameios | 
|---|
|  |  |  | # code    是    string    兑换码 | 
|---|
|  |  |  | # accid    是    string    账号 | 
|---|
|  |  |  | # spid    是    string    运营商ID,研发自己配置的,如jisu代表极速平台 | 
|---|
|  |  |  | # sid    是    int    服务器ID 数字 | 
|---|
|  |  |  | # pushurl    是    string    域名链接s222.xxx.com | 
|---|
|  |  |  | # roleid    是    string    玩家游戏名 | 
|---|
|  |  |  | # level    是    int    玩家等级 | 
|---|
|  |  |  | # viplevel    是    Int    玩家VIP等级 | 
|---|
|  |  |  | #=============================================================================== | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #2018.10.10 混服支持导致账号拼接逻辑变更需要spid | 
|---|
|  |  |  | # 卡类型 开头字母做标识如 g1~999代表此卡只能使用一次 h1~999卡可以重复使用 z开头代表固定码 | 
|---|
|  |  |  | # 卡类型 开头字母做标识如 g1~999代表此卡只能使用一次 h1~999卡可以重复使用 z开头代表固定码 wx开头代表微信商店 | 
|---|
|  |  |  | # 玩家使用卡号 参数 平台 区服 账号 区服链接(GM用)卡号 | 
|---|
|  |  |  | # http://center.xxx.com:53003/Coupon/CouponCode.php?channel=appid&code=XXX&accid=YYY&sid=222&pushurl=s222.xxx.com&spid=jisu | 
|---|
|  |  |  | # http://center.xxx.com:53003/Coupon/CouponCode.php | 
|---|
|  |  |  | @myapp.route('/Coupon/CouponCode.php') | 
|---|
|  |  |  | def CouponCode(): | 
|---|
|  |  |  | dataDict = request.GET | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | spID = dataDict.get("spid", "") | 
|---|
|  |  |  | if not spID: | 
|---|
|  |  |  | mylog.debug("no spid") | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | tdict = {"jisugame":"jisu", 'spxjgame':'sipu', 'mrgame':'maoer', | 
|---|
|  |  |  | "jisugameios":"jisu", 'spyxxjios':'sipu', 'mrgameios':'maoer'} | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 没传的话默认和appid一样 | 
|---|
|  |  |  | spID = tdict.get(agentName, agentName) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | accid = dataDict.get("accid", "") | 
|---|
|  |  |  | if not accid: | 
|---|
|  |  |  | return | 
|---|
|  |  |  | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 转化为游戏账号 | 
|---|
|  |  |  | accid = "%s@%s@s%s"%(accid, spID, sid) | 
|---|
|  |  |  | accid = "%s@%s@s%s"%(accid.lower(), spID, sid) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | dbController = CouponDB.GetDBEventCon() | 
|---|
|  |  |  | if not dbController: | 
|---|
|  |  |  | 
|---|
|  |  |  | mylog.debug("common ok") | 
|---|
|  |  |  | return SendGm(gmresult, pushurl) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #-----------微信商城---------------------- | 
|---|
|  |  |  | if codeStr.startswith('wx'): | 
|---|
|  |  |  | operateID = GetOperateID(agentName) | 
|---|
|  |  |  | if not operateID: | 
|---|
|  |  |  | mylog.debug("wx no appid  = %s"%agentName) | 
|---|
|  |  |  | return | 
|---|
|  |  |  | result, wxdata = dbController.find_one(CouponDB.CouponWXColName, {"code":codeStr, "operateid":operateID}) | 
|---|
|  |  |  | if not wxdata: | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if int(wxdata['status']) == 1: | 
|---|
|  |  |  | gmresult['status'] = 2 | 
|---|
|  |  |  | mylog.debug("wxcard used!") | 
|---|
|  |  |  | return SendGm(gmresult, pushurl) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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['roleid'] = dataDict.get("roleid", "") | 
|---|
|  |  |  | wxdata['level'] = dataDict.get("level", "") | 
|---|
|  |  |  | wxdata['viplevel'] = dataDict.get("viplevel", "") | 
|---|
|  |  |  | if SendWXBill(wxdata, pushurl): | 
|---|
|  |  |  | # 充值成功 | 
|---|
|  |  |  | dbController.update(CouponDB.CouponWXColName, {"code":codeStr, "operateid":operateID}, wxdata) | 
|---|
|  |  |  | # 通知后台记录 | 
|---|
|  |  |  | SendDataCollectorBillInfo(wxdata, pushurl, operateID) | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #-----------批量兑换码处理---------------------- | 
|---|
|  |  |  | result, data = dbController.find_one(CouponDB.CouponCodeColName + "_" + agentName, {"code":codeStr, "channel":agentName}) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if not data: | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 通过appid找到运营商 | 
|---|
|  |  |  | def GetOperateID(appid): | 
|---|
|  |  |  | appidDict = eval(ConfigIO.GetValue("Coupon", "appid_dict")) | 
|---|
|  |  |  | for key, value in appidDict.items(): | 
|---|
|  |  |  | if appid in value: | 
|---|
|  |  |  | return key | 
|---|
|  |  |  | return "" | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 微信入口充值 | 
|---|
|  |  |  | def SendWXBill(wxdata, pushurl): | 
|---|
|  |  |  | try: | 
|---|
|  |  |  | billurl = "http://%s/api/exchange/index.php"%pushurl | 
|---|
|  |  |  |  | 
|---|
|  |  |  | post = {} | 
|---|
|  |  |  | post['AccountID'] = wxdata['accid'] | 
|---|
|  |  |  | post['RegionName'] = wxdata['serverid'] | 
|---|
|  |  |  | post['OrderAmount'] = wxdata['money'] | 
|---|
|  |  |  | post['BillNO'] = wxdata['orderid'] | 
|---|
|  |  |  | post['OrderInfo'] = wxdata['orderinfo'] | 
|---|
|  |  |  | post['OperatorID'] = wxdata['appid'] | 
|---|
|  |  |  |  | 
|---|
|  |  |  | key = ConfigIO.GetValue("Coupon", "key_%s"%post['OperatorID']) | 
|---|
|  |  |  | # $sign=md5($AccountID.$OrderAmount.$BillNO.$RegionName.$key) | 
|---|
|  |  |  | mylog.debug("appid = %s  key = %s"%(post['OperatorID'], key)) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | sign = md5.md5(post['AccountID'] + str(post['OrderAmount']) + post['BillNO'] + post['RegionName'] + key).hexdigest() | 
|---|
|  |  |  |  | 
|---|
|  |  |  | post['Sign'] = sign | 
|---|
|  |  |  | result = urllib2.urlopen(billurl, urllib.urlencode(post), 3) | 
|---|
|  |  |  | resultDict = json.loads(result.read()) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | mylog.debug("resultDict = %s "%(resultDict)) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if int(resultDict["errorcode"]) > 0: | 
|---|
|  |  |  | return True | 
|---|
|  |  |  | except Exception, e: | 
|---|
|  |  |  | mylog.info("SendWXBill error %s"%e) | 
|---|
|  |  |  | return False | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 通知后台数据中心记录 | 
|---|
|  |  |  | def SendDataCollectorBillInfo(wxdata, pushurl, operateID): | 
|---|
|  |  |  | try: | 
|---|
|  |  |  | billurl = "http://recharge.game.2460web.com:12000/api/notify/swwx" | 
|---|
|  |  |  |  | 
|---|
|  |  |  | post = {} | 
|---|
|  |  |  | post['appid'] = wxdata['appid'] | 
|---|
|  |  |  | post['regionid'] = wxdata['serverid'] | 
|---|
|  |  |  | post['orderid'] = wxdata['orderid'] | 
|---|
|  |  |  | post['passport'] = wxdata['accid'] | 
|---|
|  |  |  | post['roleid'] =  wxdata['roleid'] | 
|---|
|  |  |  | post['ordertitle'] = wxdata['ordertitle'].encode("UTF8") | 
|---|
|  |  |  | post['orderinfo'] = wxdata['orderinfo'] | 
|---|
|  |  |  | post['money'] = wxdata['money'] | 
|---|
|  |  |  | post['ip'] = wxdata['ip'] | 
|---|
|  |  |  | post['level'] = wxdata['level'] | 
|---|
|  |  |  | post['viplevel'] = wxdata['viplevel'] | 
|---|
|  |  |  | post['time'] = int(time.time()) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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"%(\ | 
|---|
|  |  |  | 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) | 
|---|
|  |  |  | #mylog.debug("SendDataCollectorBillInfo result %s"%result.read()) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | except Exception, e: | 
|---|
|  |  |  | mylog.debug("SendDataCollectorBillInfo error %s"%e) | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|