def doXYZSDJPayCallback(cls, rpath): # 获取XY助手单机斗地主的appkey和paykey rparam = TyContext.RunHttp.convertArgsToDict() orderPlatformId = rparam["extra"] try: appid = rparam['orderid'].split('_')[0] keyvalue = TyContext.Configure.get_global_item_json( 'XYDJSdk_config', {}) if keyvalue and appid in keyvalue: appkey = keyvalue[appid]['appkey'] paykey = keyvalue[appid]['paykey'] else: config = GameItemConfigure.get_game_channel_configure_by_orderId( orderPlatformId) appkey = config.get('appkey', "") paykey = config.get('paykey', "") if not appkey or not paykey: TyContext.ftlog.error( 'TuYouPayXYZS->doXYZSDJPayCallback get appkey and paykey ERROR' ) return cls._response_result(8) except: TyContext.ftlog.error( 'TuYouPayXYZS->doXYZSDJPayCallback get appkey and paykey ERROR' ) return cls._response_result(8) TyContext.ftlog.debug( 'TuYouPayXYZS->doXYZSDJPayCallback rparam: [%s], appid: [%s], appkey: [%s], paykey: [%s]' % (rparam, appid, appkey, paykey)) ChargeModel.save_third_pay_order_id(orderPlatformId, rparam.get('orderid', '')) return cls._docallback(appkey, paykey)
def doVivoCallback(cls, rpath): rparam = TyContext.RunHttp.convertArgsToDict() TyContext.ftlog.info('doVivoCallback->rparam=', rparam) orderPlatformId = rparam['storeOrder'] try: appinfoconfig = TyContext.Configure.get_global_item_json( 'vivo_appkeys', {}) cpId = rparam['storeId'] appdata = appinfoconfig[str(cpId)] appKey = appdata['cpkey'] except KeyError: config = GameItemConfigure.get_game_channel_configure_by_orderId( orderPlatformId, 'vivo') appKey = config.get('vivo_cpkey') sign = rparam['signature'] if not cls.__verify_sign(rparam, appKey, sign): return 'ERROR' total_fee = float(rparam['orderAmount']) ChargeModel.save_third_pay_order_id(rparam.get('vivoOrder', '')) isOk = PayHelperV4.callback_ok(orderPlatformId, total_fee, rparam) if isOk: return 'SUCCESS' else: return 'ERROR'
def doPayAiSiCallback(cls, rpath): rparam = TyContext.RunHttp.convertArgsToDict() TyContext.ftlog.debug('TuYouPayAiSi->rparam', rparam) try: orderPlatformId = rparam['billno'] total_fee = float(rparam['amount']) status = int(rparam['status']) sign = rparam['sign'] third_orderid = rparam['order_id'] appid = rparam['app_id'] except Exception as e: TyContext.ftlog.error('TuYouPayAiSi->doPayAiSiCallback Error: ', e) return 'fail' # 验签 if not cls.VerifySign(sign, rparam): TyContext.ftlog.error( 'TuYouPayMiDaShi->doMiDaShiPayCallback Verify sign ERROR!') return 'fail' rparam['third_orderid'] = third_orderid rparam['chargeType'] = 'aisi' if status == 0: ChargeModel.save_third_pay_order_id(orderPlatformId, third_orderid) PayHelperV4.callback_ok(orderPlatformId, total_fee, rparam) return 'success' elif status == 1: return 'success' else: errinfo = '支付失败' PayHelperV4.callback_error(orderPlatformId, errinfo, rparam) return 'fail'
def __check_callback(cls, rparam, appKey): signQuery = rparam['signature'] del rparam['signature'] sk = rparam.keys() sk.sort() queryStr = "" for k in sk: queryStr = queryStr + str(k) + '=' + str(rparam[k]) + '&' signData = queryStr[:-1] TyContext.ftlog.info('doXiaomiCallback->queryStr=', queryStr, 'signData=', signData) a = hmac.new(appKey, signData, sha1) sign = a.digest().encode('hex').upper() if signQuery.upper() != sign: TyContext.ftlog.info( 'doXiaomiCallback->ERROR, sign error !! signQuery=', signQuery, 'sign=', sign) return '{"errcode":1525}' orderPlatformId = rparam['cpOrderId'] total_fee = float(rparam['payFee']) / 100 ChargeModel.save_third_pay_order_id(orderPlatformId, rparam.get('orderId')) isOk = PayHelperV4.callback_ok(orderPlatformId, total_fee, rparam) if isOk: return '{"errcode":200}' else: return '{"errcode":1506}'
def doLenovoDanjiCallback(cls, rpath): rparam = TyContext.RunHttp.convertArgsToDict() TyContext.ftlog.info('doLenovoDanjiCallback->rparam=', rparam) try: transdata = rparam['transdata'] verifyData = transdata signStr = rparam['sign'] transdata = json.loads(transdata) TyContext.ftlog.debug( 'TuYouPayLenovoDanji->doLenovoDanjiCallback transdata: ', transdata) orderPlatformId = transdata['cpprivate'] appid = transdata['appid'] total_fee = transdata['money'] result = transdata['result'] paytype = transdata['paytype'] ChargeModel.save_third_pay_order_id(orderPlatformId, transdata.get('transid')) except Exception as e: TyContext.ftlog.error( 'TuYouPayLenovoDanji->doLenovoDanjiCallback ERROR:', e) return 'FAILURE' if '0' != str(result): TyContext.ftlog.error( 'TuYouPayLenovoDanji->doLenovoDanjiCallback ERROR, sign error !! rparam=', rparam, 'sign=', sign) PayHelperV4.callback_error(orderPlatformId, '支付失败', transdata) return 'FAILURE' appkeyconfig = TyContext.Configure.get_global_item_json( 'lenovodanji_config', {}) if not appkeyconfig: TyContext.ftlog.error( 'TuYouPayLenovoDanji->doLenovoDanjiCallback Doesn\'t find appkeyconfig by lenovodanji_config' ) for item in appkeyconfig: if 0 == cmp(appid, item['appId']): lenovodanji_prikey_str = item['appKey'] break else: TyContext.ftlog.error( 'TuYouPayLenovoDanji->doLenovoDanjiCallback Doesn\'t find appkey by appid:', appid) config = GameItemConfigure.get_game_channel_configure_by_orderId( orderPlatformId, 'lenovodj') lenovodanji_prikey_str = cls.loadRsaPrivateKey( config.get('lenovo_appKey', "")) if not cls.verifySign(lenovodanji_prikey_str, verifyData, signStr): TyContext.ftlog.error( 'TuYouPayLenovoDanji->doLenovoDanjiCallback ERROR, sign error') return 'FAILURE' transdata['sub_paytype'] = paytype PayHelperV4.callback_ok(orderPlatformId, float(total_fee) / 100, transdata) return 'SUCCESS'
def doMeizuPayCallback(cls, rpath): rparam = TyContext.RunHttp.convertArgsToDict() TyContext.ftlog.info('doMeizuPayCallback rparam', rparam) cp_order_id = None try: cp_order_id = rparam['cp_order_id'] total_price = float(rparam['total_price']) trade_status = rparam['trade_status'] ChargeModel.save_third_pay_order_id(cp_order_id, rparam.get('order_id', '')) except Exception as e: TyContext.ftlog.error('doMeizuCallback param error, exception', e, 'cp_order_id', cp_order_id) return json.dumps({ 'code': 900000, 'message': '参数不匹配', 'redirect': '', 'value': None }) if not cls._check_sign(rparam): TyContext.ftlog.error('TuYouPayMeizu _check_sign failed', cp_order_id) return json.dumps({ 'code': 900000, 'message': '签名错误', 'redirect': '', 'value': None }) if trade_status == '3': PayHelperV4.callback_ok(cp_order_id, total_price, rparam) return json.dumps({ 'code': 200, 'message': '充值成功', 'redirect': '', 'value': None }) elif trade_status == '4': PayHelperV4.callback_error(cp_order_id, '订单取消', rparam) return json.dumps({ 'code': 900000, 'message': '', 'redirect': '', 'value': None }) elif trade_status == '1' or trade_status == '2': return json.dumps({ 'code': 90000, 'message': '订单处理中', 'redirect': '', 'value': None }) elif trade_status == '5': return json.dumps({ 'code': 90000, 'message': '订单异常取消', 'redirect': '', 'value': None })
def doIappayPayCallback(cls, rpath): rparam = TyContext.RunHttp.convertArgsToDict() transdata = rparam['transdata'] transdata = json.loads(transdata) sign = rparam['sign'] appid = transdata['appid'] signtype = rparam['signtype'] iappayConfig = TyContext.Configure.get_global_item_json( 'iappay_config', {}) try: pubkey = iappayConfig.get(appid)['pubkey'] if iappayConfig.get( appid) else "" orderPlatformId = transdata['cporderid'] total_fee = transdata['money'] result = transdata['result'] ChargeModel.save_third_pay_order_id(orderPlatformId, transdata.get('transid')) except Exception as e: TyContext.ftlog.error('doIappayPayCallback->ERROR, exception', e, 'rparam', transdata) return 'error' if not pubkey: chargeKey = 'sdk.charge:' + orderPlatformId chargeInfo = TyContext.RedisPayData.execute( 'HGET', chargeKey, 'charge') if chargeInfo: chargeInfo = TyContext.strutil.loads(chargeInfo, decodeutf8=True) else: return 'failed' chargeType = chargeInfo['chargeType'] sdk = chargeType.split('.')[0] config = GameItemConfigure.get_game_channel_configure_by_orderId( orderPlatformId, sdk) pubkey = config.get('iappay_pubKey') if not pubkey: TyContext.ftlog.error( 'doIappayPayCallback->ERROR,cannot get sdkconfig for', appid) return 'failed' pubkey = cls.loadRsaPublicKey(pubkey) if not cls._verify_sign(rparam, sign, pubkey): errinfo = '支付失败' PayHelperV4.callback_error(orderPlatformId, errinfo, rparam) return 'failed' if result != 0: errinfo = '支付失败' TyContext.ftlog.error( 'doIappayPayCallback->ERROR, exception, result not 0') PayHelperV4.callback_error(orderPlatformId, errinfo, rparam) return 'failed' PayHelperV4.callback_ok(orderPlatformId, total_fee, rparam) return 'success'
def doMaopaoPayCallback(cls, rpath): rparam = TyContext.RunHttp.convertArgsToDict() maopaoInfo = {} maopaoInfo['orderId'] = rparam['orderId'] maopaoInfo['skyId'] = rparam['skyId'] maopaoInfo['resultCode'] = rparam['resultCode'] maopaoInfo['payNum'] = rparam['payNum'] maopaoInfo['cardType'] = rparam['cardType'] maopaoInfo['realAmount'] = rparam['realAmount'] maopaoInfo['payTime'] = rparam['payTime'] maopaoInfo['failure'] = rparam['failure'] maopaoInfo['signMsg'] = rparam['signMsg'] rparam['third_orderid'] = maopaoInfo['payNum'] rparam['chargeType'] = 'maopao' maopaoConfig = TyContext.Configure.get_global_item_json( 'maopao_config', {}) md5key = maopaoConfig['md5key'] signParams = rparam['orig_uri'] signInfo = signParams[signParams.find('?') + 1:signParams.find('signMsg') - 1] + '&' + 'key' + '=' + md5key TyContext.ftlog.info('doMaopaoCallback signInfo', signInfo) total_fee = int(maopaoInfo['realAmount']) / 100 orderPlatformId = maopaoInfo['orderId'] sign = cls._cal_sign(signInfo) TyContext.ftlog.debug('doMaopaoCallback sign', sign, 'signMsg', maopaoInfo['signMsg'], 'signInfo', signInfo) if sign == maopaoInfo['signMsg']: if int(maopaoInfo['realAmount']) > 0: ChargeModel.save_third_pay_order_id(orderPlatformId, maopaoInfo['payNum']) PayHelperV4.callback_ok(orderPlatformId, total_fee, rparam) TyContext.ftlog.info('doMaopaoCallback->SUCCESSFUL rparam', rparam) return 'result=0' else: errinfo = '支付失败' PayHelperV4.callback_error(orderPlatformId, errinfo, rparam) TyContext.ftlog.error('doMaopaoCallback->ERROR, failDesc', errinfo, 'rparam', rparam) else: errinfo = '签名校验失败' PayHelperV4.callback_error(orderPlatformId, errinfo, rparam) TyContext.ftlog.error('doMaopaoCallback->ERROR, failDesc', errinfo, 'rparam', rparam) return 'result=0'
def doMomoCallback(cls, rpath): rparam = TyContext.RunHttp.convertArgsToDict() momo_paykeys = TyContext.Configure.get_global_item_json( 'momo_paykeys', {}) TyContext.ftlog.debug('doMomoCallback->rparam=', rparam) try: orderPlatformId = rparam['app_trade_no'] trade_no = rparam['trade_no'] appid = rparam['appid'] postparams = {} postparams['appid'] = appid postparams['sign'] = rparam['sign'] postparams['trade_no'] = trade_no postparams['app_secret'] = momo_paykeys[str(appid)] response, _ = TyContext.WebPage.webget(cls.checkorder_url, postdata_=postparams) response = json.loads(response) if int(response['ec']) != 0: TyContext.ftlog.error( 'doMomoCallback->ERROR, check momo order fail, response=', response) return 'fail' except: TyContext.ftlog.exception() TyContext.ftlog.error('doMomoCallback->ERROR, rparam=', rparam) return 'fail' if int(rparam['currency_type']) == 0: total_fee = float(rparam['total_fee']) else: total_fee = float(rparam['total_fee']) / 10 rparam['third_orderid'] = trade_no rparam['chargeType'] = 'momo' # channel_type string 支付渠道 0-苹果 1-支付宝 2-短信 3-陌陌币 4-网页版 rparam['sub_paytype'] = rparam['channel_type'] try: chargeKey = 'sdk.charge:' + orderPlatformId chargeInfo = TyContext.RedisPayData.execute( 'HGET', chargeKey, 'charge') if chargeInfo == None: chargeInfo = {} else: chargeInfo = TyContext.strutil.loads(chargeInfo, decodeutf8=True) chargeInfo['sub_paytype'] = rparam['channel_type'] TyContext.RedisPayData.execute('HSET', chargeKey, 'charge', json.dumps(chargeInfo)) except: TyContext.ftlog.error() ChargeModel.save_third_pay_order_id(orderPlatformId, trade_no) isOk = PayHelperV4.callback_ok(orderPlatformId, total_fee, rparam) return 'success'
def save_order(self, chargeInfo, consumeInfo): orderId = chargeInfo['platformOrderId'] datas = [ 'state', PayConst.CHARGE_STATE_BEGIN, 'createTime', datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'charge', json.dumps(chargeInfo), ] if consumeInfo: datas.extend(['consume', json.dumps(consumeInfo)]) ChargeModel.save_order(orderId, *datas)
def doCallback(cls, rpath): data = TyContext.RunHttp.get_body_content() rparams = json.loads(data) platformOrderId = rparams['orderId'] TyContext.ftlog.debug('TuYouPayKuaiwan->doCallback, rparams=', rparams) if not cls.check_sign(rparams): TyContext.ftlog.error('TuYouPayKuaiwan->ERROR, sign error !! rparam=', rparams) return 'failure' # do charge ChargeModel.save_third_pay_order_id(platformOrderId, rparams.get('trade_sn', '')) isOk = PayHelperV4.callback_ok(platformOrderId, -1, rparams) if isOk: return 'success' else: return 'failure'
def doCallback(cls, rpath): rparams = TyContext.RunHttp.convertArgsToDict() TyContext.ftlog.debug('TuYouPayLetv->doCallback, rparams=', rparams) order_id = rparams['cooperator_order_no'] if not cls.check_sign(rparams): TyContext.ftlog.error('TuYouPayLetv->ERROR, sign error !! rparam=', rparams) return 'fail' ChargeModel.save_third_pay_order_id(order_id, rparams.get('lepay_order_no', '')) # do charge is_ok = PayHelperV4.callback_ok(order_id, -1, rparams) if is_ok: return 'success' else: return 'fail'
def doCallback(cls, rpath): rparams = TyContext.RunHttp.convertArgsToDict() platformOrderId = rparams['app_order_id'] TyContext.ftlog.debug('TuYouPayPapa->doCallback, rparams=', rparams) if not cls.check_sign(rparams): TyContext.ftlog.error('TuYouPayPapa->ERROR, sign error !! rparam=', rparams) return 'failure' # do charge ChargeModel.save_third_pay_order_id( platformOrderId, rparams.get('pa_open_order_id', '')) isOk = PayHelperV4.callback_ok(platformOrderId, -1, rparams) if isOk: return 'success' else: return 'failure'
def do360payCallback(cls, rpath): TyContext.ftlog.debug('do360payCallback start') rparam = TyContext.RunHttp.convertArgsToDict() try: orderPlatformId = rparam['app_order_id'] appId = orderid.get_appid_frm_order_id(orderPlatformId) sign = rparam['sign'] except: TyContext.ftlog.info( 'do360payCallback->ERROR, param error !! rparam=', rparam) return "error" clientId = rparam['app_ext1'] app_key = rparam['app_key'] client_ids = TyContext.Configure.get_game_item_json( appId, 'account.360.client.version', {}) clientver = '' if clientId in client_ids: clientver = str(client_ids[clientId]) client_secret = TyContext.Configure.get_game_item_str( appId, 'account.360.client.secret.' + app_key) if not client_secret: config = GameItemConfigure.get_game_channel_configure_by_orderId( orderPlatformId, "360") client_secret = config.get('QHOPENSDK_APPSECRET') if not client_secret: TyContext.ftlog.error( 'Account360 the appinfo of QIHOO(appKey:%s) is not found !' % app_key) return "error" # 签名校验 if not cls.__verify_sign(rparam, client_secret, sign): TyContext.ftlog.error( 'TuyouPay360pay.do360payCallbacksign verify error !!') return "error" total_fee = float(rparam['amount']) / 100 ChargeModel.save_third_pay_order_id(orderPlatformId, rparam.get('order_id', '')) isOk = PayHelperV4.callback_ok(orderPlatformId, total_fee, rparam) if isOk: return "ok" else: return "error"
def handle_callback(self, rpath): rparams = TyContext.RunHttp.convertArgsToDict() platformOrderId = rparams['out_trade_no'] aliOrder = rparams['trade_no'] config = GameItemConfigure.get_game_channel_configure_by_orderId( platformOrderId, 'alipayapp') pubkey = config.get('alipay_publick_key') if not self.rsaVerify(self.createLinkString(rparams), rparams['sign'], pubkey): return 'failure' if rparams['trade_status'] != 'TRADE_SUCCESS' and rparams[ 'trade_status'] != 'TRADE_SUCCESS': return 'failure' total_fee = rparams['total_amount'] rparams['third_orderid'] = aliOrder ChargeModel.save_third_pay_order_id(platformOrderId, aliOrder) PayHelperV4.callback_ok(platformOrderId, total_fee, rparams) return 'success'
def doCallback(self, rpath): rparams = TyContext.RunHttp.convertArgsToDict() order_id = rparams['orderId'] price_coin = rparams['price'] config = TyContext.Configure.get_global_item_json('ysdk_keys', {}) app_id = rparams['ysdk_appid'] ysdk_model = rparams['ysdk_model'] ysdk_openId = rparams.get('ysdk_openid', '') ChargeModel.save_third_pay_order_id(order_id, 'openId:%s' % ysdk_openId) try: self.request_url = 'https://' + config['%s_url' % ysdk_model] app_key = config[app_id]['%s_appKey' % ysdk_model] except: config = GameItemConfigure.get_game_channel_configure_by_orderId(order_id, 'ysdk') self.request_url = 'https://' + config.get('ysdk_%s_url' % ysdk_model, "") app_key = config.get('ysdk_%s_appKey' % ysdk_model, "") if not self.request_url or not app_key: return 'check sign fail' # 验签 if not self.check_sign(rparams): return 'check sign fail' # 轮询金币是否到账 has_balance = self.get_balance_m('/mpay/get_balance_m', app_key, rparams) if not has_balance: return '充值金币未到账' # 尝试扣除金币 pay_response = self.pay_m('/mpay/pay_m', app_key, rparams) if 0 == int(pay_response['ret']) and order_id == pay_response['billno']: # 尝试发货 isOk = PayHelperV4.callback_ok(order_id, -1, rparams) if isOk: return '发货成功' else: # 发货失败尝试取消扣费 return self.cancel_pay_m('/mpay/cancel_pay_m', app_key, rparams) elif 1004 == int(pay_response['ret']): return '余额不足' elif 1018 == int(pay_response['ret']): return '登录校验失败' else: return '扣费失败'
def doDuoKuCallback(cls, rpath): TyContext.ftlog.info('doDuoKuCallback start') rparam = TyContext.RunHttp.convertArgsToDict() try: shortOrderPlatformId = rparam['cpdefinepart'] orderPlatformId = ShortOrderIdMap.get_long_order_id(shortOrderPlatformId) appId = rparam['appid'] sign = rparam['sign'] unit = rparam['unit'] amount = rparam['amount'] status = rparam['status'] mobileId = rparam.get('phone', '') except: TyContext.ftlog.info('doDuoKuCallback->ERROR, param error !! rparam=', rparam) TyContext.ftlog.exception() return 'failure' if status != 'success': PayHelperV4.callback_error(orderPlatformId, 'pay fail', rparam) return 'failure' paykey_dict = TyContext.Configure.get_global_item_json('duoku_paykeys', {}) paykey = paykey_dict.get(appId, "") if not paykey: config = GameItemConfigure.get_game_channel_configure_by_orderId(orderPlatformId) paykey = config.get('dksdk_appsecret', "") if not paykey: TyContext.ftlog.error("doDuokuCallback", "cannot get %s sdkconfig" % appId) # 签名校验 if not cls.__verify_sign(rparam, paykey, sign): return 'failure' if unit == 'fen': total_fee = float(amount) / 100 else: total_fee = float(amount) ChargeModel.save_third_pay_order_id(orderPlatformId, rparam.get('orderid')) rparam['chargeType'] = 'duoku' rparam['third_orderid'] = rparam['orderid'] PayHelperV4.set_order_mobile(orderPlatformId, mobileId) isOk = PayHelperV4.callback_ok(orderPlatformId, total_fee, rparam) if isOk: return 'success' else: return 'failure'
def doCallback(cls, rpath): postData = TyContext.RunHttp.get_body_content() TyContext.ftlog.info("postData", postData) response = urlparse.parse_qs(postData) order = response['order'][0].strip('"') sign = response['sign'][0].strip('"') jsonData = json.loads(order) platformOrderId = jsonData['game_order_id'] if not rsaVerify(order, sign, 'jolo'): TyContext.ftlog.debug('TuYouPayJolo->doCallback', 'order=%s' % order, 'sign=%s' % sign) return 'sign error' ChargeModel.save_third_pay_order_id(platformOrderId, jsonData.get('jolo_order_id', '')) isOk = PayHelperV4.callback_ok(platformOrderId, -1, jsonData) if isOk: return 'success' else: return 'error'
def doCallback(cls, rpath): rparams = TyContext.RunHttp.convertArgsToDict() content = rparams['content'] content_json = json.loads(content) orderId = content_json['out_trade_no'] if not cls.verify_sign(rparams): TyContext.ftlog.info('TuYouPayWandoujiadanji->sign verify ERROR') return "fail" total_fee = int(float(content_json['money'])) total_fee = int(total_fee / 100) ChargeModel.save_third_pay_order_id(orderId, content_json.get('orderId', '')) is_ok = PayHelperV4.callback_ok(orderId, total_fee, rparams) if is_ok: return 'success' else: return 'fail'
def doVivoCallback(cls, rpath): rparams = TyContext.RunHttp.convertArgsToDict() appId = rparams.get('verdorCode') platformOrderId = rparams.get('orderId') config = GameItemConfigure.get_game_channel_configure_by_orderId( platformOrderId, '16wifi') md5key = config.get('16wifi_key') signStr = '&'.join(k + '=' + rparams[k] for k in sorted(rparams.keys()) if rparams[k] and k != 'sign') signStr += '&key=%s' % md5key m = md5(signStr) if m.hexdigest().upper() != rparams['sign']: return {'ReturnCode': 1} total_fee = rparams.get('cashAmount') ChargeModel.save_third_pay_order_id(platformOrderId, rparams.get('payCode')) PayHelperV4.callback_ok(platformOrderId, total_fee, rparams) return {'ReturnCode': 200}
def doTongBuTuiPayCallback(cls, rpath): success = json.dumps({'status': 'success'}) fail = json.dumps({'status': 'fail'}) params = TyContext.RunHttp.convertArgsToDict() TyContext.ftlog.debug('TuYouPayTongBuTui->doPayTongBuTuiCallback Request Params: ', params) rparam = OrderedDict() try: rparam['source'] = params['source'] rparam['trade_no'] = params['trade_no'] rparam['amount'] = params['amount'] rparam['partner'] = params['partner'] rparam['paydes'] = params['paydes'] rparam['debug'] = params['debug'] rparam['tborder'] = params['tborder'] rparam['sign'] = params['sign'] except Exception as e: TyContext.ftlog.error('TuYouPayTongBuTui->doPayTongBuTuiCallback Get Params ERROR. ', e) return fail # appid = 150918, appkey = rBODan#VKXuF8He2B4Olyn@KhXu8RG2q # 获取key,根据partner keyvalue = TyContext.Configure.get_global_item_json('tongbutui_config', {}) # 获取同步推的key for value in keyvalue: if 0 == cmp(value['appid'], params['partner']): appkey = value['appkey'] break else: TyContext.ftlog.error('TuYouPayHaiMaWan->doHaiMaWanPayCallback get appkey ERROR') return 'fail' rparam['key'] = appkey sign = cls.generate_verifysign(rparam) if 0 != cmp(sign, rparam['sign']): TyContext.ftlog.error('TuYouPayHaiMaWan->doHaiMaWanPayCallback verify sign ERROR.' 'sign: [%s], verify_sign: [%s]' % (rparam['sign'], sign)) return fail # 通知游戏服发货 rparam['third_orderid'] = rparam['tborder'] ChargeModel.save_third_pay_order_id(rparam['trade_no'], rparam['tborder']) PayHelperV4.callback_ok(rparam['trade_no'], float(rparam['amount']) / 100, rparam) return success
def handle_callback(self, rpath): rparams = TyContext.RunHttp.convertArgsToDict() sigStr = '&'.join(k + '=' + rparams[k] for k in sorted(rparams) if k != 'sign' and rparams[k]) platformOrderId = rparams['cp_order_id'] config = GameItemConfigure.get_game_channel_configure_by_orderId( platformOrderId, 'liebao') md5key = config.get('liebao_key', 'kxkSJClvdDidZ7AOc9T1wGfLQiXd6r8P') sigStr += md5key from hashlib import md5 m = md5(sigStr) if m.hexdigest().lower() != rparams['sign']: return 'fail' if rparams['status'] != "2": TyContext.ftlog.info("liebao callback fail,status error", rparams['status']) return 'fail' total_fee = rparams['total_price'] ChargeModel.save_third_pay_order_id(platformOrderId, rparams['order_id']) PayHelperV4.callback_ok(platformOrderId, total_fee, rparams) return 'success'
def doHuaWeiCallback(self, rpath): rparam = TyContext.RunHttp.convertArgsToDict() TyContext.ftlog.info('doHuaWeiCallback->rparam=', rparam) try: orderPlatformId = rparam['requestId'] clientId = rparam['extReserved'] huawei_config = TyContext.Configure.get_global_item_json( 'huawei_config', {}) try: hwapps = huawei_config.get[clientId] except KeyError: config = GameItemConfigure.get_game_channel_configure_by_orderId( orderPlatformId, 'huawei') hwapps = { 'pay_ras_pub_key': config.get('huaWei_publicKey'), 'pay_ras_privat_key': config.get('huaWei_privateKey'), } isOk = self.__check_ras_code__(hwapps, rparam, False) if isOk: total_fee = float(rparam['amount']) try: # huawei sdk also use payType, which is tuyou's sub_paytype rparam['sub_paytype'] = rparam['payType'] del rparam['payType'] except: pass ChargeModel.save_third_pay_order_id(orderPlatformId, rparam.get('orderId', '')) isOk = PayHelper.callback_ok(orderPlatformId, total_fee, rparam) if isOk: return '{"result":0}' else: return '{"result":3}' else: return '{"result":1}' except: TyContext.ftlog.exception() return '{"result":94}'
def doWanDouJiaCallback(self, rpath): rparam = TyContext.RunHttp.convertArgsToDict() TyContext.ftlog.info('doWanDouJiaCallback->rparam=', rparam) transdata = rparam['content'] datas = json.loads(transdata) appId = datas['appKeyId'] orderPlatformId = datas['out_trade_no'] try: appkeyconfig = TyContext.Configure.get_global_item_json( 'wannew_appkeys', {}) appKey = appkeyconfig[str(appId)] except: config = GameItemConfigure.get_game_channel_configure_by_orderId( orderPlatformId, 'wannew') TyContext.ftlog.debug('wandoujia,get sdk config -->', config) if not config: TyContext.ftlog.exception() TyContext.ftlog.info( 'doWanDouJiaCallback->ERROR, sign error !! transdata=', transdata) return 'Fail' appKey = config.get('wannew_secretKey') # appKey = self.appkeys[str(appId)] sign = rparam['sign'] if self.verifySign(transdata, sign, appKey) != True: TyContext.ftlog.info( 'doWanDouJiaCallback->ERROR, sign error !! transdata=', transdata, 'sign=', sign) return 'Fail' trade_status = 'TRADE_FINISHED' total_fee = int(float(datas['money'])) total_fee = int(total_fee / 100) ChargeModel.save_third_pay_order_id(orderPlatformId, datas.get('orderId', '')) isOk = PayHelperV4.callback_ok(orderPlatformId, total_fee, rparam) if isOk: return 'Success' else: return 'Fail'
def doLenovoCallback(self, rpath): rparam = TyContext.RunHttp.convertArgsToDict() TyContext.ftlog.info('doLenovoCallback->rparam=', rparam) transdata = rparam['transdata'] try: datas = json.loads(transdata) appId = datas['appid'] except: TyContext.ftlog.exception() TyContext.ftlog.info( 'doLenovoCallback->ERROR, sign error !! transdata=', transdata) return 'ERROR' orderPlatformId = datas['exorderno'] ChargeModel.save_third_pay_order_id(orderPlatformId, datas.get('transid', '')) appkeyconfig = TyContext.Configure.get_global_item_json( 'lenovo_appkeys', {}) try: appKey = appkeyconfig[str(appId)] except KeyError: config = GameItemConfigure.get_game_channel_configure_by_orderId( orderPlatformId, 'lenovo') appKey = config.get('lenovo_appKey') sign = rparam['sign'] if self.verifySign(transdata, sign, appKey) != True: TyContext.ftlog.info( 'doLenovoCallback->ERROR, sign error !! transdata=', transdata, 'sign=', sign) return 'ERROR' total_fee = float(datas['money']) / 100 isOk = PayHelperV4.callback_ok(orderPlatformId, total_fee, rparam) if isOk: return 'SUCCESS' else: return 'ERROR'
def doCallback(self, rpath): rparam = TyContext.RunHttp.convertArgsToDict() transdata = rparam['transdata'] transdata = json.loads(transdata) sign = rparam['sign'] appid = transdata['appid'] signtype = rparam['signtype'] orderPlatformId = transdata['cporderid'] try: coolpad_keys = TyContext.Configure.get_global_item_json('coolpad_keys', {}) pubkey = coolpad_keys[appid]['publicKey'] except: config = GameItemConfigure.get_game_channel_configure_by_orderId(orderPlatformId, 'coolpad') pubkey = config.get('coolpad_appPubKey', '') if not pubkey: TyContext.ftlog.debug("doCoolpadCallback,cannot find coolpad sdkconfig for", appid) return 'error' pubkey = self.loadRsaPublicKey(pubkey) try: # total_fee = transdata['money'] result = transdata['result'] except Exception as e: TyContext.ftlog.error('doCoolpadPayCallback->ERROR, exception', e, 'rparam', transdata) return 'error' if not self._verify_sign(rparam, sign, pubkey): errinfo = '支付失败' ChargeModel.save_third_pay_order_id(orderPlatformId, transdata.get('transid', '')) PayHelperV4.callback_error(orderPlatformId, errinfo, rparam) return 'failed' if result != 0: errinfo = '支付失败' TyContext.ftlog.error('doCoolpadPayCallback->ERROR, exception, result not 0') PayHelperV4.callback_error(orderPlatformId, errinfo, rparam) return 'failed' PayHelperV4.callback_ok(orderPlatformId, -1, rparam) return 'success'
def doUcDjCallback(cls, rpath): body = TyContext.RunHttp.get_body_content() TyContext.ftlog.debug('TuYouPayUcDj->doUcDjCallback Request data: ', body) rparam = TyContext.strutil.loads(body, decodeutf8=True) try: data = rparam['data'] orderPlatformId = data['orderId'] state = data['orderStatus'] total_fee = data['amount'] sign = rparam['sign'] thirdorderid = data['tradeId'] except: TyContext.ftlog.error( 'TuYouPayUcDj->doUcDjCallback ERROR, param error !! rparam=', rparam) return 'FAILURE' # 签名校验 if not cls.__verify_sign(data, sign): TyContext.ftlog.error( 'TuYouPayUcDj->doUcDjCallback verify error !!') return 'FAILURE' # 充值状态校验 if state != 'S': TyContext.ftlog.info( 'TuYouPayUcDj->doUcDjCallback charge failed. fail reason:', data['failedDesc']) PayHelperV4.callback_error(orderPlatformId, data['failedDesc'], rparam) return 'SUCCESS' data['third_orderid'] = thirdorderid total_fee = float(total_fee) ChargeModel.save_third_pay_order_id(orderPlatformId, thirdorderid) PayHelperV4.callback_ok(orderPlatformId, total_fee, data) return 'SUCCESS'
def doKuaiYongPingGuoPayCallback(cls, rpath): rparam = TyContext.RunHttp.convertArgsToDict() TyContext.ftlog.debug( 'TuYouPayKuaiYongPingGuo->doKuaiYongPingGuoPayCallback rparam', rparam) ''' uid = rparam['uid'] subject = rparam['subject'] version = rparam['version'] ''' thirdId = rparam['orderid'] platformOrderId = rparam['dealseq'] encryptData = rparam['notify_data'] sign = rparam['sign'] verifySign = ''.join([ k + '=' + str(rparam[k]) + '&' for k in sorted(rparam.keys()) if k != 'sign' ]) verifySign = verifySign[0:-1] TyContext.ftlog.debug( 'TuYouPayKuaiYongPingGuo->doKuaiYongPingGuoPayCallback verifySign', verifySign) # 公钥验签 if not _verify_with_publickey_pycrypto(verifySign, sign, _kuaiyongpingguo_pubkey_py): TyContext.ftlog.error( 'TuYouPayKuaiYongPingGuo->doKuaiYongPingGuoPayCallback public verify fail' ) return 'failed' # 公钥解密:加载.so文件,python嵌入动态库 decryptData = rsa_decrypto_with_publickey(encryptData, KUAIYONGPINGGUO_PUB_KEY, 1) TyContext.ftlog.debug( 'TuYouPayKuaiYongPingGuo->doKuaiYongPingGuoPayCallback decryptData', decryptData) # 将dealseq=20130219160809567&fee=0 .01&payresult=0转化为dict结构. responseStatus = {} attr = decryptData.split('&') for param in attr: params = param.split('=') responseStatus[params[0]] = params[1] TyContext.ftlog.debug( 'TuYouPayKuaiYongPingGuo->doKuaiYongPingGuoPayCallback responseStatus', responseStatus) rparam['third_orderid'] = thirdId rparam['chargeType'] = 'kuaiyongpingguo' if 0 == int(responseStatus['payresult']): total_fee = int(float(responseStatus['fee'])) chargeKey = 'sdk.charge:' + platformOrderId chargeInfo = TyContext.RedisPayData.execute( 'HGET', chargeKey, 'charge') chargeInfo = json.loads(chargeInfo) # 当返回的fee和商品定价不一致时,采用商品本身的价格 TyContext.ftlog.debug( 'TuYouPayKuaiYongPingGuo->doKuaiYongPingGuoPayCallback chargeInfo', chargeInfo, chargeInfo['chargeTotal'], total_fee) if chargeInfo['chargeTotal'] != total_fee: total_fee = chargeInfo['chargeTotal'] ChargeModel.save_third_pay_order_id(platformOrderId, thirdId) PayHelperV4.callback_ok(platformOrderId, total_fee, rparam) return 'success' else: errinfo = '支付失败' PayHelperV4.callback_error(platformOrderId, errinfo, rparam) return 'failed'
def doAnZhiCallback(cls, rpath): postData = TyContext.RunHttp.get_body_content() TyContext.ftlog.debug( 'TuYouPayAnZhi->doAnZhiCallback original postData is:', postData) paramslist = postData.split('&') rparam = {} for k in paramslist: paramdata = k.split('=') rparam[paramdata[0]] = paramdata[1] TyContext.ftlog.debug( 'TuYouPayAnZhi->doAnZhiCallback parame list(Before urldecode) is: ', rparam) for k in rparam.keys(): rparam[k] = unquote(rparam[k]) TyContext.ftlog.debug( 'TuYouPayAnZhi->doAnZhiCallback parame list(After urldecode) is: ', rparam) if 'data' in rparam and 'appId' in rparam: data = rparam['data'] appId = rparam['appId'] else: TyContext.ftlog.error( 'TuYouPayAnZhi->doAnZhiCallback ERROR There doesn\'t has data or appId in post data.' ) return 'failed' anzhiconfig = TyContext.Configure.get_global_item_json( 'anzhi_config', {}) encryptKey = "" if anzhiconfig: for item in anzhiconfig: if 0 == cmp(item['appId'], appId): encryptKey = item['appsecret'] break else: TyContext.ftlog.error( 'TuYouPayAnZhi->doAnZhiCallback ERROR Cann\'t find appsecert, appId is: ', appId) else: TyContext.ftlog.error( 'TuYouPayAnZhi->doAnZhiCallback ERROR cann\'t find anzhi_config.' ) if not encryptKey: charge_key = 'sdk.charge:anzhi:%s' % appId encryptKey = TyContext.RedisPayData.execute( 'HGET', charge_key, 'appSecret') TyContext.ftlog.debug('get sdk config from redis,', encryptKey) try: # 先用base64解码,再采用3des解密 tripelDes = triple_des(encryptKey.encode('ascii'), mode=ECB, padmode=PAD_NORMAL) data = tripelDes.decrypt(base64.b64decode(data)) data = "".join([data.rsplit("}", 1)[0], "}"]) TyContext.ftlog.debug('TuYouPayAnZhi->doAnZhiCallback Data is: ', data) params = json.loads(data) params['third_orderid'] = params['orderId'] # 三方订单号 orderPlatformId = params['cpInfo'] # 途游订单号 orderAmount = params['orderAmount'] # 商品金额(分) redBagMoney = params['redBagMoney'] code = int(params['code']) # 订单状态 成功:1 ChargeModel.save_third_pay_order_id(orderPlatformId, params['orderId']) TyContext.ftlog.info('TuYouPayAnZhi->doAnZhiCallback params: ', params, ' orderPlatformId is: ', orderPlatformId) except Exception as e: TyContext.ftlog.error('TuYouPayAnZhi->doAnZhiCallback ERROR: ', e) return 'success' # 安智的同事说,只会出现code==1的情况,这里只是为了以防万一 if 1 != code: TyContext.ftlog.error() errinfo = '安智支付失败' PayHelperV4.callback_error(orderPlatformId, errinfo, params) # 2) orderAmount+redBagMoney 应等于道具金额,金额验证异常请返回”money_error”。 chargeKey = 'sdk.charge:' + orderPlatformId chargeTotal = TyContext.RedisPayData.execute('HGET', chargeKey, 'chargeTotal') anzhiTotal = (float(orderAmount) + float(redBagMoney)) / 100 if float(chargeTotal) != anzhiTotal: return 'money_error' PayHelperV4.callback_ok(orderPlatformId, anzhiTotal, params) return 'success'