def do_yipay_callback(cls, paytype): rparam = TyContext.RunHttp.convertArgsToDict() try: orderPlatformId = rparam['app_orderid'] mobileId = rparam.get('phone', '') if not mobileId and 'phone' in rparam.keys(): del rparam['phone'] sign = rparam['sign'] merc_id = rparam['merc_id'] status = int(rparam['status']) user_id = rparam['userid'] is_monthly = int(rparam['is_monthly']) except Exception as e: TyContext.ftlog.error('do_yipay_callback->ERROR, exception', e, 'rparam', rparam) return 'error' # 签名校验 appkey_config = TyContext.Configure.get_global_item_json( 'yipay_appkey_config', {}) try: appkey = appkey_config[merc_id] except: TyContext.ftlog.error( 'do_yipay_callback appkey not configed' ' for merc_id', merc_id) return 'error' if not cls._verify_sign(rparam, sign, appkey): return 'error' rec_amount = rparam['rec_amount'] pay_amount = rparam['pay_amount'] if rec_amount != pay_amount: TyContext.ftlog.error('do_yipay_callback pay_amount', pay_amount, 'not equal to rec_amount', rec_amount) total_fee = float(pay_amount) / 100 rparam['third_orderid'] = rparam['orderid'] rparam['sub_paytype'] = rparam['ch_type'] rparam['chargeType'] = paytype rparam['mobileId'] = mobileId if status == 1: PayHelperV4.set_order_mobile(orderPlatformId, mobileId) # 判断用户购买的是不是包月会员 if 2 == is_monthly: TyContext.ftlog.debug( 'TuYouPayYi->doYiPayCallback User [%s] buy monthly goods.' % user_id) # 修改用户表,将用户状态置为会员状态 ''' if 'message' in rparam: message = rparam['message'] else: TyContext.ftlog.info('TuYouPayYi->doYiPayCallback ERROR, Doesn\'t has message parameter.' 'userid: [%s], platformorderid: [%s], third_id: [%s]' % (user_id, orderPlatformId, rparam['third_orderid'])) message = '退订请联系会员退订专用电话: 4008-098-000' ''' message = '退订请联系会员退订专用电话: 4008-098-000' # 记录购买会员的appId、clientId chargeKey = 'sdk.charge:' + orderPlatformId chargeInfo = TyContext.RedisPayData.execute( 'HGET', chargeKey, 'charge') if chargeInfo == None: chargeInfo = {} else: chargeInfo = TyContext.strutil.loads(chargeInfo, decodeutf8=True) appId = chargeInfo.get('appId', 9999) clientId = chargeInfo.get('clientId', '') TyContext.RedisUser.execute(user_id, 'HMSET', 'user:'******'isYouyifuVipUser', '1', 'youyifuVipMsg', message, 'bugYouyifuVipAppid', appId, 'bugYouyifuVipClientid', clientId) # 这个参数用来告诉游戏服务器,这个商品是一件优易付的会员包月商品 rparam['isYouyifuMonthVip'] = '1' PayHelperV4.callback_ok(orderPlatformId, total_fee, rparam) cls.reportBi(Order.SUBSCRIBE, rparam) TyContext.ftlog.info( 'TuYouPayYi->doYiPayCallback user %s has subscribed Monthly VIP.' % user_id) else: PayHelperV4.callback_ok(orderPlatformId, total_fee, rparam) return 'success' elif status == 3: # 包月退订,修改用户表,将用户状态置为非会员状态,并通知游戏服用户退订 status = cls._NotifyGameServerUnsubscribe(orderPlatformId, user_id) if not status: TyContext.ftlog.error( 'TuYouPayYi->doYiPayCallback Notify Game server user [%s] unsubscribed ERROR!' % user_id) return 'success' try: TyContext.MySqlSwap.checkUserDate(user_id) except: TyContext.ftlog.error( 'TuYouPayYi->doYiPayCallback get cold data') TyContext.RedisUser.execute(user_id, 'HSET', 'user:'******'isYouyifuVipUser', '0') cls.reportBi(Order.UNSUBSCRIBE, rparam) return 'success' else: errinfo = '支付失败' + str(rparam.get('status_desc', '')) PayHelperV4.callback_error(orderPlatformId, errinfo, rparam) return 'success'
def doAiDongManCallback(cls, rpath): xmlData = TyContext.RunHttp.getRequestParam('requestData', '') xmlroot = ElementTree.fromstring(xmlData) TyContext.ftlog.info('doAiDongManCallback rparam xmlData', xmlData) params = OrderedDict() params['Behavior'] = xmlroot.find('Behavior').text params['Trade_status'] = xmlroot.find('Trade_status').text params['Trade_no'] = xmlroot.find('Trade_no').text params['Buyer_id'] = xmlroot.find('Buyer_id').text params['Extension'] = xmlroot.find('Extension').text sign = params['Behavior'] + params['Trade_status'] + params[ 'Trade_no'] + params['Buyer_id'] + params['Extension'] params['Product_id'] = xmlroot.find('Product_id').text params['Product_name'] = xmlroot.find('Product_name').text params['Price'] = int(float(xmlroot.find('Price').text)) params['App_id'] = xmlroot.find('App_id').text params['sign'] = xmlroot.find('Sign').text.replace(' ', '+') params['sign'] = ''.join(params['sign'].split()) TyContext.ftlog.info('doAiDongManCallback params', params) aidongmanconfig = TyContext.Configure.get_global_item_json( 'aidongmanpay_config', {}) if aidongmanconfig: cls.encryptKey = aidongmanconfig['3des']['encryptKey'] # 采用3des加密 padByte = chr(int(8 - len(sign) % 8)) ivBytes = '' ivSource = aidongmanconfig['3des']['iv'] for i in ivSource: ivBytes = ivBytes + chr(int(i)) tripelDes = triple_des(unhexlify(cls.encryptKey), mode=CBC, pad=padByte, IV=ivBytes, padmode=PAD_NORMAL) sign = tripelDes.encrypt(sign) sign = base64.b64encode(sign) plantformId = params['Extension'][23:] TradeNo = xmlroot.find('Trade_no').text params['chargeType'] = 'aidongman' params['third_orderid'] = params['Trade_no'] PayHelperV4.set_order_mobile(plantformId, params['Buyer_id']) TyContext.ftlog.info('doAiDongManCallback sign', sign, 'params[sign]', params['sign']) ResponseBody = ElementTree.Element('ResponseBody') Trade_no = ElementTree.SubElement(ResponseBody, 'Trade_no') Status = ElementTree.SubElement(ResponseBody, 'Status') Trade_no.text = str(TradeNo) Status.text = '1' mo = ElementTree.tostring(ResponseBody) if sign == params['sign']: if int(params['Trade_status']) == 0 or int( params['Trade_status']) == 1: PayHelperV4.callback_ok(plantformId, float(params['Price']), params) Status.text = '0' mo = ElementTree.tostring(ResponseBody) TyContext.ftlog.info('doAiDongManCallback->SUCCESS rparams', params, 'mo', mo) return mo else: errinfo = '爱动漫支付失败' PayHelperV4.callback_error(plantformId, errinfo, params) TyContext.ftlog.error('doAiDongManCallback->ERROR, failDesc', errinfo, 'rparams', params, 'mo', mo) return mo else: errinfo = '签名校验失败' PayHelperV4.callback_error(plantformId, errinfo, params) TyContext.ftlog.error('doAiDongManCallback->ERROR, failDesc', errinfo, 'rparams', params) return mo