def order(self, mi): mo = TyContext.Cls_MsgPack() TyContext.ftlog.info('ChargeV3Delegator', 'order mi', mi) userId = mi.getParamInt('userId', 0) # authorCode = mi.getParamStr('authorCode') appId = mi.getParamStr('appId', '9999') appInfo = mi.getParamStr('appInfo', '') clientId = mi.getParamStr('clientId') tyChannelName = mi.getParamStr('tyChannelName') chargeType = mi.getParamStr('chargeType') prodId = mi.getParamStr('prodId') # 检查支持的支付列表 store_payment = ChargeConfigure.get_store_payment(prodId, appId, clientId=clientId) if not store_payment: mo.setResult('code', 1) mo.setResult('info', '支付类型未配置') return mo # 获取对应的支付类型 payInfo = filter(lambda x: x['paytype'] == chargeType, store_payment) if not payInfo: mo.setResult('code', 1) mo.setResult('info', '支付类型无效') return mo # 获取商品信息 prod_info = ChargeConfigure.get_prod_info(appId, prodId, clientId=clientId) if not prod_info: mo.setResult('code', 1) mo.setResult('info', '未找到对应的商品') return mo try: chargeInfo = self.get_charge_info(mi) except TyContext.FreetimeException as e: TyContext.ftlog.error('_charge_begin_w_new_categories exception', e) mo.setError(e.errorCode, e.message) return mo # chargeinfo_dump = json.dumps(chargeInfo) # datas = ['state', PayConst.CHARGE_STATE_BEGIN, # 'charge', chargeinfo_dump, # 'createTime', datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')] # # TyContext.RedisPayData.execute('HMSET', 'sdk.charge:' + orderId, *datas) # ChargeModel.save_order(prodOrderId, *datas) # 返回数据 mo.setResult('code', 0) mo.setResult('chargeInfo', chargeInfo) return mo
def check_charge_info(self, mi, chargeInfo): appId = chargeInfo['appId'] # packageName = chargeInfo['packageName'] clientId = chargeInfo['clientId'] diamondId = chargeInfo['diamondId'] diamondPrice = chargeInfo['diamondPrice'] chargetype = chargeInfo['chargeType'] prodDict = ChargeConfigure.get_prod_dict(appId, clientId=clientId) payCodes = TyContext.Configure.get_global_item_json('paycodes', clientid=clientId) payData = payCodes[chargetype]['paydata'] prodList = [] for data in payData: prodid = data['prodid'] if diamondId == prodid: return # 单机商品过滤掉 if prodid.endswith('DJ'): continue try: prodInfo = prodDict[prodid] except KeyError: continue if int(prodInfo.get('is_diamond', 0)) and prodInfo['price'] >= diamondPrice: prodList.append(prodInfo) if prodList: prodList.sort(lambda x, y: cmp(x['price'], y['price'])) prodInfo = prodList[0] chargeInfo['buttonId'] = prodInfo['id'] chargeInfo['diamondId'] = prodInfo['id'] chargeInfo['diamondName'] = prodInfo['name'] chargeInfo['buttonName'] = prodInfo['name'] chargeInfo['diamondPrice'] = prodInfo['price'] chargeInfo['chargeTotal'] = prodInfo['price'] * chargeInfo['diamondCount'] chargeInfo['chargeCoin'] = prodInfo['diamondPrice'] * chargeInfo['diamondCount']
def change_chargeinfo(self, diamondList, chargeInfo): clientId = chargeInfo['clientId'] diamondPrice = chargeInfo['diamondPrice'] prodDict = ChargeConfigure.get_prod_dict(chargeInfo['appId'], clientId=clientId) prodList = [] for id in diamondList: # 单机商品过滤掉 if id.endswith('DJ'): continue try: prodInfo = prodDict[id] except KeyError: continue if int(prodInfo.get('is_diamond', 0)) and prodInfo['price'] >= diamondPrice: prodList.append(prodInfo) if prodList: prodList.sort(lambda x, y: cmp(x['price'], y['price'])) prodInfo = prodList[0] chargeInfo['diamondId'] = prodInfo['id'] chargeInfo['diamondName'] = prodInfo['name'] chargeInfo['buttonName'] = prodInfo['name'] chargeInfo['diamondPrice'] = prodInfo['price'] chargeInfo[ 'chargeTotal'] = prodInfo['price'] * chargeInfo['diamondCount'] chargeInfo['chargeCoin'] = prodInfo['diamondPrice'] * chargeInfo[ 'diamondCount']
def filter_payment(self, payment, prod_info, **kwargs): """ 支付方式列表中过滤检查,没有计费点得商品就不要显示此支付方式 :param prodInfo: :param chargeInfo: :param kwargs: :return: """ appId = kwargs['appId'] clientId = kwargs['clientId'] prodConfig = TyContext.Configure.get_global_item_json( 'yisdkpay_prodids', {}) yipayDict = prodConfig[str(appId)] prodId, prodPrice = prod_info['id'], prod_info['price'] # 计费点直购 prodDict = ChargeConfigure.get_prod_dict(appId, clientId=clientId) if prodId in yipayDict: return True # 替代计费点 for id in yipayDict: tmpProdInfo = prodDict[id] if int(tmpProdInfo.get('is_diamond', 0)) and tmpProdInfo['price'] >= prodPrice: return True return False
def check_charge_info(self, mi, chargeInfo): appId = chargeInfo['appId'] diamondId = chargeInfo['diamondId'] prodConfig = TyContext.Configure.get_global_item_json( 'yisdkpay_prodids', {}) yipayDict = prodConfig[str(appId)] if not diamondId in yipayDict: clientId = chargeInfo['clientId'] diamondPrice = chargeInfo['diamondPrice'] prodDict = ChargeConfigure.get_prod_dict(appId, clientId=clientId) prodList = [] for id in yipayDict: # 单机商品过滤掉 if id.endswith('DJ'): continue prodInfo = prodDict[id] if int(prodInfo.get('is_diamond', 0)) and prodInfo['price'] >= diamondPrice: prodList.append(prodInfo) if prodList: prodList.sort(lambda x, y: cmp(x['price'], y['price'])) prodInfo = prodList[0] chargeInfo['diamondId'] = prodInfo['id'] chargeInfo['diamondName'] = prodInfo['name'] chargeInfo['diamondPrice'] = prodInfo['price'] chargeInfo['chargeTotal'] = prodInfo['price'] * chargeInfo[ 'diamondCount'] chargeInfo['chargeCoin'] = prodInfo[ 'diamondPrice'] * chargeInfo['diamondCount']
def check_charge_info(self, mi, chargeInfo): appId = chargeInfo['appId'] clientId = chargeInfo['clientId'] diamondId = chargeInfo['diamondId'] diamondPrice = chargeInfo['diamondPrice'] packageName = chargeInfo.get('packageName', '') products = [] if packageName: _, products = self.get_ios_product_by_packageName(appId, packageName, clientId, diamondId) if not products: products = TuyouPayDiamondList._get_pay_products_list_(appId, clientId, 'ios-products-v2', clientId) # 没有计费点商品 if not filter(lambda x: x['tyid'] == diamondId, products): prodDict = ChargeConfigure.get_prod_dict(appId, clientId=clientId) diamondList = [] for diamond in products: tyid = diamond['tyid'] prodInfo = prodDict.get(tyid, {}) if prodInfo.get('is_diamond') and prodInfo['price'] >= diamondPrice: diamondList.append(prodInfo) if diamondList: diamondList.sort(lambda x, y: cmp(x['price'], y['price'])) prodInfo = diamondList[0] chargeInfo['diamondId'] = prodInfo['id'] chargeInfo['buttonId'] = prodInfo['id'] chargeInfo['diamondName'] = prodInfo['name'] chargeInfo['diamondPrice'] = prodInfo['price'] chargeInfo['chargeTotal'] = prodInfo['price'] * chargeInfo['diamondCount'] chargeInfo['chargeCoin'] = prodInfo['diamondPrice'] * chargeInfo['diamondCount']
def check_charge_info(self, mi, chargeInfo): if not self.need_continue_change_chargeinfo(chargeInfo): return appId = chargeInfo['appId'] packageName = chargeInfo['packageName'] diamondId = chargeInfo['diamondId'] prodConfig = TyContext.Configure.get_global_item_json('duoku_prodids', {}) thirdDict = prodConfig[packageName] if not diamondId in thirdDict: clientId = chargeInfo['clientId'] diamondPrice = chargeInfo['diamondPrice'] prodDict = ChargeConfigure.get_prod_dict(appId, clientId=clientId) prodList = [] for id in thirdDict: # 单机商品过滤掉 if id.endswith('DJ'): continue try: prodInfo = prodDict[id] except KeyError: continue if int(prodInfo.get('is_diamond', 0)) and prodInfo['price'] >= diamondPrice: prodList.append(prodInfo) if prodList: prodList.sort(lambda x, y: cmp(x['price'], y['price'])) prodInfo = prodList[0] chargeInfo['diamondId'] = prodInfo['id'] chargeInfo['diamondName'] = prodInfo['name'] chargeInfo['buttonName'] = prodInfo['name'] chargeInfo['diamondPrice'] = prodInfo['price'] chargeInfo['chargeTotal'] = prodInfo['price'] * chargeInfo['diamondCount'] chargeInfo['chargeCoin'] = prodInfo['diamondPrice'] * chargeInfo['diamondCount']
def check_charge_info(self, mi, chargeInfo): appId = chargeInfo['appId'] clientId = chargeInfo['clientId'] diamondId = chargeInfo['diamondId'] # prodPrice = chargeInfo['diamondPrice'] prodCount = chargeInfo['diamondCount'] mustcharge = int(chargeInfo.get('mustcharge', 0)) diamondlist = TuyouPayDiamondList.diamondlist2(appId, clientId) prodInfo = ChargeConfigure.get_prod_info(appId, diamondId, clientId=clientId) # 非钻石商品需要先购买钻石 if not prodInfo.get('is_diamond', 0): # 消耗的钻石数量 consumeCoin = int(prodInfo['diamondPrice'] * prodCount) if not diamondlist: TyContext.ftlog.error('__consume_charge__ diamondlist ERROR', appId, clientId) raise PayErrorV4(6, '钻石列表配置错误') return True ios_patch = TyContext.Configure.get_global_item_int( 'patch_ios_bug_TY9999R0003001', 1) if ios_patch: diamondlist = TuyouPayConsume._patch_ios_client_bug( clientId, diamondlist) for diamond in diamondlist: count = diamond['count'] if count >= consumeCoin: break else: TyContext.ftlog.error( '__consume_charge__ find charge diamond ERROR', appId, clientId, consumeCoin, diamondlist) raise PayErrorV4(7, '钻石项目取得失败') chargeInfo['diamondId'] = diamond['id'] chargeInfo['diamondPrice'] = diamond['price'] chargeInfo[ 'chargeTotal'] = diamond['price'] * chargeInfo['diamondCount'] if mustcharge or True: chargeInfo['diamondName'] = diamond['name'] chargeInfo['buttonId'] = chargeInfo['diamondId'] chargeInfo['buttonName'] = chargeInfo['diamondName'] try: self.get_charge_data(chargeInfo) except TyContext.FreetimeException as e: TyContext.ftlog.error('_charge_begin_w_new_categories exception', e) # mo.setError(e.errorCode, e.message) # return mo raise (e.errorCode, e.message)
def get_consume_info(self, chargeInfo): prodInfo = ChargeConfigure.get_prod_info( chargeInfo['appId'], chargeInfo['diamondId'], clientId=chargeInfo['clientId']) prodDiamondPrice = prodInfo[ 'diamondPrice'] # 商品钻石价格(一般等于10*prodInfo['price']) ### prodCount = chargeInfo['diamondCount'] appId = chargeInfo['appId'] appInfo = chargeInfo.get('appInfo', '') clientId = chargeInfo['clientId'] userId = chargeInfo['userId'] prodId = chargeInfo['diamondId'] prodPrice = chargeInfo['diamondPrice'] prodCount = prodCount prodName = chargeInfo['diamondName'] consumeCoin = prodCount * prodDiamondPrice prodOrderId = chargeInfo['prodOrderId'] mo = TyContext.Cls_MsgPack() # 创建消耗订单 fail, consumeOrderId = TuyouPayConsume._create_consume_transaction( appId, appInfo, clientId, userId, consumeCoin, prodId, prodPrice, prodCount, prodName, prodOrderId, mo) if fail: raise PayErrorV4(mo.getErrorCode(), mo.getErrorInfo()) consumeInfo = { 'appId': int(chargeInfo['appId']), 'appInfo': chargeInfo['appInfo'], 'clientId': chargeInfo['clientId'], 'userId': chargeInfo['userId'], 'consumeCoin': consumeCoin, 'prodId': chargeInfo['diamondId'], 'prodPrice': chargeInfo['diamondPrice'], 'prodCount': chargeInfo['diamondCount'], 'prodName': chargeInfo['diamondName'], 'prodOrderId': consumeOrderId, 'mustcharge': '1', } # diamondInfo = self.get_consume_diamond(chargeInfo['appId'], prodInfo,clientId=chargeInfo['clientId']) # replace item # chargeInfo['diamondId'] = diamondInfo['id'] # chargeInfo['diamondName'] = diamondInfo['name'] # chargeInfo['diamondPrice'] = diamondInfo['price'] # consumeInfo['diamondCount'] = diamondInfo[''] # self.check_charge_info(chargeInfo) return consumeInfo
def check_store_payment(self, mi): prodId = mi.getParamStr('prodId') chargeType = mi.getParamStr('chargeType') appId = mi.getParamStr('appId', '9999') clientId = mi.getParamStr('clientId') # mustcharge = mi.getParamInt('mustcharge') # tyGameName = mi.getParamStr('tyGameName') # tySubGameName = mi.getParamStr('tySubGameName') tyChannelName = mi.getParamStr('tyChannelName') # tyVersionName = mi.getParamStr('tyVersionName') # 3.71 store_payment = ChargeConfigure.get_store_payment(prodId, appId, clientId=clientId) if not store_payment: raise PayErrorV4(1, '支付类型未配置') # 获取对应的支付类型 payInfo = filter(lambda x: x['paytype'] == chargeType, store_payment) if not payInfo: raise PayErrorV4(1, '支付类型无效')
def charge(cls, mi): TyContext.ftlog.info(cls.__name__, 'charge mi', mi) mo = TyContext.Cls_MsgPack() ### userId = mi.getParamInt('userId', 0) appId = mi.getParamStr('appId', '9999') clientId = mi.getParamStr('clientId') ### prodId = mi.getParamStr('prodId') prodCount = mi.getParamInt('prodCount', 0) ### tyGameName = mi.getParamStr('tyGameName') tySubGameName = mi.getParamStr('tySubGameName') tyChannelName = mi.getParamStr('tyChannelName') tyVersionName = mi.getParamStr('tyVersionName') # 3.71 ### prodName = mi.getParamStr('prodName') prodPrice = mi.getParamInt('prodPrice', -1) # 道具价格,单位元 prodIcon = mi.getParamStr('prodIcon', "") # prodOrderId = mi.getParamStr('prodOrderId', '') mustcharge = mi.getParamInt('mustcharge', 0) # 获取商品信息 prod_info = ChargeConfigure.get_prod_info(appId, prodId, clientId=clientId) if not prod_info: mo.setResult('code', 1) mo.setResult('info', '未找到对应的商品') return mo if not prodPrice or prodPrice < 0: prodPrice = prod_info['price'] if not prodCount or prodCount < 0: prodCount = 1 if not prodName: prodName = prod_info.get('name', '') if not prodIcon: prodIcon = prod_info.get('icon', '') store_payment = [] payment_list = ChargeConfigure.get_store_payment(prodId, appId, clientId=clientId) for payment in payment_list: try: chargeType = payment['paytype'] method = payv4_filter_map[chargeType] payment = deepcopy(payment) if not method(payment, prod_info, appId=appId, clientId=clientId, userId=userId): continue except KeyError: pass store_payment.append(payment) # 过滤328 & 648 商品 if len(payment_list) > 1 and filter( lambda x: x['paytype'] == 'tuyooios', payment_list): strategy = TuYooPayIOSAppStoreStrategy() if strategy(appId, userId, prodId): store_payment = filter(lambda x: x['paytype'] != 'tuyooios', payment_list) ## 完成 mo.setResult('userId', userId) mo.setResult('appId', appId) mo.setResult('clientId', clientId) mo.setResult('prodId', prodId) mo.setResult('prodName', prodName) mo.setResult('prodIcon', prodIcon) mo.setResult('prodPrice', prodPrice) mo.setResult('prodCount', prodCount) mo.setResult('mustcharge', mustcharge) if store_payment: mo.setResult('code', 0) mo.setResult('store_payment', store_payment) else: mo.setResult('code', 1) mo.setResult('info', '支付类型未配置') mo.setCmd('charge') return mo
def consume(cls, mi): userId = mi.getParamInt('userId') # authorCode = mi.getParamStr('authorCode') appId = mi.getParamInt('appId') clientId = mi.getParamStr('clientId') appInfo = mi.getParamStr('appInfo') prodId = mi.getParamStr('prodId') # prodName = mi.getParamStr('prodName') prodCount = mi.getParamInt('prodCount') # prodPrice = mi.getParamInt('prodPrice') # 商品的钻石价格 # 用于第三方应用(appId>10000)传递游戏订单号。途游的游戏不用传或传空串 prodOrderId = mi.getParamStr('prodOrderId', '') mustcharge = mi.getParamInt('mustcharge') clientPayType = mi.getParamStr('payType') payInfo = mi.getParamStr('payInfo') prodInfo = ChargeConfigure.get_prod_info(appId, prodId, clientId=clientId) mo = TyContext.Cls_MsgPack() if not prodInfo: mo.setResult('code', 1) mo.setResult('info', '未找到对应的商品') return mo prodPrice = prodInfo['diamondPrice'] prodName = prodInfo['name'] ## # 取得当前用户的COIN userDiamond = TyContext.RedisUser.execute(userId, 'HGET', 'user:'******'diamond') if isinstance(userDiamond, (int, float)): userDiamond = int(userDiamond) else: userDiamond = 0 TyContext.ftlog.info('consume->appId=', appId, 'clientId=', clientId, 'userId=', userId, 'userCoin=', userDiamond, 'prodPrice=', prodPrice, 'prodId=', prodId, 'prodName=', prodName, 'prodCount=', prodCount, 'prodOrderId=', prodOrderId, 'mustcharge=', mustcharge, 'clientPayType', clientPayType, 'payInfo=', payInfo) if prodCount <= 0: prodCount = 1 else: prodCount = int(prodCount) prodPrice = int(prodPrice) consumeDiamond = int(prodPrice * prodCount) mo = TyContext.Cls_MsgPack() mo.setCmd('consume') if not consumeDiamond: mo.setError(2, '商品价格信息错误,请检查') return mo # 是否需要充值 if mustcharge == 1 or userDiamond < consumeDiamond: mi.setParam('mustcharge', 1) return cls.charge(mi) # 直接兑换道具或金币 fail, prodOrderId = TuyouPayConsume._create_consume_transaction( appId, appInfo, clientId, userId, consumeDiamond, prodId, prodPrice, prodCount, prodName, prodOrderId, mo) if fail: mo.setError(3, '兑换错误,请稍后重试') return mo TuyouPayConsume.__consume_user_coin__(appId, appInfo, clientId, userId, consumeDiamond, prodId, prodPrice, prodCount, prodName, prodOrderId, mo) return mo
def get_charge_info(self, mi): """ 获取购买信息,prodId可能是钻石Id,也可能是道具Id :param mi: :return: """ userId = mi.getParamInt('userId', 0) appId = mi.getParamStr('appId', '9999') clientId = mi.getParamStr('clientId') appInfo = mi.getParamStr('appInfo', '') chargeType = mi.getParamStr('chargeType') prodId = mi.getParamStr('prodId') prodName = mi.getParamStr('prodName') prodCount = mi.getParamInt('prodCount', 0) prodPrice = float(mi.getParamStr('prodPrice', 0)) mustcharge = mi.getParamInt('mustcharge', 0) # tyChannelName = mi.getParamStr('tyChannelName') platformOrderId = mi.getParamStr('platformOrderId', '') if not platformOrderId: platformOrderId = self.make_order_id(userId, appId, clientId) # 获取商品信息 prod_info = ChargeConfigure.get_prod_info(appId, prodId, clientId=clientId) if not prod_info: raise PayErrorV4(1, '商品信息错误') if prodPrice >= 0.1 and abs(prodPrice - prod_info['price']) > 0.1: raise PayErrorV4(2, '商品信息错误') # 商品加个通过后台配置 prodPrice = prod_info['price'] if not prodCount or prodCount < 0: prodCount = 1 if not prodName: prodName = prod_info.get('name', '') # 获取折扣信息 cpExtInfo = "" cpExtObj = ChargeConfigure.get_cpExt_info(prodId, appId, clientId=clientId, chargeType=chargeType) if cpExtObj: cpExtInfo = cpExtObj.get('cpExtInfo', 0) chargeInfo = { 'uid': userId, 'userId': userId, 'appId': int(appId), 'clientId': clientId, 'appInfo': appInfo, 'chargeType': chargeType, 'diamondId': prodId, 'diamondName': prodName, 'diamondPrice': prodPrice, 'diamondCount': prodCount, 'chargeTotal': prodPrice * prodCount, # 充值的RMB数量 'chargeCoin': prodCount * prod_info['diamondPrice'], # 充值的钻石数量 'platformOrderId': platformOrderId, 'phoneType': TyContext.UserSession.get_session_phone_type(userId), 'buttonId': prodId, 'buttonName': prodName, 'cpExtInfo': cpExtInfo, 'mustcharge': mustcharge, 'prodOrderId': mi.getParamStr('prodOrderId', ''), 'mainChannel': clientId.split('.')[-2], 'packageName': mi.getParamStr('tyPackageName', '') or mi.getParamStr('packageName', ''), 'channelName': mi.getParamStr('tyChannelName', ''), } # 非钻石需要兑换或途游游戏 if not int(prod_info.get('is_diamond', 0)) or int(appId) > 9999: consumeInfo = self.get_consume_info(chargeInfo) else: consumeInfo = None # 计费点获取(有些钻石也需要) self.check_charge_info(mi, chargeInfo) self.save_order(chargeInfo, consumeInfo) # bi report Order.log(platformOrderId, Order.CREATE, userId, appId, clientId, diamondid=chargeInfo['diamondId'], prodid=consumeInfo['prodId'] if consumeInfo else 'na', prod_price=consumeInfo['prodPrice'] if consumeInfo else 'na', paytype=chargeInfo.get('chargeType', 'na'), charge_price=chargeInfo['chargeTotal'], shortId='', pay_appid='') return chargeInfo