示例#1
0
    def get_order_info(self, mi):
        chargeinfo = self.get_charge_info(mi)
        if self.is_out_pay_limit(chargeinfo):
            config = TyContext.Configure.get_global_item_json('smspay_strategy')
            tips = config.get('out_limit_tips', '暂时无法支付,请稍后重试!')
            raise PayErrorV4(1, tips)
        chargetype = chargeinfo['chargeType']
        clientId = chargeinfo['clientId']
        paycodes = TyContext.Configure.get_global_item_json('paycodes',
                                                            clientid=clientId)
        clientip = TyContext.UserSession.get_session_client_ip(chargeinfo['userId'])
        from tysdk.entity.pay_common.fengkong import Fengkong
        if Fengkong.is_ip_limited(clientip, clientId, 'liantong.wo'):
            raise PayErrorV4(
                1, '对不起,您已超出支付限制,请联系客服4008-098-000')
        buttonId = chargeinfo['buttonId']
        try:
            pdata = paycodes[chargetype]['paydata']
        except Exception as e:
            TyContext.ftlog.error('paycodes', paycodes, 'config error for',
                                  clientId, 'buttonId', buttonId)
            raise PayErrorV4(-1, "找不到%s的联通计费点配置!" % buttonId)

        chargeData = filter(lambda x: x['prodid'] == buttonId, pdata)
        if not chargeData:
            raise PayErrorV4(-1, "找不到%s的联通计费点配置!" % buttonId)
        return self.return_mo(0, chargeInfo=chargeinfo, payData=chargeData[0])
示例#2
0
 def charge_data(cls, mi):
     chargedata = {}
     chargeinfo = cls.get_charge_info(mi)
     mz_appId = mi.getParamStr('mz_appId')
     if not mz_appId:
         raise PayErrorV4(1, '【魅族】mz_appId没有找到!')
     chargedata['app_id'] = mz_appId
     chargedata['cp_order_id'] = chargeinfo['platformOrderId']
     mz_uid = mi.getParamStr('mz_uid')
     if not mz_uid:
         raise PayErrorV4(1, '【魅族】没有找到mz_uid参数!')
     chargedata['uid'] = mi.getParamStr('mz_uid')
     chargedata['product_id'] = chargeinfo['buttonId']
     chargedata['product_subject'] = chargeinfo['diamondName']
     chargedata['product_body'] = chargeinfo['diamondName']
     chargedata['product_unit'] = ''
     chargedata['buy_amount'] = chargeinfo['diamondCount']
     chargedata['product_per_price'] = chargeinfo['diamondPrice']
     chargedata['total_price'] = chargeinfo['chargeTotal']
     chargedata['create_time'] = int(time.time())
     chargedata['pay_type'] = '0'
     chargedata['user_info'] = chargeinfo['clientId']
     chargedata['sign_type'] = 'md5'
     sign = cls._calc_sign(chargedata)
     chargedata['sign'] = sign
     chargeinfo['chargeData'] = chargedata
     TyContext.ftlog.info('TuYouPayMeizu charge_data chargeinfo ',
                          chargeinfo)
     return cls.return_mo(0, chargeInfo=chargeinfo)
示例#3
0
 def charge_data(self, mi):
     chargeinfo = self.get_charge_info(mi)
     if self.is_out_pay_limit(chargeinfo):
         config = TyContext.Configure.get_global_item_json(
             'smspay_strategy')
         tips = config.get('out_limit_tips', '暂时无法支付,请稍后重试!')
         raise PayErrorV4(1, tips)
     appId = chargeinfo['appId']
     buttonId = chargeinfo['buttonId']
     clientId = chargeinfo['clientId']
     userId = chargeinfo['uid']
     clientip = TyContext.UserSession.get_session_client_ip(userId)
     from tysdk.entity.pay_common.fengkong import Fengkong
     if Fengkong.is_ip_limited(clientip, clientId, 'ydjd'):
         raise PayErrorV4(1, '对不起,您已超出支付限制,请联系客服4008-098-000')
     paycodes = TyContext.Configure.get_global_item_json('paycodes',
                                                         clientid=clientId)
     paydata = {}
     if paycodes:
         paydata = filter(lambda x: x['prodid'] == buttonId,
                          paycodes['ydjd']['paydata'])
     paycodes = TyContext.Configure.get_global_item_json(
         'ydjd_paycodes', paycode_dict)
     if not paydata:
         paycode = paycodes.get(str(appId), {})
         if buttonId in paycode.keys():
             paydata = {'msgOrderCode': paycode[buttonId]}
         else:
             raise PayErrorV4(-1, "基地%spaycodes参数错误" % buttonId)
     else:
         paydata = paydata[0]
     if not paydata:
         raise PayErrorV4(-1, "基地%spaycodes没找到啊" % buttonId)
     return self.return_mo(0, chargeInfo=chargeinfo, payData=paydata)
示例#4
0
    def _pay_request(cls, chargeInfo, mi, mo, bankIndex):

        rparam = cls._get_pay_requset_params(chargeInfo, mi, mo, bankIndex)
        if not rparam:
            return PayConst.CHARGE_STATE_REQUEST_RETRY

        purl = cls.pay_request_url + PayHelperV4.createLinkString4Get(rparam)

        TyContext.ftlog.info(cls.__name__, '_pay_request->return bankIndex=', bankIndex, 'purl=', purl)
        response, purl = TyContext.WebPage.webget(purl)
        TyContext.ftlog.info(cls.__name__, '_pay_request->return bankIndex=', bankIndex, 'purl=', purl, 'response=',
                             response)

        if response == None:
            response = ''
        else:
            response = response.strip()

        mo.setResult('payData', '')
        if response[0:7] == 'success':
            return PayConst.CHARGE_STATE_REQUEST
        elif response[0] == '{':
            try:
                jsondatas = json.loads(response)
                if jsondatas['code'] == 'success':
                    mo.setResult('payData', jsondatas['paydata'])
                else:
                    if 'info' in jsondatas:
                        errInfo = jsondatas['info']
                        mo.setResult('info', jsondatas['info'])
                    else:
                        errInfo = '360充值请求错误'
                        raise PayErrorV4(1, errInfo)
                    mo.setError(1, errInfo)
                return PayConst.CHARGE_STATE_REQUEST
            except:
                pass

        i = response.find('<h2>[')
        if i > 0:
            j = response.find('</h2>', i)
            errInfo = response[i + 4: j]
            errInfo = errInfo.decode('gb2312')
            mo.setError(1, errInfo)
            return PayConst.CHARGE_STATE_REQUEST_IGNORE
        else:
            try:
                errInfo = response.decode('gb2312')
            except:
                errInfo = response
            if errInfo.find('failed:') == 0:
                errInfo = errInfo[7:]
                raise PayErrorV4(1, errInfo)
            mo.setError(1, errInfo)
            return PayConst.CHARGE_STATE_ERROR_REQUEST
示例#5
0
    def charge_data(self, mi):
        chargeinfo = self.get_charge_info(mi)
        orderPlatformId = chargeinfo['platformOrderId']
        vivo_appId = mi.getParamStr('vivo_appId')
        appinfoconfig = TyContext.Configure.get_global_item_json('vivo_appkeys', {})
        appdata = appinfoconfig.get(str(vivo_appId), None)
        if not appdata:
            config = GameItemConfigure(chargeinfo['appId']).get_game_channel_configure_by_package('vivo', chargeinfo[
                'packageName'],
                                                                                                  chargeinfo[
                                                                                                      'mainChannel'])
            appdata = {
                'cpid': config.get('vivo_cpid'),
                'appid': config.get('vivo_appId'),
                'cpkey': config.get('vivo_cpkey'),
            }
        cpkey = appdata['cpkey']

        url = 'https://pay.vivo.com.cn/vcoin/trade'
        params = {
            'version': '1.0.0',
            # 'signature': '',
            'cpId': appdata['cpid'],
            'appId': appdata['appid'],
            'cpOrderNumber': orderPlatformId,
            'notifyUrl': PayHelperV4.getSdkDomain() + '/v1/pay/vivounion/callback',
            'orderTime': datetime.datetime.now().strftime('%Y%m%d%H%M%S'),
            'orderAmount': int(float(chargeinfo['chargeTotal']) * 100),
            'orderTitle': chargeinfo['buttonName'],
            'orderDesc': chargeinfo['buttonName'],
            'extInfo': orderPlatformId
        }

        sign = self.__cal_sign(params, cpkey)
        params['signature'] = sign
        params['signMethod'] = 'MD5'
        response, _ = TyContext.WebPage.webget(url, params)

        TyContext.ftlog.debug('TuYouPayVivounionV4 -> trade response ->', response)

        try:
            datas = json.loads(response)
            if int(datas['respCode']) != 200:
                raise PayErrorV4(1, 'TuYouPayVivo charge_data->order push url response ERROR, rspmsg=',
                                 datas['respMsg'])
            if not self.__verify_sign(datas, cpkey, datas['signature']):
                raise PayErrorV4(1, 'vivo 验签失败!')
            chargeinfo['chargeData'] = {'vivoOrder': datas['orderNumber'],
                                        'vivoSignature': datas['accessKey']}
            return self.return_mo(0, chargeInfo=chargeinfo)
        except:
            raise PayErrorV4(1, 'TuYouPayVivo charge_data->order push url return ERROR, response=', response)
示例#6
0
    def charge_data(self, mi):
        chargeinfo = self.get_charge_info(mi)
        appid = mi.getParamStr('iappay_appid', None)
        if not appid:
            raise PayErrorV4(1, "爱贝支付ID不存在")
        iappayConfig = TyContext.Configure.get_global_item_json(
            'iappay_config', {})
        appKey = iappayConfig.get(appid)['appkey'] if iappayConfig.get(
            appid) else ""
        if not appKey:
            chargeType = chargeinfo['chargeType']
            sdk = chargeType.split('.')[0]
            config = GameItemConfigure(
                chargeinfo['appId']).get_game_channel_configure_by_package(
                    sdk, chargeinfo['packageName'], chargeinfo['mainChannel'])

            prodConfig = config.get('products', {})
            diamondList = filter(
                lambda x: chargeinfo['diamondId'] in x.values(), prodConfig)
            diamondConfig = diamondList[0] if diamondList else {}
            if not diamondConfig:
                raise PayErrorV4(1, '【爱贝】没有对应的计费点代码!')
            chargeinfo['chargeData'] = {
                'waresid': diamondConfig.get("feecode"),
                'appKey': config.get('iappay_appKey')
            }
            return self.return_mo(0, chargeInfo=chargeinfo)
        try:
            # if 'prodId' in chargeinfo:
            #    waresid = iappayConfig[appid]['payConfig'][chargeinfo['prodId']]
            # if 'buttonId' in chargeinfo:
            #     waresid = iappayConfig[appid]['payConfig'][chargeinfo['buttonId']]
            # elif 'diamondId' in chargeinfo:
            waresid = iappayConfig[appid]['payConfig'][chargeinfo['diamondId']]
            # else:
            #    waresid = None
        except:
            waresid = None
        if not waresid:
            raise PayErrorV4(1, '【爱贝】没有对应的计费点代码!')
        if not appKey:
            TyContext.ftlog.error('TuYooIappay this id has no key , id ',
                                  appid)
            raise PayErrorV4(1, '爱贝ID [%s] 没有找到对应的参数' % appid)
        if not waresid:
            TyContext.ftlog.error(
                'TuYooIappay this prodId has no waresid , chargeinfo ',
                chargeinfo)
        chargeinfo['chargeData'] = {'waresid': waresid, 'appKey': appKey}
        return self.return_mo(0, chargeInfo=chargeinfo)
示例#7
0
 def check_charge_info(self, mi, chargeInfo):
     appId = chargeInfo['appId']
     clientId = chargeInfo['clientId']
     diamondId = chargeInfo['diamondId']
     # prodPrice = chargeInfo['diamondPrice']
     prodCount = chargeInfo['diamondCount']
     mustcharge = int(chargeInfo.get('mustcharge', 0))
     diamondlist = TuyouPayDiamondList.diamondlist2(appId, clientId)
     prodInfo = ChargeConfigure.get_prod_info(appId,
                                              diamondId,
                                              clientId=clientId)
     # 非钻石商品需要先购买钻石
     if not prodInfo.get('is_diamond', 0):
         # 消耗的钻石数量
         consumeCoin = int(prodInfo['diamondPrice'] * prodCount)
         if not diamondlist:
             TyContext.ftlog.error('__consume_charge__ diamondlist ERROR',
                                   appId, clientId)
             raise PayErrorV4(6, '钻石列表配置错误')
             return True
         ios_patch = TyContext.Configure.get_global_item_int(
             'patch_ios_bug_TY9999R0003001', 1)
         if ios_patch:
             diamondlist = TuyouPayConsume._patch_ios_client_bug(
                 clientId, diamondlist)
         for diamond in diamondlist:
             count = diamond['count']
             if count >= consumeCoin:
                 break
         else:
             TyContext.ftlog.error(
                 '__consume_charge__ find charge diamond ERROR', appId,
                 clientId, consumeCoin, diamondlist)
             raise PayErrorV4(7, '钻石项目取得失败')
         chargeInfo['diamondId'] = diamond['id']
         chargeInfo['diamondPrice'] = diamond['price']
         chargeInfo[
             'chargeTotal'] = diamond['price'] * chargeInfo['diamondCount']
         if mustcharge or True:
             chargeInfo['diamondName'] = diamond['name']
             chargeInfo['buttonId'] = chargeInfo['diamondId']
             chargeInfo['buttonName'] = chargeInfo['diamondName']
     try:
         self.get_charge_data(chargeInfo)
     except TyContext.FreetimeException as e:
         TyContext.ftlog.error('_charge_begin_w_new_categories exception',
                               e)
         # mo.setError(e.errorCode, e.message)
         # return mo
         raise (e.errorCode, e.message)
示例#8
0
    def charge_data(cls, mi):

        chargeinfo = cls.get_charge_info(mi)

        packageName = chargeinfo['packageName']

        appId = chargeinfo['appId']
        buttonId = chargeinfo['diamondId']
        clientId = chargeinfo['clientId']
        # 先取多appId对应的支付配置
        payData = None
        duokuAppId = mi.getParamStr('dksdk_appid', "")
        config = GameItemConfigure(appId).get_game_channel_configure_by_primarykey('duoku', 'dksdk_appid', duokuAppId,
                                                                                   chargeinfo['mainChannel'])
        if config:
            prodconfig = config.get('products', {})
            diamondList = filter(lambda x: buttonId in x.values(), prodconfig)
            payData = diamondList[0] if diamondList else {}
            if payData:
                orderPlatformId = chargeinfo['platformOrderId']
                shortOrderPlatformId = ShortOrderIdMap.get_short_order_id(orderPlatformId)
                payData['orderPlatformId'] = shortOrderPlatformId
                chargeinfo['chargeData'] = payData
                return cls.return_mo(0, chargeInfo=chargeinfo)
        prodconfig = TyContext.Configure.get_global_item_json('duoku_prodids')
        if duokuAppId:
            config = prodconfig.get(duokuAppId, None)
            if config:
                payData = config.get(buttonId, None)
        if not payData:
            if packageName:
                try:
                    appconfig = prodconfig[packageName]
                    payData = appconfig[buttonId]
                except:
                    TyContext.ftlog.exception()
                    raise PayErrorV4(1, '【百度】找不到这个商品[%s]配置!' % buttonId)
            else:
                try:
                    appconfig = prodconfig[str(appId)]
                    payData = appconfig[buttonId]
                except Exception as e:
                    TyContext.ftlog.exception()
                    raise PayErrorV4(1, '【百度】找不到这个商品[%s]配置!' % buttonId)
        orderPlatformId = chargeinfo['platformOrderId']
        shortOrderPlatformId = ShortOrderIdMap.get_short_order_id(orderPlatformId)
        payData['orderPlatformId'] = shortOrderPlatformId
        chargeinfo['chargeData'] = payData
        return cls.return_mo(0, chargeInfo=chargeinfo)
示例#9
0
    def charge_data(self, mi):
        chargeinfo = self.get_charge_info(mi)
        appId = mi.getParamStr('lenovodj_openId', None)
        if not appId:
            raise PayErrorV4(1, '请检查一下是否有联想单机的openId')

        diamondId = chargeinfo['buttonId']
        prodconfig = TyContext.Configure.get_global_item_json(
            'lenovodanji_prodids', {})
        data = None
        payCode = None
        bgname = None
        try:
            data = prodconfig[str(appId)].get(str(diamondId), None)
        except Exception as e:
            TyContext.ftlog.info('doLenovoDanji old app requested!, ', e)
        appKey = ''
        appConfig = TyContext.Configure.get_global_item_json(
            'lenovodanji_config', {})
        for item in appConfig:
            if 0 == cmp(str(appId), item['appId']):
                appKey = item['appKey']
                break
        else:
            TyContext.ftlog.error(
                'TuYouPayLenovoDanji->doLenovoDanjiCallback Doesn\'t find appkey by appid:',
                appId)
            # raise PayErrorV4(1,'【联想单机】openId[%s]对应的参数没有找到!' % appId)

        # 前端不要private key开头和结尾的字符
        appKey = appKey.replace('-----BEGIN PRIVATE KEY-----\n',
                                '').replace('\n-----END PRIVATE KEY-----', '')
        if data:
            payCode = data['feecode']
        if not payCode or not appKey:
            config = GameItemConfigure(
                chargeinfo['appId']).get_game_channel_configure_by_package(
                    'lenovodj', chargeinfo['packageName'],
                    chargeinfo['mainChannel'])
            prodconfig = config.get('products', {})
            diamondList = filter(lambda x: diamondId in x.values(), prodconfig)
            diamondConfig = diamondList[0] if diamondList else {}
            payCode = diamondConfig.get('code', '')
            appKey = config.get('lenovo_appKey', '')
            if not payCode or not appKey:
                raise PayErrorV4(1, '【联想单机】没有找到计费点!')
        chargeinfo['chargeData'] = {'msgOrderCode': payCode, 'appKey': appKey}
        return self.return_mo(0, chargeInfo=chargeinfo)
示例#10
0
 def charge_data(cls, mi):
     chargeinfo = cls.get_charge_info(mi)
     appId = chargeinfo['appId']
     diamondId = chargeinfo['buttonId']
     prodconfig = TyContext.Configure.get_global_item_json(
         'momo_prodids', {})
     data = prodconfig['6'].get(str(diamondId), None)
     if data:
         payCode = data['feecode']
     else:
         config = GameItemConfigure(
             chargeinfo['appId']).get_game_channel_configure_by_package(
                 'momo', chargeinfo['packageName'],
                 chargeinfo['mainChannel'])
         if not config:
             package = 'com.wemomo.game.ddz'
             channel = 'momo'
             config = GameItemConfigure(
                 chargeinfo['appId']).get_game_channel_configure_by_package(
                     'momo', package, channel)
         products = config.get('products', {})
         productConfig = filter(
             lambda x: x['diamondId'].strip() == diamondId, products)
         payCode = productConfig[0].get(
             'feecode', '') if len(productConfig) > 0 else ''
         if not payCode:
             raise PayErrorV4(
                 1, 'can not find momo product define of diamondId=' +
                 diamondId)
     chargeinfo['chargeData'] = {'msgOrderCode': payCode}
     return cls.return_mo(0, chargeInfo=chargeinfo)
示例#11
0
 def charge_data(cls, mi):
     chargeinfo = cls.get_charge_info(mi)
     chargeinfo['chargeData'] = {
         'platformOrderId': chargeinfo['platformOrderId'],
     }
     mumayi_keys = TyContext.Configure.get_global_item_json(
         'mumayi_keys', {})
     packageName = chargeinfo['packageName']
     try:
         appKey = mumayi_keys[packageName]
     except:
         config = GameItemConfigure(
             chargeinfo['appId']).get_game_channel_configure_by_package(
                 'mumayi', chargeinfo['packageName'],
                 chargeinfo['mainChannel'])
         appKey = config.get('mumayi_appKey', "")
         if not appKey:
             raise PayErrorV4(1, "找不到木螞蟻的配置")
     userId = chargeinfo['uid']
     chargeKey = 'sdk.charge:mumayi:%s' % userId
     TyContext.RedisPayData.execute('HMSET', chargeKey, 'platformOrderId',
                                    chargeinfo['platformOrderId'], 'appKey',
                                    appKey)
     TyContext.RedisPayData.execute('EXPIRE', chargeKey, 60 * 60)
     return cls.return_mo(0, chargeInfo=chargeinfo)
示例#12
0
 def charge_data(cls, mi):
     chargeinfo = cls.get_charge_info(mi)
     zhuoyi_keys = TyContext.Configure.get_global_item_json(
         'zhuoyi_keys', {})
     buttonId = chargeinfo['buttonId']
     buttonName = chargeinfo['buttonName']
     packageName = chargeinfo['packageName']
     try:
         payInfo = zhuoyi_keys[packageName]
         codes = payInfo['codes']
         code = codes.get(buttonId, codes.get(buttonName))
     except:
         config = GameItemConfigure(
             chargeinfo['appId']).get_game_channel_configure_by_package(
                 'zhuoyi', packageName, chargeinfo['mainChannel'])
         prodConfig = config.get('products', {})
         diamondList = filter(lambda x: buttonId in x.values(), prodConfig)
         diamondConfig = diamondList[0] if diamondList else {}
         if not diamondConfig:
             raise PayErrorV4(1, "找不到商品%s的计费点配置" % buttonId)
         code = diamondConfig.get('code', '')
         payInfo = {
             'appId': config.get('zhuoyi_appId', ''),
             'appKey': config.get('zhuoyi_appKey', '')
         }
     chargeinfo['chargeData'] = {
         'platformOrderId': chargeinfo['platformOrderId'],
         'appId': payInfo['appId'],
         'appKey': payInfo['appKey'],
         'code': code
     }
     return cls.return_mo(0, chargeInfo=chargeinfo)
示例#13
0
 def handle_weixinjs(self, mi):
     chargeInfo = self.get_charge_info(mi)
     # 必须采用途游棋牌的wxappId
     wxappId = 'wxb01a635a437adb75'  # mi.getParamStr('wxappId')
     openid = mi.getParamStr('openid', None)
     tradeType = mi.getParamStr('tradeType', 'WAP')
     wxconfig = TyContext.Configure.get_global_item_json('wx_config', {})
     config = wxconfig.get(str(wxappId), None)
     if config:
         wxappId = str(config['appId'])
         wxpaySignKey = str(config['paySignKey'])
         wxappSecret = str(config['appSecret'])
         wxpartnerId = str(config['partnerId'])
         wxpartnerKey = str(config['partnerKey'])
     else:
         appId = chargeInfo['appId']
         packageName = chargeInfo['packageName']
         config = GameItemConfigure(
             appId).get_game_channel_configure_by_package(
                 'weixin', packageName)
         if not config:
             raise PayErrorV4(
                 1, 'can not find wxpay config info define of wxappId=' +
                 str(wxappId))
         wxappId = str(config['WXAPPID'])
         wxpaySignKey = ""  # 用不到了
         wxappSecret = str(config['WXAPPKEY'])
         wxpartnerId = str(config['partnerId'])
         wxpartnerKey = str(config['partnerKey'])
     token = self.__get_accesstoken(wxappId, wxappSecret)
     payData = self.__get_prepayid_new(chargeInfo, token, wxappId,
                                       wxpaySignKey, wxpartnerId,
                                       wxpartnerKey, tradeType, openid)
     return self.return_mo(0, chargeInfo=chargeInfo, payData=payData)
示例#14
0
    def charge_data(cls, mi):
        chargeinfo = cls.get_charge_info(mi)
        platformOrderId = chargeinfo['platformOrderId']
        prodPrice = int(chargeinfo['chargeTotal']) * 100
        charge = int(chargeinfo['chargeTotal'])
        prodName = chargeinfo['diamondName']
        callbackAddress = PayHelperV4.getSdkDomain(
        ) + '/v1/pay/maopao/callback'

        prodPayMethod = ''
        maopaoConfig = TyContext.Configure.get_global_item_json(
            'maopao_config', {})

        phoneType = TyContext.UserSession.get_phone_type_name(
            chargeinfo['phoneType'])
        maopaoAppid = mi.getParamStr('maopao_appId')
        if not maopaoAppid:
            raise PayErrorV4(1, '【冒泡】maopao_appId参数 没有!')
        if charge in maopaoConfig['paysms'] and PHONETYPE_INTS[phoneType] != 1:
            prodPayMethod = 'sms'
            typroductId = chargeinfo['buttonId']
            payPointNum = '-1'
            if maopaoAppid in maopaoConfig:
                maopaoAppidPayNum = maopaoConfig[maopaoAppid]
                if typroductId in maopaoAppidPayNum:
                    payPointNum = maopaoAppidPayNum[typroductId]
                    TyContext.ftlog.debug('doMaopaoCallback payInfo',
                                          'maopaoAppid', maopaoAppid,
                                          'typroductId', typroductId)
            else:
                raise PayErrorV4(1, '【冒泡】ID [%s] 没有[%s]计费点配置!', maopaoAppid,
                                 typroductId)
        else:
            prodPayMethod = '3rd'
            payPointNum = '1'

        TyContext.ftlog.debug('doMaopaoCallback payPointNum', payPointNum)

        chargeinfo['chargeData'] = {
            'platformOrderId': platformOrderId,
            'prodPrice': prodPrice,
            'prodName': prodName,
            'prodPayMethod': prodPayMethod,
            'callbackAddress': callbackAddress,
            'payPointNum': payPointNum
        }
        return cls.return_mo(0, chargeInfo=chargeinfo)
示例#15
0
    def get_order_info(self, mi):
        chargeinfo = self.get_charge_info(mi)
        chargetype = chargeinfo['chargeType']
        clientId = chargeinfo['clientId']
        paycodes = TyContext.Configure.get_global_item_json('paycodes',
                                                            clientid=clientId)
        buttonId = chargeinfo['buttonId']
        try:
            pdata = paycodes[chargetype]['paydata']
        except Exception as e:
            TyContext.ftlog.error('paycodes', paycodes, 'config error for',
                                  clientId, 'buttonId', buttonId)
            raise PayErrorV4(-1, "找不到%s的MM计费点配置!" % buttonId)

        chargeData = filter(lambda x: x['prodid'] == buttonId, pdata)
        if not chargeData:
            raise PayErrorV4(-1, "找不到%s的MM计费点配置!" % buttonId)
        return self.return_mo(0, chargeInfo=chargeinfo, payData=chargeData[0])
示例#16
0
 def check_store_payment(self, mi):
     prodId = mi.getParamStr('prodId')
     chargeType = mi.getParamStr('chargeType')
     appId = mi.getParamStr('appId', '9999')
     clientId = mi.getParamStr('clientId')
     # mustcharge = mi.getParamInt('mustcharge')
     # tyGameName = mi.getParamStr('tyGameName')
     # tySubGameName = mi.getParamStr('tySubGameName')
     tyChannelName = mi.getParamStr('tyChannelName')
     # tyVersionName = mi.getParamStr('tyVersionName') # 3.71
     store_payment = ChargeConfigure.get_store_payment(prodId,
                                                       appId,
                                                       clientId=clientId)
     if not store_payment:
         raise PayErrorV4(1, '支付类型未配置')
     # 获取对应的支付类型
     payInfo = filter(lambda x: x['paytype'] == chargeType, store_payment)
     if not payInfo:
         raise PayErrorV4(1, '支付类型无效')
示例#17
0
 def handle_order(self, mi):
     chargeInfo = self.get_charge_info(mi)
     mo = TyContext.Cls_MsgPack()
     try:
         self.doPayRequestAli(chargeInfo, mi, mo)
     except:
         raise PayErrorV4(1, "阿里支付请求错误")
     paydata = mo.getResult("payData")
     payData = {}
     payData['360ali_config'] = paydata
     return self.return_mo(0, chargeInfo=chargeInfo, payData=payData)
示例#18
0
 def order_alibig(self, mi):
     userId = mi.getParamInt('userId')
     clientId = mi.getParamStr('clientId')
     alibig_config = TyContext.Configure.get_global_item_json(
         'alibig_config', {})
     userList = alibig_config.get('userList', [])
     clientList = alibig_config.get('clientList', [])
     if not userId in userList or not clientId in clientList:
         raise PayErrorV4(-1, "用户信息错误")
     mi.setParam('prodId', alibig_config['prodId'])
     mi.setParam('prodCount', alibig_config['prodCount'])
     mi.setParam('prodName', alibig_config['prodName'])
     chargeInfo = self.get_charge_info(mi)
     return self.return_mo(0, chargeInfo=chargeInfo)
示例#19
0
 def doPay(self, rpath):
     rparams = TyContext.RunHttp.convertArgsToDict()
     TyContext.ftlog.info('PayWeixinV4Gateway.doPay rparams=', rparams)
     if not self.checkGatewaySign(rparams):
         return '{"code":1,"msg":"signature error"}'
     appId = rparams['appId']
     prodName = rparams['prodName']
     prodPrice = rparams['prodPrice']
     orderId = rparams['orderId']
     notifyUrl = rparams['notifyUrl']
     ###
     chargeInfo = {
         'buttonName': prodName,
         'platformOrderId': orderId,
         'chargeTotal': float(prodPrice),
     }
     wxappId = 'wxb01a635a437adb75'  # mi.getParamStr('wxappId')
     openid = None  # mi.getParamStr('openid')
     tradeType = 'WAP'
     wxconfig = TyContext.Configure.get_global_item_json('wx_config', {})
     config = wxconfig.get(str(wxappId), None)
     if config:
         wxappId = str(config['appId'])
         wxpaySignKey = str(config['paySignKey'])
         wxappSecret = str(config['appSecret'])
         wxpartnerId = str(config['partnerId'])
         wxpartnerKey = str(config['partnerKey'])
     else:
         raise PayErrorV4(
             1, 'can not find wxpay config info define of wxappId=' +
             str(wxappId))
     token = PayWeixinV4.get_accesstoken(wxappId, wxappSecret)
     callbackUrl = PayHelper.getSdkDomain() + '/open/gateway/wxpay/callback'
     payData = PayWeixinV4.get_prepayid_new(chargeInfo, token, wxappId,
                                            wxpaySignKey, wxpartnerId,
                                            wxpartnerKey, tradeType, openid,
                                            callbackUrl)
     ###
     chargeData = {
         'appId': appId,
         'prodName': prodName,
         'prodPrice': prodPrice,
         'orderId': orderId,
         'notifyUrl': notifyUrl,
         'payData': payData
     }
     TyContext.RedisPayData.execute('SET', 'sdk.charge.gateway:' + orderId,
                                    json.dumps(chargeData))
     return json.dumps({'code': 0, 'payData': payData})
示例#20
0
 def get_consume_info(self, chargeInfo):
     prodInfo = ChargeConfigure.get_prod_info(
         chargeInfo['appId'],
         chargeInfo['diamondId'],
         clientId=chargeInfo['clientId'])
     prodDiamondPrice = prodInfo[
         'diamondPrice']  # 商品钻石价格(一般等于10*prodInfo['price'])
     ###
     prodCount = chargeInfo['diamondCount']
     appId = chargeInfo['appId']
     appInfo = chargeInfo.get('appInfo', '')
     clientId = chargeInfo['clientId']
     userId = chargeInfo['userId']
     prodId = chargeInfo['diamondId']
     prodPrice = chargeInfo['diamondPrice']
     prodCount = prodCount
     prodName = chargeInfo['diamondName']
     consumeCoin = prodCount * prodDiamondPrice
     prodOrderId = chargeInfo['prodOrderId']
     mo = TyContext.Cls_MsgPack()
     # 创建消耗订单
     fail, consumeOrderId = TuyouPayConsume._create_consume_transaction(
         appId, appInfo, clientId, userId, consumeCoin, prodId, prodPrice,
         prodCount, prodName, prodOrderId, mo)
     if fail:
         raise PayErrorV4(mo.getErrorCode(), mo.getErrorInfo())
     consumeInfo = {
         'appId': int(chargeInfo['appId']),
         'appInfo': chargeInfo['appInfo'],
         'clientId': chargeInfo['clientId'],
         'userId': chargeInfo['userId'],
         'consumeCoin': consumeCoin,
         'prodId': chargeInfo['diamondId'],
         'prodPrice': chargeInfo['diamondPrice'],
         'prodCount': chargeInfo['diamondCount'],
         'prodName': chargeInfo['diamondName'],
         'prodOrderId': consumeOrderId,
         'mustcharge': '1',
     }
     # diamondInfo = self.get_consume_diamond(chargeInfo['appId'], prodInfo,clientId=chargeInfo['clientId'])
     # replace item
     # chargeInfo['diamondId'] = diamondInfo['id']
     # chargeInfo['diamondName'] = diamondInfo['name']
     # chargeInfo['diamondPrice'] = diamondInfo['price']
     # consumeInfo['diamondCount'] = diamondInfo['']
     # self.check_charge_info(chargeInfo)
     return consumeInfo
示例#21
0
    def get_order(self, mi):
        chargeInfo = self.get_charge_info(mi)
        ali_appid = mi.getParamStr('ali_appid', '')
        platformOrderId = chargeInfo['platformOrderId']
        config = GameItemConfigure.get_game_channel_configure_by_orderId(
            platformOrderId, 'alipayapp')
        if not config:
            raise PayErrorV4(1, '请当前包的渠道参数配置')
        alipay_id = config.get('alipay_id')
        alipay_private_key = config.get('alipay_private_key')
        params = {
            'app_id':
            alipay_id,
            'method':
            'alipay.trade.app.pay',
            'format':
            'JSON',
            'charset':
            'utf-8',
            'sign_type':
            'RSA',
            'timestamp':
            datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
            'version':
            '1.0',
            'notify_url':
            PayHelperV4.getSdkDomain() + '/v1/pay/alinewpay/app/callback'
        }

        biz_content = {
            'subject': chargeInfo['buttonName'],
            'out_trade_no': platformOrderId,
            'timeout_express': '90m',
            'total_amount': '%.2f' % chargeInfo['chargeTotal'],
            'product_code': 'QUICK_MSECURITY_PAY',
            'goods_type': '0',
        }
        import json
        params['biz_content'] = json.dumps(biz_content)
        signStr = '&'.join(k + '=' + str(params[k]) for k in sorted(params))
        params['sign'] = self.rsaAliSign(signStr, alipay_private_key)
        orderStr = '&'.join(k + '=' + urllib.quote(str(params[k]))
                            for k in sorted(params))
        orderStr += '&sign=' + urllib.quote(
            self.rsaAliSign(signStr, alipay_private_key))
        payData = {'ali_config': orderStr}
        return self.return_mo(0, chargeInfo=chargeInfo, payData=payData)
示例#22
0
    def charge_data(cls, mi):
        chargeinfo = cls.get_charge_info(mi)
        appId = chargeinfo['appId']
        buttonId = chargeinfo['buttonId']
        prodconfig = TyContext.Configure.get_global_item_json(
            'jinri_prodids', {})
        data = prodconfig[str(appId)].get(str(buttonId), None)

        if data:
            payCode = data['feecode']
        else:
            raise PayErrorV4(
                1, 'can not find jinri product define of buttonId=' +
                buttonId + ' clientId=' + chargeinfo['clientId'])

        chargeinfo['chargeData'] = {'msgOrderCode': payCode}
        return cls.return_mo(0, chargeInfo=chargeinfo)
示例#23
0
 def get_accesstoken(cls, wxappId, wxappSecret):
     wxtokenkey = 'wx:token:' + wxappId
     token = TyContext.RedisPayData.execute('GET', wxtokenkey)
     if not token:
         postparams = {}
         postparams['grant_type'] = 'client_credential'
         postparams['appid'] = wxappId
         postparams['secret'] = wxappSecret
         response, _ = TyContext.WebPage.webget(cls.token_url,
                                                postdata_=postparams)
         response = json.loads(response)
         if response['access_token']:
             token = str(response['access_token'])
             TyContext.RedisPayData.execute('SET', wxtokenkey, token)
             TyContext.RedisPayData.execute('EXPIRE', wxtokenkey,
                                            int(response['expires_in']))
         else:
             raise PayErrorV4(
                 1, 'can not get wxpay access token of appId=' + wxappId)
     return token
示例#24
0
    def charge_data(self, mi):
        chargeinfo = self.get_charge_info(mi)
        borui_paykeys = TyContext.Configure.get_global_item_json('borui_paykeys', {})
        payNowAppId = mi.getParamStr('borui_appId')
        if not payNowAppId:
            raise PayErrorV4(1, '【博瑞】参数中没有borui_appId')

        try:
            payNowInfo = borui_paykeys[payNowAppId]
        except KeyError:
            payNowInfo = borui_paykeys
        appSecret = payNowInfo['appSecret']
        chargeData = {
            # 'platformOrderId' : chargeinfo['platformOrderId'],
            'appId': payNowInfo['appId'],  #
            'mhtOrderNo': chargeinfo['platformOrderId'],
            'mhtOrderName': chargeinfo['buttonName'],
            'mhtOrderType': '01',  # 普通消费
            'mhtCurrencyType': '156',  # 人民币
            'mhtOrderAmt': int(float(chargeinfo['chargeTotal']) * 100),  # 单位分
            'mhtOrderDetail': chargeinfo['buttonName'],
            'mhtOrderTimeOut': 3600,
            'mhtOrderStartTime': datetime.now().strftime('%Y%m%d%H%M%S'),
            'notifyUrl': payNowInfo['notifyUrl'],
            'mhtCharset': 'UTF-8',
            'payChannelType': chargeinfo.get('payChannelType', None),  # 支付宝
            'mhtReserved': payNowInfo['mhtReserved'],
        }
        keys = chargeData.keys()
        keys.sort()
        keys = filter(lambda x: chargeData[x], keys)
        text = '&'.join(['%s=%s' % (k, chargeData[k]) for k in keys])
        sign1 = hashlib.md5(appSecret).hexdigest()
        sign2 = hashlib.md5('%s&%s' % (text.encode('utf-8'), sign1)).hexdigest()
        chargeData['mhtSignature'] = sign2
        chargeData['mhtSignType'] = 'MD5'
        chargeData['consumerId'] = chargeinfo['uid']
        chargeData['consumerName'] = chargeinfo['uid']
        chargeinfo['chargeData'] = chargeData
        return self.return_mo(0, chargeInfo=chargeinfo)
示例#25
0
    def get_prepayid_new(cls,
                         chargeInfo,
                         token,
                         wxappId,
                         wxpaySignKey,
                         partnerId,
                         partnerKey,
                         tradeType='APP',
                         openid=None,
                         notifyurl=None):

        if not notifyurl:
            notifyurl = PayHelper.getSdkDomain(
            ) + '/open/ve/pay/wxpap/callback'
        prepayUrl = cls.prepay_url_new + '?access_token=' + token
        postparams = {}
        postparams['appid'] = wxappId
        postparams['mch_id'] = partnerId
        postparams['nonce_str'] = md5(str(random.randint(0,
                                                         10000))).hexdigest()
        postparams['body'] = chargeInfo['buttonName']
        postparams['out_trade_no'] = chargeInfo['platformOrderId']
        postparams['fee_type'] = 'CNY'  # 货币类型
        postparams['total_fee'] = str(
            int(float(chargeInfo['chargeTotal']) * 100))
        postparams['spbill_create_ip'] = TyContext.RunHttp.get_client_ip()
        postparams['notify_url'] = notifyurl
        postparams['trade_type'] = tradeType
        if tradeType == 'JSAPI':
            postparams['openid'] = openid

        calStr = '&'.join(
            k + "=" + postparams[k]
            for k in sorted(postparams.keys())) + '&key=' + partnerKey
        signValue = md5(calStr).hexdigest().upper()
        postparams['sign'] = signValue
        TyContext.ftlog.debug('TuyouPayWXpay.__get_prepayid_new calStr=',
                              calStr, 'postparams=', postparams)

        rootXml = ElementTree.Element('xml')
        for i in postparams:
            element = ElementTree.SubElement(rootXml, i)
            element.text = postparams[i]
        postXml = ElementTree.tostring(rootXml, encoding='utf-8')
        TyContext.ftlog.debug('TuyouPayWXpay.__get_prepayid_new postXml=',
                              postXml)

        response, _ = TyContext.WebPage.webget(
            prepayUrl, postdata_=postXml.encode('utf-8'))
        xmlResponse = ElementTree.fromstring(response)
        TyContext.ftlog.debug('TuyouPayWXpay.__get_prepayid_new xmlResponse=',
                              xmlResponse)

        if 'SUCCESS' == xmlResponse.find('return_code').text:
            if 'SUCCESS' == xmlResponse.find('result_code').text:
                payData = OrderedDict()
                prepayid = xmlResponse.find('prepay_id').text

                if tradeType == 'JSAPI':
                    payData['appId'] = wxappId
                    payData['nonceStr'] = postparams['nonce_str']
                    payData['package'] = "prepay_id=" + prepayid
                    payData['timeStamp'] = str(int(time.time()))
                    payData['signType'] = 'MD5'
                elif tradeType == 'WAP':
                    payData['appid'] = wxappId
                    payData['noncestr'] = postparams['nonce_str']
                    payData['package'] = 'WAP'
                    payData['prepayid'] = prepayid
                    payData['timestamp'] = str(int(time.time()))
                else:
                    payData['appid'] = wxappId
                    payData['noncestr'] = postparams['nonce_str']
                    payData['prepayid'] = prepayid
                    payData['package'] = 'Sign=WXpay'
                    payData['partnerid'] = partnerId
                    payData['timestamp'] = str(int(time.time()))
                signStr = '&'.join(
                    k + "=" + payData[k]
                    for k in sorted(payData.keys())) + '&key=' + partnerKey
                sign = md5(signStr).hexdigest().upper()
                payData['sign'] = sign
                if tradeType == 'WAP':
                    payData['deeplink'] = cls.get_deeplink(payData)
                TyContext.ftlog.debug(
                    'TuyouPayWXpay.__get_prepayid_new payData=', payData,
                    'signStr', signStr)
                return payData
            else:
                TyContext.ftlog.error(
                    'TuyouPayWXpay.__get_prepayid_new return_msg',
                    xmlResponse.find('return_msg').text)
        else:
            raise PayErrorV4(
                1, 'can not get wxpay prepayid  of wxappId=' + wxappId)
示例#26
0
    def charge_data(cls, mi):
        chargeinfo = cls.get_charge_info(mi)
        cls.check_charge_info(mi, chargeinfo)
        packageName = chargeinfo['packageName']
        userId = int(chargeinfo['uid'])
        snsId, snsinfo = TyContext.RedisUser.execute(userId, 'HMGET', 'user:%s' % userId, 'snsId', 'snsinfo')
        coolpad_keys = TyContext.Configure.get_global_item_json('coolpad_keys', {})
        for appId, appInfo in coolpad_keys.items():
            if appId == 'publicKey':
                continue
            if isinstance(appInfo, dict) and appInfo.get('package') == packageName:
                break
        else:
            TyContext.ftlog.error('TuYouPayCoolpad package not found ', packageName)
            config = GameItemConfigure(chargeinfo['appId']).get_game_channel_configure_by_package('coolpad',
                                                                                                  chargeinfo[
                                                                                                      'packageName'],
                                                                                                  chargeinfo[
                                                                                                      'mainChannel'])
            if not config:
                raise PayErrorV4(1, 'TuYouPayCoolpad package not found %s' % packageName)
            else:
                appInfo = {
                    'appId': config.get('coolpad_appId'),
                    'appKey': config.get('coolpad_appKey'),
                }
            prodConfig = config.get('products', {})
            diamondId = chargeinfo['diamondId']
            diamondList = filter(lambda x: diamondId in x.values(), prodConfig)
            diamondConfig = {}
            if diamondList:
                diamondConfig = diamondList[0]
            waresid = diamondConfig.get('code', '')
            if not waresid:
                raise PayErrorV4(1, "找不到计费点 ")
            chargeinfo['chargeData'] = {'callback': 'http://open.touch4.me/v1/pay/coolpad/callback', 'waresid': waresid,
                                        'appKey': appInfo['appKey'], 'openID': snsId[len('coolpad:'):],
                                        'authToken': snsinfo}
            return cls.return_mo(0, chargeInfo=chargeinfo)
        appId = appInfo['appId']
        appKey = appInfo['appKey']
        try:
            if 'diamondId' in chargeinfo:
                waresid = chargeinfo['diamondId']
            elif 'buttonId' in chargeinfo:
                waresid = chargeinfo['buttonId']
            elif 'prodId' in chargeinfo:
                waresid = chargeinfo['prodId']
            else:
                waresid = None
            waresid = appInfo['products'][waresid]
        except:
            TyContext.ftlog.error('TuYouPayCoolpad product not found ', chargeinfo)
            raise PayErrorV4(1, "找不到计费点 ")
        if not appKey:
            TyContext.ftlog.error('TuYooIappay this id has no key , id ', appId)

        if not waresid:
            TyContext.ftlog.error('TuYooIappay this prodId has no waresid , chargeinfo ', chargeinfo)
            raise PayErrorV4(1, "找不到计费点 ")
        chargeinfo['chargeData'] = {'callback': 'http://open.touch4.me/v1/pay/coolpad/callback', 'waresid': waresid,
                                    'appKey': appKey, 'openID': snsId[len('coolpad:'):], 'authToken': snsinfo}
        return cls.return_mo(0, chargeInfo=chargeinfo)
示例#27
0
 def get_charge_info(self, mi):
     """
     获取购买信息,prodId可能是钻石Id,也可能是道具Id
     :param mi:
     :return:
     """
     userId = mi.getParamInt('userId', 0)
     appId = mi.getParamStr('appId', '9999')
     clientId = mi.getParamStr('clientId')
     appInfo = mi.getParamStr('appInfo', '')
     chargeType = mi.getParamStr('chargeType')
     prodId = mi.getParamStr('prodId')
     prodName = mi.getParamStr('prodName')
     prodCount = mi.getParamInt('prodCount', 0)
     prodPrice = float(mi.getParamStr('prodPrice', 0))
     mustcharge = mi.getParamInt('mustcharge', 0)
     # tyChannelName = mi.getParamStr('tyChannelName')
     platformOrderId = mi.getParamStr('platformOrderId', '')
     if not platformOrderId:
         platformOrderId = self.make_order_id(userId, appId, clientId)
     # 获取商品信息
     prod_info = ChargeConfigure.get_prod_info(appId,
                                               prodId,
                                               clientId=clientId)
     if not prod_info:
         raise PayErrorV4(1, '商品信息错误')
     if prodPrice >= 0.1 and abs(prodPrice - prod_info['price']) > 0.1:
         raise PayErrorV4(2, '商品信息错误')
     # 商品加个通过后台配置
     prodPrice = prod_info['price']
     if not prodCount or prodCount < 0:
         prodCount = 1
     if not prodName:
         prodName = prod_info.get('name', '')
         # 获取折扣信息
     cpExtInfo = ""
     cpExtObj = ChargeConfigure.get_cpExt_info(prodId,
                                               appId,
                                               clientId=clientId,
                                               chargeType=chargeType)
     if cpExtObj:
         cpExtInfo = cpExtObj.get('cpExtInfo', 0)
     chargeInfo = {
         'uid':
         userId,
         'userId':
         userId,
         'appId':
         int(appId),
         'clientId':
         clientId,
         'appInfo':
         appInfo,
         'chargeType':
         chargeType,
         'diamondId':
         prodId,
         'diamondName':
         prodName,
         'diamondPrice':
         prodPrice,
         'diamondCount':
         prodCount,
         'chargeTotal':
         prodPrice * prodCount,  # 充值的RMB数量
         'chargeCoin':
         prodCount * prod_info['diamondPrice'],  # 充值的钻石数量
         'platformOrderId':
         platformOrderId,
         'phoneType':
         TyContext.UserSession.get_session_phone_type(userId),
         'buttonId':
         prodId,
         'buttonName':
         prodName,
         'cpExtInfo':
         cpExtInfo,
         'mustcharge':
         mustcharge,
         'prodOrderId':
         mi.getParamStr('prodOrderId', ''),
         'mainChannel':
         clientId.split('.')[-2],
         'packageName':
         mi.getParamStr('tyPackageName', '')
         or mi.getParamStr('packageName', ''),
         'channelName':
         mi.getParamStr('tyChannelName', ''),
     }
     # 非钻石需要兑换或途游游戏
     if not int(prod_info.get('is_diamond', 0)) or int(appId) > 9999:
         consumeInfo = self.get_consume_info(chargeInfo)
     else:
         consumeInfo = None
     # 计费点获取(有些钻石也需要)
     self.check_charge_info(mi, chargeInfo)
     self.save_order(chargeInfo, consumeInfo)
     # bi report
     Order.log(platformOrderId,
               Order.CREATE,
               userId,
               appId,
               clientId,
               diamondid=chargeInfo['diamondId'],
               prodid=consumeInfo['prodId'] if consumeInfo else 'na',
               prod_price=consumeInfo['prodPrice'] if consumeInfo else 'na',
               paytype=chargeInfo.get('chargeType', 'na'),
               charge_price=chargeInfo['chargeTotal'],
               shortId='',
               pay_appid='')
     return chargeInfo
示例#28
0
    def charge_data(cls, mi):
        chargeinfo = cls.get_charge_info(mi)
        config = GameItemConfigure(
            chargeinfo['appId']).get_game_channel_configure_by_package(
                'anzhi', chargeinfo['packageName'], chargeinfo['mainChannel'])
        if not config:
            TyContext.ftlog.error(
                'Anzhi,get sdkconfig error,cannot save orderinfo berforpay!')
        anzhiAppId = config.get('anzhi_appKey', "")
        anzhi_appSecret = config.get('anzhi_appSecret', "")
        charge_key = 'sdk.charge:anzhi:%s' % anzhiAppId
        TyContext.RedisPayData.execute('HSET', charge_key, 'appSecret',
                                       anzhi_appSecret)
        TyContext.ftlog.debug('TuYouAiDongManPay charge_data chargeinfo',
                              chargeinfo)

        anzhiconfig = TyContext.Configure.get_global_item_json(
            'anzhi_config', {})
        desKey = ''
        azsrt = ''
        azappKey = mi.getParamStr('anzhi_appKey')

        if anzhiconfig:
            for item in anzhiconfig:
                if 0 == cmp(item['appId'], azappKey):
                    TyContext.ftlog.debug('TuyouPayAnzhiv4 -> azappKey ->',
                                          azappKey, item['appId'])
                    azsrt = item['appsecret']
                    desKey = item.get('3desKey', '')
                    break
        TyContext.ftlog.debug('TuYouanzhi 3desKey=%s,sct=%s' % (azsrt, desKey))
        if not azsrt:
            azsrt = config.get('anzhi_appSecret', '')
            desKey = config.get('anzhi_3desKey', '')
            if not azsrt:
                raise PayErrorV4(1, '找不到安智的配置%s' % azappKey)
        chargeinfo['chargeData'] = {
            'platformOrderId': chargeinfo['platformOrderId']
        }

        if desKey:
            price = chargeinfo['diamondPrice']

            data = {
                'cpOrderId': chargeinfo['platformOrderId'],
                'cpOrderTime': int(time.time()),
                'amount': int(price * 100),
                'cpCustomInfo': chargeinfo['platformOrderId'],
                'productName': chargeinfo['diamondName'],
                'productCode': chargeinfo['diamondId'],
            }

            tripelDes = triple_des(desKey.encode('ascii'),
                                   mode=ECB,
                                   padmode=PAD_NORMAL)
            data_json = json.dumps(data)
            des_3_data = b64encode(
                tripelDes.encrypt(data_json, padmode=PAD_PKCS5))
            TyContext.ftlog.debug(
                'TuYouPayAnZhiV4 data_json=%s,key=%s,3des=%s', data_json,
                desKey, des_3_data)
            chargeinfo['chargeData']['secretMD5'] = md5(desKey).hexdigest()
            chargeinfo['chargeData']['order_data'] = des_3_data

        return cls.return_mo(0, chargeInfo=chargeinfo)
示例#29
0
    def charge_data(self, mi):
        chargeinfo = self.get_charge_info(mi)
        appId = chargeinfo['appId']
        diamondId = chargeinfo['buttonId']
        orderPlatformId = chargeinfo['platformOrderId']
        vivo_appId = mi.getParamStr('vivo_appId')
        if not vivo_appId:
            raise PayErrorV4(1, '沒有找到参数vivo_appId!')

        pramas = {}
        pramas['version'] = '1.0.0'
        pramas['orderTitle'] = chargeinfo['buttonName']
        pramas['orderDesc'] = chargeinfo['buttonName']
        pramas['orderAmount'] = '%.2f' % chargeinfo['chargeTotal']

        appinfoconfig = TyContext.Configure.get_global_item_json(
            'vivo_appkeys', {})
        appdata = appinfoconfig.get(str(vivo_appId), None)
        if not appdata:
            config = GameItemConfigure(
                chargeinfo['appId']).get_game_channel_configure_by_package(
                    'vivo', chargeinfo['packageName'],
                    chargeinfo['mainChannel'])
            appdata = {
                'cpid': config.get('vivo_cpid'),
                'appid': config.get('vivo_appId'),
                'cpkey': config.get('vivo_cpkey'),
            }
        pramas['storeId'] = appdata['cpid']
        pramas['appId'] = appdata['appid']
        notifyurl = PayHelperV4.getSdkDomain() + '/v1/pay/vivo/callback'
        pramas['notifyUrl'] = notifyurl
        pramas['storeOrder'] = orderPlatformId

        timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
        pramas['orderTime'] = timestamp
        cpkey = appdata['cpkey']
        sign = self.__cal_sign(pramas, cpkey)
        pramas['signature'] = sign
        pramas['signMethod'] = 'MD5'

        orderpushurl = 'https://pay.vivo.com.cn/vivoPay/getVivoOrderNum'
        TyContext.ftlog.debug('TuYouPayVivo->order push url->', orderpushurl)
        response, orderpushurl = TyContext.WebPage.webget(orderpushurl, pramas)
        try:
            datas = json.loads(response)
            if int(datas['respCode']) != 200:
                raise PayErrorV4(
                    1,
                    'TuYouPayVivo charge_data->order push url response ERROR, rspmsg=',
                    datas['respMsg'])
            if not self.__verify_sign(datas, cpkey, datas['signature']):
                raise PayErrorV4(1, 'vivo 验签失败!')
            chargeinfo['chargeData'] = {
                'vivoOrder': datas['vivoOrder'],
                'vivoSignature': datas['vivoSignature']
            }
            return self.return_mo(0, chargeInfo=chargeinfo)
        except:
            raise PayErrorV4(
                1,
                'TuYouPayVivo charge_data->order push url return ERROR, response=',
                response)
示例#30
0
    def charge_data(self, mi):
        chargeinfo = self.get_charge_info(mi)
        TyContext.ftlog.info('TuYouPayGeFuBigSdk charge_data chargeinfo',
                             chargeinfo)
        geFuBigSdkconfig = TyContext.Configure.get_global_item_json(
            'geFuBigSdk_config', {})
        rparam = collections.OrderedDict()

        rparam['appid'] = geFuBigSdkconfig['appId']
        rparam['appuserid'] = str(chargeinfo['uid'])
        rparam['cporderid'] = chargeinfo['platformOrderId']
        # rparam['cpprivateinfo'] = '在线途游'
        rparam['currency'] = 'RMB'
        rparam['price'] = int(chargeinfo['chargeTotal'])
        rparam['waresid'] = int(geFuBigSdkconfig['waresId'])
        rparam['notifyurl'] = PayHelperV4.getSdkDomain(
        ) + '/v1/pay/gefubigsdk/callback'

        msg = json.dumps(rparam, separators=(',', ':'))
        TyContext.ftlog.info('TuYouPayGeFuBigSdk charge_data msg', msg)
        msgsign = ''
        for i in msg:
            if i == '/':
                msgsign += '\/'
            else:
                msgsign += i

        TyContext.ftlog.info('TuYouPayGeFuBigSdk charge_data msgsign', msgsign)
        signMsg = rsacrypto._sign_with_privatekey_openssl_md5(
            msgsign, _aibei_privkey)

        TyContext.ftlog.info('TuYouPayGeFuBigSdk charge_data signMsg', signMsg)

        self.createorder_url = geFuBigSdkconfig['createOrderUrl']
        params = {}
        params['transdata'] = msgsign
        params['sign'] = signMsg
        params['signtype'] = 'RSA'
        responsemsg, _ = TyContext.WebPage.webget(self.createorder_url, params,
                                                  None, params)

        TyContext.ftlog.info('TuYouPayGeFuBigSdk charge_data responsemsg',
                             responsemsg)

        responsemsg = urllib.unquote(responsemsg)
        responseDict = urlparse.parse_qs(responsemsg)
        TyContext.ftlog.info('TuYouPayGeFuBigSdk charge_data Ditct',
                             responseDict)

        response = str(responseDict['transdata'][0])
        TyContext.ftlog.info(
            'TuYouPayGeFuBigSdk charge_data responseDict[transdata]',
            responseDict['transdata'], 'response', response)

        response = eval(str(response))
        TyContext.ftlog.info('TuYouPayGeFuBigSdk charge_data eval response',
                             response)

        strtransdata = str(responseDict['transdata'][0])
        strsign = responseDict['sign'][0].replace(' ', '+')

        TyContext.ftlog.info('TuYouPayGeFuBigSdk charge_data strtransdata',
                             strtransdata, 'strsign', strsign)

        if rsacrypto._verify_with_publickey_pycrypto_md5(
                strtransdata, strsign, _aibei_pubkey_py):
            if response['transid']:
                TyContext.ftlog.info(
                    'TuYouPayGeFuBigSdk success userId transid',
                    response['transid'])
                chargeinfo['chargeData'] = {'transid': response['transid']}
                return self.return_mo(0, chargeInfo=chargeinfo)
            else:
                raise PayErrorV4(
                    1, 'TuYouGeFuDaEAiBeiSdk Failed ' + chargeinfo['userId'] +
                    'code' + responseDict['code'] + 'errmsg' +
                    response['errmsg'])
        else:
            raise PayErrorV4(1, 'TuYouPayGeFuBigSdk Failed ', '验签失败')