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_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