|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | myapp = Bottle() | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 防止短时间内的多次无效访问 accid:time | 
|---|
|  |  |  | 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" | 
|---|
|  |  |  | 
|---|
|  |  |  | # 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(): | 
|---|
|  |  |  | 
|---|
|  |  |  | codeStr = dataDict.get("code", "") | 
|---|
|  |  |  | if not codeStr: | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | codeStr = codeStr.strip() | 
|---|
|  |  |  | #只是用来拼接账号 | 
|---|
|  |  |  | spID = dataDict.get("spid", "") | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | # 转化为游戏账号 | 
|---|
|  |  |  | 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: | 
|---|
|  |  |  | # 无法获取数据库 | 
|---|
|  |  |  | 
|---|
|  |  |  | gmresult = {'accID':accid, 'sid':sid, 'channel':agentName} | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #-----------统一固定码处理---------------------- | 
|---|
|  |  |  | CommonCards = CommonCards.get(agentName, []) | 
|---|
|  |  |  | if codeStr in CommonCards: | 
|---|
|  |  |  | CommonCardsList = CommonCards.get(agentName, []) | 
|---|
|  |  |  | if codeStr in CommonCardsList: | 
|---|
|  |  |  | # 不同固定码各自只能领一次 | 
|---|
|  |  |  | result, commondata = dbController.find_one(CouponDB.CouponCodeColName + "_Common", {"code":codeStr, "accid":accid}) | 
|---|
|  |  |  | if commondata: | 
|---|
|  |  |  | 
|---|
|  |  |  | 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] = '1' | 
|---|
|  |  |  | pack_data["IsBind%s"%i] = str(itemList[2] if len(itemList) > 2 else 0) | 
|---|
|  |  |  | i += 1 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | pack_data["pack_type"] = "GMT_AddPersonalCompensation" | 
|---|
|  |  |  | 
|---|
|  |  |  | 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() | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 成功提示 | 
|---|
|  |  |  | 
|---|
|  |  |  | post['sign'] = sign; | 
|---|
|  |  |  | urllib2.urlopen(gmurl, urllib.urlencode(post), 3) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return content | 
|---|
|  |  |  | return 0 | 
|---|
|  |  |  | except Exception, e: | 
|---|
|  |  |  | mylog.debug("gm error %s"%e) | 
|---|
|  |  |  | return | 
|---|