def doYdjdCallback(self, rpath): xmldata = TyContext.RunHttp.get_body_content() TyContext.ftlog.debug('TuYouPayYdjd.doYdjdCallback in xmldata=', xmldata) notifys = {'xml': xmldata, 'chargeType': 'ydjd'} try: xmlroot = ElementTree.fromstring(xmldata) ret = xmlroot.find('hRet').text status = xmlroot.find('status').text userId = xmlroot.find('userId').text contentId = xmlroot.find('contentId').text consumeCode = xmlroot.find('consumeCode').text orderPlatformId = xmlroot.find('cpparam').text[2:] except Exception as e: msg = 'failure' TyContext.ftlog.error('TuYouPayYdjd.doYdjdCallback:', msg, e) return TuYouPayYdjdV4.XML_RET % (1, msg) notifys['pay_appid'] = contentId notifys['third_prodid'] = consumeCode notifys['third_userid'] = userId if ret != '0' or status != '1800': msg = 'ret(%s) is not 0 or status(%s) is not 1800' % (ret, status) TyContext.ftlog.error('TuYouPayYdjd.doYdjdCallback:', msg) PayHelperV4.callback_error(orderPlatformId, msg, notifys) return TuYouPayYdjdV4.XML_RET % (1, 'failure') isOk = PayHelperV4.callback_ok(orderPlatformId, -1, notifys) if isOk: return TuYouPayYdjdV4.XML_RET % (0, 'successful') else: return TuYouPayYdjdV4.XML_RET % (1, 'failure')
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 doAliCallback(self, rpath): rparam = PayHelperV4.getArgsDict() TyContext.ftlog.info('doAliCallbackNew->args=', rparam) sign = rparam['sign'] notify_data = self.createLinkString(rparam) # TyContext.ftlog.info('doAliCallbackNew->notify_data=', notify_data) # TyContext.ftlog.info('doAliCallbackNew->sign=', sign) # 签名校验 if not self.rsaVerify(notify_data, **rparam): TyContext.ftlog.error('TuyouPayTuyou.doAliCallback rsa verify error !!') return 'error' trade_status = rparam['trade_status'] total_fee = rparam['total_fee'] subject = rparam['subject'] out_trade_no = rparam['out_trade_no'] trade_no = rparam['trade_no'] platformOrderId = out_trade_no chargeKey = 'sdk.charge:' + platformOrderId oldState, chargeInfo, consumeInfo = TyContext.RedisPayData.execute('HMGET', chargeKey, 'state', 'charge', 'consume') chargeInfo = TyContext.strutil.loads(chargeInfo, decodeutf8=True) if chargeInfo else {} appId = int(chargeInfo.get('appId', 9999)) chargeType = chargeInfo.get('chargeType', 'tuyou.ali') notifys = {'status': trade_status, 'total_fee': total_fee, 'subject': subject, 'out_trade_no': out_trade_no, 'trade_no': trade_no, 'sign': sign, 'notify_data': notify_data, 'chargeType': chargeType, 'third_orderid': trade_no} if trade_status == 'TRADE_CLOSED': PayHelperV4.callback_error(platformOrderId, 'TRADE_CLOSED', notifys) return 'success' if trade_status != 'TRADE_SUCCESS' and trade_status != 'TRADE_FINISHED': if chargeInfo.get('chargeType') == 'alibig': userId = chargeInfo['userId'] timestamp, count = TyContext.RedisPayData.execute('HMGET', 'alibig:%s' % userId, 'timestamp', 'count') now = date.fromtimestamp(int(time.time())) if timestamp and now.toordinal() == date.fromtimestamp(int(timestamp)).toordinal(): count = int(count) + 1 else: timestamp = int(time.time()) count = 1 TyContext.RedisPayData.execute('HMSET', 'alibig:%s' % userId, 'timestamp', timestamp, 'count', count) return 'success' isOK = PayHelperV4.callback_ok(platformOrderId, -1, notifys) if isOK: return 'success' else: return 'error'
def doAiGameMsgCallback(self, rpath): notifys = TyContext.RunHttp.convertArgsToDict() cpparam = notifys.get('cpparam', '') if not cpparam: appkeys = '62d55e5d5d47f5d0121d2049d6893bc1' return self._doAiGameMsgCallbackNew(appkeys, rpath) resultcode = notifys.get('resultCode', '') resultmsg = notifys.get('resultMsg', '') try: order_paytype = notifys['payType'] notifys['sub_paytype'] = order_paytype except: order_paytype = '' validatecode = notifys.get('validatecode', '') # 限制ip请求 # clientIp = TyContext.RunHttp.get_client_ip() # TyContext.ftlog.info('TuYouPayAiGame.doAiGameMsgCallback in clientIp=', clientIp) # iplist = clientIp.split('.') # if len(iplist) != 4 or iplist[0] != '202' or iplist[1] != '102' or iplist[2] != '39' : # return cpparam if resultcode == '' or resultmsg == '' or cpparam == '' or order_paytype != 'isagSmsPay' or validatecode == '': return TuYouPayAiGameV4.XML_RET % ('1', cpparam) tSign = resultcode + cpparam m = md5() m.update(tSign) vSign = m.hexdigest() if validatecode != vSign: TyContext.ftlog.info( 'doAiGameMsgCallback->ERROR, sign error !! sign=', validatecode, 'vSign=', vSign) return TuYouPayAiGameV4.XML_RET % ('1', cpparam) # 解密得到原始游戏订单号 orderPlatformId = cpparam TyContext.ftlog.info('doAiGameMsgCallback orderPlatformId=', orderPlatformId) notifys['chargeType'] = 'aigame.msg' if resultcode == '00': PayHelperV4.callback_ok(orderPlatformId, -1, notifys) else: PayHelperV4.callback_error(orderPlatformId, 'resultCode(%s) not 0' % resultcode, notifys) return TuYouPayAiGameV4.XML_RET % ('0', cpparam)
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(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 doYdMmCallback(cls, rpath): xmldata = TyContext.RunHttp.get_body_content() TyContext.ftlog.info('TuYouPayYdMmWeak.doYdMmCallback in xmldata=', ''.join(xmldata.splitlines())) orderPlatformId = '' try: xmlroot = ElementTree.fromstring(xmldata) # orderPlatformId = xmlroot.find('OrderId').text orderPlatformId = xmlroot.find( '{http://www.monternet.com/dsmp/schemas/}ExData').text if not orderPlatformId: TyContext.ftlog.info( 'TuYouPayYdMmWeak.doYdMmCallback->ERROR, orderPlatformId error !! xmldata=', xmldata) return TuYouPayYdMmWeakV4.XML_RET % ('1') OrderID = xmlroot.find( '{http://www.monternet.com/dsmp/schemas/}OrderID').text # TradeID = xmlroot.find('{http://www.monternet.com/dsmp/schemas/}TradeID').text # ActionTime = xmlroot.find('{http://www.monternet.com/dsmp/schemas/}ActionTime').text AppID = xmlroot.find( '{http://www.monternet.com/dsmp/schemas/}AppID').text PayCode = xmlroot.find( '{http://www.monternet.com/dsmp/schemas/}PayCode').text ChannelID = xmlroot.find( '{http://www.monternet.com/dsmp/schemas/}ChannelID').text TotalPrice = xmlroot.find( '{http://www.monternet.com/dsmp/schemas/}TotalPrice' ).text # 单位:分 MD5Sign = xmlroot.find( '{http://www.monternet.com/dsmp/schemas/}MD5Sign').text except Exception as e: TyContext.ftlog.info( 'TuYouPayYdMmWeak.doYdMmCallback->xmldata error', e) return TuYouPayYdMmWeakV4.XML_RET % ('1') notifys = { 'xml': xmldata, 'chargeType': 'ydmm', 'pay_appid': AppID, 'third_orderid': OrderID, 'third_prodid': PayCode } ProvinceID = xmlroot.find( '{http://www.monternet.com/dsmp/schemas/}ProvinceID') FeeMSISDN = xmlroot.find( '{http://www.monternet.com/dsmp/schemas/}FeeMSISDN') OrderType = xmlroot.find( '{http://www.monternet.com/dsmp/schemas/}OrderType') ReturnStatus = xmlroot.find( '{http://www.monternet.com/dsmp/schemas/}ReturnStatus') if OrderType is None or OrderType.text == '0': TyContext.ftlog.info('doYdMmCallback->isTestOrder: OrderID', OrderID, 'platformOrder', orderPlatformId, 'OrderType', OrderType.text) notifys['isTestOrder'] = True if FeeMSISDN is not None: notifys['third_userid'] = FeeMSISDN.text if ProvinceID is not None: notifys['third_provid'] = ProvinceID.text if OrderID == '0' * len(OrderID): errorMessage = cls.StatusMessage(ReturnStatus) TyContext.ftlog.info( 'TuYouPayYdMmWeak.doYdMmCallback->ERROR, failed order: OrderID: [%s], message: [%s]', (OrderID, errorMessage)) PayHelperV4.callback_error(orderPlatformId, errorMessage, notifys) # 需要回0,否则ydmm会一直重试 return TuYouPayYdMmWeakV4.XML_RET % ('0') if not cls._check_sign(AppID, OrderID, ChannelID, PayCode, MD5Sign, orderPlatformId): order = PlatformOrder(orderPlatformId) TyContext.ftlog.error( 'doYdMmCallback check sign failed, might be config error: orderid', orderPlatformId, 'userId', order.userid, 'clientId', order.clientid, 'buttonId', order.buttonid, 'AppID', AppID, 'PayCode', PayCode) return TuYouPayYdMmWeakV4.XML_RET % ('1') isOk = PayHelperV4.callback_ok(orderPlatformId, float(TotalPrice) / 100.0, notifys) # 需要回0,否则ydmm会一直重试 return TuYouPayYdMmWeakV4.XML_RET % ('0')
def doIosCallback(cls, rpath): platformOrderId = TyContext.RunHttp.getRequestParam('iosOrderId', '') TyContext.RunMode.get_server_link(platformOrderId) isReturn, params = AccountCheck.normal_check(rpath, True) if isReturn: return params userId = params['userId'] appId = params['appId'] clientId = params['clientId'] appInfo = TyContext.RunHttp.getRequestParam('appInfo', '') isMock = bool(TyContext.RunHttp.getRequestParam('isMock')) receipt = TyContext.RunHttp.getRequestParam('receipt', '') receiptData = {'receiptJsonStr': '{"receipt-data" : "' + receipt + '"}', 'platformOrder': platformOrderId, 'userId': userId} TyContext.ftlog.info('IOS->doIosCallback->userId', userId, 'appId', appId, 'clientId', clientId, 'appInfo', appInfo, 'platformOrderId', platformOrderId, 'receipt', receipt, 'isMock', isMock) rparam = PayHelperV4.getArgsDict() rparam['chargeType'] = 'tuyooios' rparam['userId'] = params['userId'] rparam['appId'] = params['appId'] rparam['clientId'] = params['clientId'] isSandbox = is_sandbox_receipt(receipt) ret = cls.doIosCallbackVerify(receiptData, isSandbox, isMock) TyContext.ftlog.debug('IOS->doIosCallback->doIosCallbackVerify ret=', ret) if ret != 'ok' and ret != 'uuid_prohibit': PayHelperV4.callback_error(platformOrderId, ret, rparam) return ret # 如果是被封禁的uuid,不进行发货处理 if ret == 'uuid_prohibit': return 'success' transaction_id = receiptData['original_transaction_id'] rparam['third_orderid'] = transaction_id rparam['third_prodid'] = receiptData.get('product_id', 'na') rparam['isTestOrder'] = receiptData.get('sandbox', False) if cls._is_ios_transaction_delivered(transaction_id): PayHelperV4.callback_error(platformOrderId, 'error-transaction-already-delivered', rparam) TyContext.ftlog.info('IOS->doIosCallback error-transaction-already-delivered ' 'userId', userId, 'platformOrder', platformOrderId) return 'error-transaction-already-delivered' if not platformOrderId: ret = cls._deliver_missing_order(rparam) if not ret: return 'error-platform-order-missing' else: platformOrderId = ret # 根据商品Id过滤刷单的订单---------------start try: chargeKey = 'sdk.charge:' + platformOrderId chargeInfo = TyContext.RedisPayData.execute('HGET', chargeKey, 'charge') if chargeInfo == None: TyContext.ftlog.info('IOS->doIosCallback error-platformOrderId-not-found ' 'userId', userId, 'platformOrder', platformOrderId) return 'error-platform-order-missing' chargeInfo = TyContext.strutil.loads(chargeInfo, decodeutf8=True) if 'chargeData' in chargeInfo and 'orderIosCode' in chargeInfo['chargeData'] and chargeInfo['chargeData'][ 'orderIosCode'] != rparam['third_prodid']: TyContext.ftlog.info('IOS->doIosCallback error-product_id ' 'userId', userId, 'platformOrder', platformOrderId, 'orderIosCode', chargeInfo['chargeData']['orderIosCode'], 'receipt_product_id', rparam['third_prodid']) return 'error-product_id' except: pass product = cls.get_pay_ios_product(appId, rparam['third_prodid'], clientId, 'iosid') if not product: TyContext.ftlog.error('get_pay_ios_product products not found!' ' appId=', appId, 'iosId=', rparam['third_prodid'], 'clientId=', clientId, 'checkIdKey=iosid') return 'error-product_id' # 根据商品Id过滤刷单的订单---------------end isOk = PayHelperV4.callback_ok(platformOrderId, -1, rparam) if isOk: cls._mark_ios_transaction_as_delivered(transaction_id) try: # 328 & 628 第一次购买后只能使用微信支付 ios_control = TyContext.Configure.get_global_item_json('ios_weinxin_pay_control', {}) if product['tyid'] in ios_control.get('weixin_products', []): wxpay_count = TyContext.RedisUser.execute(userId, 'HGET', 'user:'******'wxpay_flag') if not wxpay_count: wxpay_count = 0 TyContext.RedisUser.execute(userId, 'HSET', 'user:'******'wxpay_flag', int(wxpay_count) + 1) except: TyContext.ftlog.exception() return 'success' else: return 'error-handle-callback'
def _do_all_callback(self, appkey, notifys): method = notifys.get('method', '') cp_order_id = notifys.get('cp_order_id', '') correlator = notifys.get('correlator', '') order_time = notifys.get('order_time', '') sign = notifys.get('sign', '') if method == 'check': # 订单效验接口 game_account = '' game_fee = '' ct = datetime.datetime.now() order_current_time = ct.strftime('%Y%m%d%H%M%S') if cp_order_id == '' or sign == '': return TuYouPayAiGameV4.XML_CHECK_RET % ( cp_order_id, correlator, game_account, game_fee, '1', order_current_time) orderPlatformId = cp_order_id appInfo = self._get_order_info(orderPlatformId) if 'uid' in appInfo and appInfo['uid'] is not None: game_account = appInfo['uid'] if 'orderPrice' in appInfo and appInfo['orderPrice'] is not None: game_fee = appInfo['orderPrice'] tSign = cp_order_id + str(correlator) + str( order_time) + method + appkey m = md5() m.update(tSign) vSign = m.hexdigest() if sign != vSign: TyContext.ftlog.info( 'TuYouPayAiGame._do_all_callback->ERROR, sign error !! sign=', sign, 'vSign=', vSign) return TuYouPayAiGameV4.XML_CHECK_RET % ( cp_order_id, correlator, game_account, game_fee, '1', order_current_time) return TuYouPayAiGameV4.XML_CHECK_RET % (cp_order_id, correlator, game_account, game_fee, '0', order_current_time) elif method == 'callback': # 成功回调接口 result_code = notifys.get('result_code', '') fee = notifys.get('fee', '-1') # 单位:元 try: fee = float(fee) except: TyContext.ftlog.error( 'TuYouPayAiGame._do_all_callback->ERROR, fee format error !! fee=', fee) fee = -1 pay_type = notifys.get('pay_type', 'na') ct = datetime.datetime.now() order_current_time = ct.strftime('%Y%m%d%H%M%S') if cp_order_id == '' or sign == '' or method != 'callback': return TuYouPayAiGameV4.XML_RET % ('1', cp_order_id) orderPlatformId = cp_order_id if appkey: tSign = cp_order_id + str(correlator) + str(result_code) + str( int(fee)) + pay_type + method + appkey m = md5() m.update(tSign) vSign = m.hexdigest() if sign != vSign: TyContext.ftlog.info( 'TuYouPayAiGame._do_all_callback->ERROR,' ' sign error !! sign=', sign, 'vSign=', vSign) return TuYouPayAiGameV4.XML_RET % ('1', cp_order_id) notifys['chargeType'] = 'aigame' notifys['sub_paytype'] = pay_type notifys['third_orderid'] = correlator notifys['pay_appid'] = notifys.get('game_code', 'na') if str(result_code) == '00': isOk = PayHelperV4.callback_ok(orderPlatformId, -1, notifys) if not isOk: TyContext.ftlog.error( 'TuYouPayAiGame._do_all_callback->callback failed', 'order', orderPlatformId) retXml = TuYouPayAiGameV4.XML_RET % ('0', cp_order_id) else: errinfo = TuYouPayAiGameV4.resultcode_msg.get( result_code, 'result_code(%s) is not 00' % result_code) TyContext.ftlog.error('TuYouPayAiGame._do_all_callback error', errinfo, 'for order', orderPlatformId) PayHelperV4.callback_error(orderPlatformId, errinfo, notifys) retXml = TuYouPayAiGameV4.XML_RET % ('0', cp_order_id) return retXml