Пример #1
0
    def _docallback(cls, appkey, paykey):
        rparam = TyContext.RunHttp.convertArgsToDict()
        TyContext.ftlog.debug('TuYouPayXYZS->_docallback rparam is : ', rparam)

        # 验签
        safeSign = cls._gen_safe_sign(rparam, appkey)
        if safeSign != rparam['sign']:
            TyContext.ftlog.error(
                'TuYouPayXYZS->_docallback sign verify failed, '
                'sign is [', safeSign, '],  rparam["sign"] is [',
                rparam['sign'], ']')
            return cls._response_result(6)
        if rparam['sig']:
            safeSign = cls._gen_safe_sign(rparam, paykey)
            if safeSign != rparam['sig']:
                TyContext.ftlog.error(
                    'TuYouPayXYZS->_docallback sign verify failed.'
                    'sig is [', safeSign, '],  rparam["sig"] is [',
                    rparam['sig'], ']')
                return cls._response_result(6)

        # 开始发货
        orderPlatformId = rparam["extra"]
        total_fee = float(rparam["amount"])
        PayHelperV4.callback_ok(orderPlatformId, total_fee, rparam)
        TyContext.ftlog.debug(
            'TuYouPayXYZS->_docallback deliver goods successed.')

        return cls._response_result(0)
Пример #2
0
    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'
Пример #3
0
    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)
Пример #4
0
 def handle_alifree_order_callback(self, rpath):
     rparams = TyContext.RunHttp.convertArgsToDict()
     sign = rparams['sign']
     # 签名校验
     if not self.verifySignMD5(sign, rparams):
         TyContext.ftlog.error('TuyouPayTuyou.doAliCallback md5 verify error !!')
         return 'error'
     trade_status = rparams['trade_status']
     if trade_status != 'TRADE_SUCCESS' and trade_status != 'TRADE_FINISHED':
         return 'success'
     buyer_id = rparams.get('buyer_id')
     platformOrderId = rparams['out_trade_no']
     chargeInfo = None
     if buyer_id:
         chargeKey = 'sdk.charge:' + platformOrderId
         chargeInfo = TyContext.RedisPayData.execute('HGET', chargeKey, 'charge')
         if chargeInfo:
             chargeInfo = TyContext.strutil.loads(chargeInfo, decodeutf8=True)
             userId = int(chargeInfo['userId'])
             TyContext.RedisUser.execute(userId, 'HMSET', 'user:%s' % userId,
                                         'alipay_sign_flag', 1,
                                         'alipay_user_id', buyer_id)
     try:
         AlipayHuiyuan(9999, userId).handle_order(chargeInfo)
     except:
         TyContext.ftlog.exception()
     isOK = PayHelperV4.callback_ok(platformOrderId, -1, rparams)
     if isOK:
         return 'success'
     else:
         return 'error'
Пример #5
0
    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')
Пример #6
0
    def doWXpayCallback(self, rpath):
        xmldata = TyContext.RunHttp.get_body_content()
        TyContext.ftlog.info('TuyouPayWXpay.doWXpayCallback in xmldata=',
                             xmldata)
        xmlroot = ElementTree.fromstring(xmldata)
        wxappId = xmlroot.find('appid').text
        openId = xmlroot.find('openid').text

        rparam = {}
        for node in xmlroot.iter():
            if 'xml' != node.tag:
                rparam[node.tag] = node.text
        TyContext.ftlog.debug('TuyouPayWXpay.doWXpayCallback in rparam=',
                              rparam)

        responseXml = ElementTree.Element('xml')
        returnCode = ElementTree.SubElement(responseXml, 'return_code')
        returnMsg = ElementTree.SubElement(responseXml, 'return_msg')

        try:
            orderPlatformId = rparam['out_trade_no']
            total_fee = float(rparam['total_fee']) / 100
            wxconfig = TyContext.Configure.get_global_item_json(
                'wx_config', {})
            config = wxconfig.get(str(wxappId), None)
            if not config:
                appConfig = GameItemConfigure.get_game_channel_configure_by_orderId(
                    orderPlatformId, 'weixin')
            wxpartnerKey = str(config['partnerKey'])
            sign = rparam['sign']
        except:
            TyContext.ftlog.info(
                'doWXpayCallback->ERROR, param error !! rparam=', rparam)
            returnCode.text = 'FAIL'
            returnMsg.text = '参数格式校验错误'
            responseStr = ElementTree.tostring(responseXml)
            return responseStr

        # 签名校验
        if not self.__verify_sign(rparam, wxpartnerKey, sign):
            TyContext.ftlog.error(
                'TuyouPayWXpay.doWXpayCallback verify error !!')
            returnCode.text = 'FAIL'
            returnMsg.text = '签名失败'
            responseStr = ElementTree.tostring(responseXml)
            return responseStr

        rparam['third_orderid'] = openId
        rparam['chargeType'] = 'wxpay'
        isOk = PayHelperV4.callback_ok(orderPlatformId, total_fee, rparam)
        if isOk:
            returnCode.text = 'SUCCESS'
            returnMsg.text = 'OK'
        else:
            returnCode.text = 'FAIL'
            returnMsg.text = '发货失败'

        responseStr = ElementTree.tostring(responseXml)
        return responseStr
Пример #7
0
    def doAiGameCallback(self, rpath):
        notifys = TyContext.RunHttp.convertArgsToDict()
        serialno = notifys.get('serialno', '')
        resultcode = notifys.get('resultCode', '')
        resultmsg = notifys.get('resultMsg', '')
        gameUserId = notifys.get('gameUserId', '')
        order_paytype = notifys.get('payType', '')
        validatecode = notifys.get('validatecode', '')

        # 限制ip请求
        # clientIp = TyContext.RunHttp.get_client_ip()
        # TyContext.ftlog.info('TuYouPayAiGame.doAiGameCallback in clientIp=', clientIp)
        # iplist = clientIp.split('.')
        # if len(iplist) != 4 or iplist[0] != '202' or iplist[1] != '102' or iplist[2] != '39' :
        #    return serialno

        if serialno == '' or resultcode == '' or resultmsg == '' or gameUserId == '' or order_paytype == '' or validatecode == '':
            return serialno

        tSign = serialno + gameUserId
        m = md5()
        m.update(tSign)
        vSign = m.hexdigest()
        if validatecode != vSign:
            TyContext.ftlog.info(
                'TuYouPayAiGame.doAiGameCallback->ERROR, sign error !! sign=',
                validatecode, 'vSign=', vSign)
            return serialno

        # 解密得到原始游戏订单号
        orderPlatformId = gameUserId

        TyContext.ftlog.info(
            'TuYouPayAiGame.doAiGameCallback orderPlatformId=',
            orderPlatformId)
        if resultcode == '120':
            #             if int(gameGold) == 0:
            #                 total_fee = -1
            #             else:
            #                 total_fee = int(gameGold)

            notifys['chargeType'] = 'aigame'
            PayHelperV4.callback_ok(orderPlatformId, -1, notifys)

        return serialno
Пример #8
0
 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'
Пример #9
0
    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'
Пример #10
0
 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'
Пример #11
0
 def doCallback(cls, rpath):
     rparams = TyContext.RunHttp.convertArgsToDict()
     platformOrderId = rparams['Extra']
     TyContext.ftlog.debug('TuYouPayZhuoyi->doCallback, rparams=', rparams)
     if not cls.check_sign(rparams):
         TyContext.ftlog.error(
             'TuYouPayZhuoyi->ERROR, sign error !! rparam=', rparams)
         return 'failure'
     # do charge
     isOk = PayHelperV4.callback_ok(platformOrderId, -1, rparams)
     if isOk:
         return 'success'
     else:
         return 'failure'
Пример #12
0
    def doMomoCallback(cls, rpath):
        params = TyContext.RunHttp.convertArgsToDict()
        clientIp = TyContext.RunHttp.get_client_ip()
        if clientIp != '101.201.110.179':
            print 'clientId diffrent,please check!', clientIp
        orderstate = params.get('orderstate', '')
        if str(orderstate) != '1':
            return 'error'
        orderId = params.get('orderid')
        chargeInfo = cls.get_charge_info_data(orderId)
        user_id = chargeInfo.get('userId', '')
        feevalue = params.get('feevalue', '')
        status = params.get('status', '')
        if str(status) == '-99':
            # 订购
            TyContext.RedisUser.execute(user_id, 'HMSET', 'user:'******'isYouyifuVipUser', '1', 'youyifuVipMsg',
                                        message, 'bugYouyifuVipAppid', appId, 'bugYouyifuVipClientid', clientId)

            # 这个参数用来告诉游戏服务器,这个商品是一件优易付的会员包月商品
            params['isYouyifuMonthVip'] = '1'
            PayHelperV4.callback_ok(orderId, feevalue, params)
            cls.reportBi(Order.SUBSCRIBE, params, orderId)

        elif str(status) == '-100':
            # 退订
            status = cls._NotifyGameServerUnsubscribe(orderId, 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, params, orderId)
Пример #13
0
 def doCallback(cls, rpath):
     # convertArgsToDict
     rparams = TyContext.RunHttp.convertArgsToDict()
     transdata = rparams['transdata']
     transdata = json.loads(transdata)
     platformOrderId = transdata['cporderid']
     TyContext.ftlog.debug('TuYouPayChangba->doCallback,rparams=', rparams)
     if not cls.verify_sign(rparams):
         return 'failure'
     # do charge
     isOk = PayHelperV4.callback_ok(platformOrderId, -1, rparams)
     if isOk:
         return 'success'
     else:
         return 'failure'
Пример #14
0
 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'
Пример #15
0
 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'
Пример #16
0
 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'
Пример #17
0
 def doUnionPayCallback(self, rpath):
     """
     银联v4版本支付回调
     :param rpath:
     :return:
     """
     params = TyContext.RunHttp.convertArgsToDict()
     TyContext.ftlog.debug('TuYouPayUnionPayV4 in prams=', '%s' % params)
     if not self.validateSign(**params):
         return 'sign-error'
     orderId = params['orderId']
     isOk = PayHelperV4.callback_ok(orderId, -1, params)
     if isOk:
         return 'ok'
     else:
         return 'error'
Пример #18
0
 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'
Пример #19
0
    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'
Пример #20
0
    def doCallback(self, rpath):
        rparams = TyContext.RunHttp.convertArgsToDict()
        TyContext.ftlog.debug('TuYouPayYiwanV4->doCallback, rparams=', rparams)
        order_id = rparams['custominfo']
        charge_key = 'sdk.charge:yiwan:%s' % order_id
        app_id = TyContext.RedisPayData.execute('HGET', charge_key, 'appId')
        if not self._check_sign(rparams, app_id):
            TyContext.ftlog.error('TuYouPayYiwanV4 check sign error')
            return '100'

        status = rparams['status']
        if 1 != int(status):
            return '100'

        is_ok = PayHelperV4.callback_ok(order_id, -1, rparams)
        if is_ok:
            return '1'
        else:
            return '103'
Пример #21
0
 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'
Пример #22
0
 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'
Пример #23
0
    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
Пример #24
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'
Пример #25
0
    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')