Exemplo n.º 1
0
    def charge_data(cls, chargeinfo):
        userId = chargeinfo['uid']
        appId = chargeinfo['appId']
        phoneType = TyContext.UserSession.get_phone_type_name(
            chargeinfo['phoneType'])
        price = int(float(chargeinfo['chargeTotal']))
        platformOrderId = chargeinfo['platformOrderId']

        response = cls.__create_order(phoneType, userId, price,
                                      platformOrderId)
        if not response:
            return
        if str(response[0]) != '000':
            TyContext.ftlog.error(
                'TuYouPayEftApi create_order failed for user', userId,
                'orderid', platformOrderId, 'response', response)
            return
        spnumber = str(response[2])
        sms_msg = str(response[3])

        if not ClientRevision(userId).support_type0_smspayinfo:
            payinfo = SmsPayInfo.getSmsPayInfo(1, sms_msg, spnumber)
            chargeinfo['chargeData'] = {'smsPayinfo': payinfo}
            return

        messages = []
        messages.append((spnumber, sms_msg, 0))
        payinfo = SmsPayInfo.build_sms_payinfo(messages)
        SmsPayInfo.fill_in_dialog_text(payinfo, chargeinfo['buttonName'],
                                       chargeinfo['diamondPrice'])
        chargeinfo['chargeData'] = {'smsPayinfo': payinfo}
Exemplo n.º 2
0
    def charge_data(cls, chargeinfo):
        userId = chargeinfo['uid']
        price = int(float(chargeinfo['chargeTotal']))
        platformOrderId = chargeinfo['platformOrderId']
        shortOrderId = ShortOrderIdMap.get_short_order_id(platformOrderId)

        response, spnumber = cls.__create_order(price, shortOrderId)
        if len(response) == 1:
            TyContext.ftlog.error('TuYouPaySzty create_order failed for user',
                                  userId, 'orderid', platformOrderId,
                                  'response', response)
            return

        sms_msg = response
        if not ClientRevision(userId).support_type0_smspayinfo:
            payinfo = SmsPayInfo.getSmsPayInfo(1, sms_msg, spnumber)
            chargeinfo['chargeData'] = {'smsPayinfo': payinfo}
            return

        messages = [(spnumber, sms_msg, 1000)]
        no_hint = chargeinfo.get('nohint', None)
        payinfo = SmsPayInfo.build_sms_payinfo(messages, nohint=no_hint)
        SmsPayInfo.fill_in_dialog_text(payinfo, chargeinfo['buttonName'],
                                       chargeinfo['diamondPrice'])
        chargeinfo['chargeData'] = {'smsPayinfo': payinfo}
Exemplo n.º 3
0
    def charge_data(cls, chargeinfo):
        mdo_config = TyContext.Configure.get_global_item_json(
            'zwmdo_configs', {})
        price = int(float(chargeinfo['chargeTotal']))
        if not str(price) in mdo_config['smscodes']:
            TyContext.ftlog.error(
                'can not find zhuowang smscode in the price=', price)
            return
        orderPlatformId = chargeinfo['platformOrderId']
        spnumber = mdo_config['spnumber']
        smscode = mdo_config['smscodes'][str(price)]
        shortorderid = ShortOrderIdMap.get_short_order_id(orderPlatformId)
        sms_msg = smscode.format(orderId=shortorderid)

        # type是短信支付的方式,1代表的是发一条短信支付
        userId = chargeinfo['uid']
        if not ClientRevision(userId).support_type0_smspayinfo:
            payinfo = SmsPayInfo.getSmsPayInfo(1, sms_msg, spnumber)
        else:
            no_hint = chargeinfo.get('nohint', None)
            messages = []
            messages.append((spnumber, sms_msg, 1000))
            payinfo = SmsPayInfo.build_sms_payinfo(messages, nohint=no_hint)
        SmsPayInfo.fill_in_dialog_text(payinfo, chargeinfo['buttonName'],
                                       chargeinfo['diamondPrice'])
        chargeinfo['chargeData'] = {'smsPayinfo': payinfo}
Exemplo n.º 4
0
 def __get_query_mo(cls, mo, state, action, chargeInfo, paytype, querynums, errorInfo=''):
     querystatus_config = TyContext.Configure.get_global_item_json('querystatus_config', decodeutf8=True)
     if action == 'fail':
         baseinfo = querystatus_config['failinfo']
     elif action == 'bug':
         baseinfo = ''
     elif action == 'timeout':
         baseinfo = querystatus_config['timeoutinfo']
     else:
         baseinfo = querystatus_config['processinfo']
     querymaxnums = int(querystatus_config['querymaxnums'])
     if action == 'process' and querynums > querymaxnums:
         action = 'timeout'
         mo.setResult('stopquery', 1)
     if ClientRevision(chargeInfo['uid']).support_querystatus_rsp_action_parameter:
         mo.setResult('status', state)
         mo.setResult('action', action)
     else:
         mo.setResult('action', action)
         mo.setResult('status', state)
     info = querystatus_config[action]['info']
     tips = querystatus_config[action]['tips']
     binfo = ''
     if baseinfo:
         for key in baseinfo.keys():
             if paytype in key:
                 binfo = baseinfo[key]
                 break
         if not binfo:
             binfo = baseinfo['thirdpay']
     infotemplate = querystatus_config[action]['content']
     if action == 'success':
         content = infotemplate.format(
             time=datetime.datetime.now().strftime('%H点%M分%S秒'),
             prodname=chargeInfo['diamondName'].encode('utf8')
         )
     elif action == 'bug':
         content = infotemplate
     elif action == 'fail':
         content = infotemplate.format(
             info=binfo + '\n' + errorInfo.encode('utf8'),
         )
     else:
         content = infotemplate.format(
             info=binfo,
         )
     mo.setResult('info', info)
     mo.setResult('content', content)
     mo.setResult('tips', tips)
     return mo
Exemplo n.º 5
0
    def _get_sms_payinfo(cls, chargeinfo, response):
        TyContext.ftlog.info('TuYouPayLinkYunApi _get_sms_payinfo '
                             'response', response, 'chargeinfo', chargeinfo)
        userId = chargeinfo['uid']
        if int(response['resultCode']) != 0:
            TyContext.ftlog.error(
                'TuYouPayLinkYunApi can not get resultCode in the response=',
                response)
            return
        sms_count = 1
        spnumbers = {}
        sms_msgs = {}
        spnumbers[0] = str(response['number'])
        sms_msgs[0] = str(response['command'])
        if response['flag']:
            sms_count = 2
            spnumbers[1] = str(response['number'])
            sms_msgs[1] = str(response['command'])
        if response['confirmContent'] != 'N':
            sms_count = 2
            sms_msgs[1] = str(response['confirmContent'])
            spnumbers[1] = str(response['confirmNumber'])
        if not ClientRevision(userId).support_type0_smspayinfo:
            if sms_count == 2:
                payinfo = SmsPayInfo.getSmsPayInfo(5, sms_msgs[0],
                                                   spnumbers[0], sms_msgs[1],
                                                   spnumbers[1])
            elif sms_count == 1:
                payinfo = SmsPayInfo.getSmsPayInfo(1, sms_msgs[0],
                                                   spnumbers[0])
            chargeinfo['chargeData'] = {'smsPayinfo': payinfo}
            TyContext.ftlog.info(
                'TuYouPayLinkYunApi _get_sms_payinfo chargeData',
                chargeinfo['chargeData'])
            return

        messages = []
        for i in xrange(sms_count):
            messages.append((spnumbers[i], sms_msgs[i], 1000))
        no_hint = chargeinfo.get('nohint', None)
        payinfo = SmsPayInfo.build_sms_payinfo(messages, nohint=no_hint)
        SmsPayInfo.fill_in_dialog_text(payinfo, chargeinfo['buttonName'],
                                       chargeinfo['diamondPrice'])
        chargeinfo['chargeData'] = {'smsPayinfo': payinfo}
        TyContext.ftlog.info('TuYouPayLinkYunApi _get_sms_payinfo chargeData',
                             chargeinfo['chargeData'])
        return
Exemplo n.º 6
0
 def chargeDataErrorMsg(cls, chargeinfo, shortOrderId, errorCode):
     errorInfo = TyContext.Configure.get_global_item_json('monthly_vip_subscribe_error_info', {})
     sms_msg = '_' + shortOrderId
     spnumber = ''
     if not ClientRevision(chargeinfo['uid']).support_type0_smspayinfo:
         payinfo = SmsPayInfo.getSmsPayInfo(1, sms_msg, spnumber)
         chargeinfo['chargeData'] = {'smsPayinfo': payinfo}
         return
     messages = [(spnumber, sms_msg, 0)]
     payinfo = {'messages': messages}
     no_hint = chargeinfo.get('nohint', None)
     if no_hint:
         payinfo['nohint'] = no_hint
     payinfo['text1'] = errorInfo[str(errorCode)]
     payinfo['text2'] = errorInfo['0']
     payinfo['support'] = 'false'
     monthlyVipParams = TyContext.Configure.get_global_item_json('monthly_vip_params', {})
     payinfo['alternativeProdId'] = monthlyVipParams['alternativeProdId']
     chargeinfo['chargeData'] = {'smsPayinfo': payinfo}
Exemplo n.º 7
0
    def charge_data(cls, chargeinfo):
        TyContext.ftlog.debug('TuyoPayShuzitianyuH5 chare_data ,chargeinfo=', chargeinfo)
        userId = chargeinfo['uid']
        price = int(float(chargeinfo['chargeTotal']))
        platformOrderId = chargeinfo['platformOrderId']
        sms_msg, spnumber = cls._create_order(price, platformOrderId)
        if not sms_msg:
            TyContext.ftlog.error('TuYouPayShuzitianyuH5 create_order failed for user', userId,
                                  'orderid', platformOrderId, 'response', sms_msg)
            return

        if not ClientRevision(userId).support_type0_smspayinfo:
            payinfo = SmsPayInfo.getSmsPayInfo(1, sms_msg, spnumber)
            chargeinfo['chargeData'] = {'smsPayinfo': payinfo}
            return
        messages = [(spnumber, sms_msg, 1000)]
        no_hint = chargeinfo.get('nohint', None)
        payinfo = SmsPayInfo.build_sms_payinfo(messages, nohint=no_hint)
        SmsPayInfo.fill_in_dialog_text(
            payinfo, chargeinfo['buttonName'], chargeinfo['diamondPrice'])
        chargeinfo['chargeData'] = {'smsPayinfo': payinfo}
Exemplo n.º 8
0
    def _charge_data_for_duandai(cls, chargeinfo):
        buttonId = chargeinfo['buttonId']
        clientId = chargeinfo['clientId']
        price = chargeinfo['chargeTotal']
        userid = chargeinfo['uid']

        phone_type = TyContext.UserSession.get_session_phone_type(userid)
        operator = TyContext.UserSession.get_phone_type_name(phone_type)
        if operator == TyContext.UserSession.PHONETYPE_OTHER_STR:
            raise Exception('phone_type other has no duandai')

        builtin_paytypes = ClientRevision(userid).get_builtin_paytypes(
            operator)

        # appids -> {"paytype": "appid"}
        appids = PayCodes(clientId).appids
        TyContext.ftlog.debug(
            'TuYouPayDuandai _charge_data_for_duandai '
            'appids', appids, 'chargeinfo', chargeinfo)

        all_duandai_paytypes = TyContext.Configure.get_global_item_json(
            "all_duandai_paytypes")
        supported_paytypes = [
            '_'.join([k, appids[k]]) for k in appids.keys()
            if k in all_duandai_paytypes
        ]

        supported_paytypes.extend(builtin_paytypes)

        paytype = cls._choose_a_paytype(userid, supported_paytypes, operator,
                                        price, buttonId, clientId)
        TyContext.ftlog.debug('TuYouPayDuandai charge_data got paytpe',
                              paytype)
        chargeType = paytype.split('_')[0]
        cfun = TuyouPayChargeConf.get_charge_data_func(chargeType)
        chargeinfo['chargeType'] = chargeType
        cfun(chargeinfo)
        if 'chargeData' not in chargeinfo or not chargeinfo['chargeData']:
            raise Exception('got null paydata for paytype %s' % chargeType)
        chargeinfo['chargeData']['issms'] = 1
Exemplo n.º 9
0
    def charge_data(cls, chargeinfo):

        userId = chargeinfo['uid']
        price = int(float(chargeinfo['chargeTotal'])) * 100
        platformOrderId = chargeinfo['platformOrderId']
        productDesc = chargeinfo['buttonName']

        appid = chargeinfo['appId']
        productName = '途游斗地主'

        phoneType = TyContext.UserSession.get_phone_type_name(
            chargeinfo['phoneType'])
        gefuconfig = TyContext.Configure.get_global_item_json(
            'gefupay_config', {})
        if gefuconfig:
            cls.createorder_url = gefuconfig[cls.thirdPartyId][phoneType]

        response = cls._create_order(phoneType, userId, price, platformOrderId,
                                     productName, productDesc)
        status = response['code']
        if int(status) != 200:
            TyContext.ftlog.error('TuYouGeFuPay create_order failed for user',
                                  userId, 'reason', response['reason'])
            return

        spnumber, sms_msg = response['sms_port'], response['sms']
        if not ClientRevision(userId).support_type0_smspayinfo:
            payinfo = SmsPayInfo.getSmsPayInfo(1, sms_msg, spnumber)
            chargeinfo['chargeData'] = {'smsPayinfo': payinfo}
            return

        messages = [(spnumber, sms_msg, 0)]
        no_hint = chargeinfo.get('nohint', None)
        payinfo = SmsPayInfo.build_sms_payinfo(messages, nohint=no_hint)
        SmsPayInfo.fill_in_dialog_text(payinfo, chargeinfo['buttonName'],
                                       chargeinfo['diamondPrice'])
        chargeinfo['chargeData'] = {'smsPayinfo': payinfo}
Exemplo n.º 10
0
    def charge_data(self, mi):
        chargeinfo = self.get_charge_info(mi)
        userId, platformOrderId, phoneType = chargeinfo['uid'], chargeinfo[
            'platformOrderId'], chargeinfo['phoneType']
        shortOrderId = ShortOrderIdMap.get_short_order_id(platformOrderId)
        TyContext.ftlog.debug(
            'TuYouPayHuiYuanBaoYue->charge_data platformOrderId:[%s] and shortOrderId:[%s]'
            % (platformOrderId, shortOrderId))
        phoneType = TyContext.UserSession.get_phone_type_name(phoneType)
        TyContext.ftlog.debug(
            'TuYouPayHuiYuanBaoYue->charge_data phoneType:[%s].' % phoneType)
        reportBiParams = {}
        reportBiParams['platformOrderId'] = platformOrderId
        reportBiParams['userId'] = userId
        reportBiParams['appId'] = chargeinfo['appId']
        reportBiParams['mobile'] = 'na'
        reportBiParams['clientId'] = chargeinfo['clientId']
        reportBiParams['productId'] = chargeinfo.get(
            'diamondId',
            chargeinfo.get('buttonId', chargeinfo.get('prodId', 'na')))
        reportBiParams['payType'] = chargeinfo.get('chargeType', 'na')

        if 0 == cmp(phoneType, 'chinaMobile'):
            iccid = TyContext.UserSession.get_session_iccid(userId)
            citycode = self.getCityCode(iccid)
            if citycode == 1:
                self.chargeDataErrorMsg(chargeinfo, shortOrderId, citycode)
                return self.return_mo(0, chargeInfo=chargeinfo)
            elif citycode == 2:
                TyContext.ftlog.info(
                    'TuYouPayHuiYuanBaoYue->charge_data User client not support Monthly VIP, iccid: [%s]'
                    % iccid)
                self.reportBi(Order.CLIENT_CANCELED, reportBiParams)
                self.chargeDataErrorMsg(chargeinfo, shortOrderId, citycode)
                return self.return_mo(0, chargeInfo=chargeinfo)
            TyContext.ftlog.debug(
                'TuYouPayHuiYuanBaoYue->charge_data citycode:[%s].' % citycode)
            smsConfigInfo = TyContext.Configure.get_global_item_json(
                'chinaMobile_monthly_smsContent', {})
            smsInfo = smsConfigInfo.get(str(citycode), None)
            if not smsInfo:
                self.chargeDataErrorMsg(chargeinfo, shortOrderId, 2)
                self.reportBi(Order.CLIENT_CANCELED, reportBiParams)
                TyContext.ftlog.info(
                    'TuYouPayHuiYuanBaoYue->charge_data User client not support Monthly VIP, iccid: [%s]'
                    % iccid)
                return self.return_mo(0, chargeInfo=chargeinfo)
            TyContext.ftlog.debug(
                'TuYouPayHuiYuanBaoYue->charge_data smsInfo is: ', smsInfo)
            sms_msg, spnumber = smsInfo['subscribe']
            autoReplyMsg = smsInfo['auto_reply']
            unsub_sms_msg, unsub_spnumber = smsInfo['unsubscribe']
            TyContext.ftlog.debug(
                'TuYouPayHuiYuanBaoYue->charge_data sms_msg:[%s] and spnumber:[%s] and antuReplyMsg:[%s].'
                % (sms_msg, spnumber, autoReplyMsg))
            TyContext.ftlog.debug(
                'TuYouPayHuiYuanBaoYue->charge_data unsub_sms_msg:[%s] and unsub_spnumber:[%s].'
                % (unsub_sms_msg, unsub_spnumber))
            TyContext.RedisPayData.execute(
                'SET', 'unsubMonthlySmsInfo:' + str(userId),
                self.getUnsubscribeSms(unsub_sms_msg, unsub_spnumber))

            # 获取自动回复功能的短信监听内容
            autoReplyListenContent = TyContext.Configure.get_global_item_json(
                'monthly_vip_sms_auto_reply_listen_content', {})
            listenContent = autoReplyListenContent[phoneType]
            messageContent = [autoReplyMsg, ""]
            messageContent += listenContent

            monthlyVipParams = TyContext.Configure.get_global_item_json(
                'monthly_vip_params', {})
            orderIdPhonenum = monthlyVipParams['orderIdPhonenum']
            order_sms_msg = '1125ty' + shortOrderId
            messages = []
            message1 = (orderIdPhonenum, order_sms_msg, 0)
            message2 = (spnumber, sms_msg, 0)
            message3 = ('', '', -1, messageContent)
            messages.append(message1)
            messages.append(message2)
            messages.append(message3)
            if not ClientRevision(userId).support_type0_smspayinfo:
                payinfo = SmsPayInfo.getSmsPayInfo(5, order_sms_msg,
                                                   orderIdPhonenum, sms_msg,
                                                   spnumber)
                chargeinfo['chargeData'] = {'smsPayinfo': payinfo}
                return self.return_mo(0, chargeInfo=chargeinfo)
            no_hint = chargeinfo.get('nohint', None)
            payinfo = {'messages': messages}
            payinfo['support'] = 'true'
            if no_hint:
                payinfo['nohint'] = no_hint
            SmsPayInfo.fill_in_dialog_text(payinfo, chargeinfo['buttonName'],
                                           chargeinfo['diamondPrice'])
            chargeinfo['chargeData'] = {'smsPayinfo': payinfo}
            return self.return_mo(0, chargeInfo=chargeinfo)

        elif 0 == cmp(phoneType, 'chinaUnion'):
            iccid = TyContext.UserSession.get_session_iccid(userId)
            citycode = self.getChinaUnionCityCode(iccid)
            if citycode == 1:
                self.chargeDataErrorMsg(chargeinfo, shortOrderId, citycode)
                return self.return_mo(0, chargeInfo=chargeinfo)
            elif citycode == 2:
                self.reportBi(Order.CLIENT_CANCELED, reportBiParams)
                TyContext.ftlog.info(
                    'TuYouPayHuiYuanBaoYue->charge_data User client not support Monthly VIP, iccid [%s]'
                    % iccid)
                self.chargeDataErrorMsg(chargeinfo, shortOrderId, citycode)
                return self.return_mo(0, chargeInfo=chargeinfo)
            TyContext.ftlog.debug(
                'TuYouPayHuiYuanBaoYue->charge_data citycode:[%s].' % citycode)
            smsConfigInfo = TyContext.Configure.get_global_item_json(
                'chinaUnion_monthly_smsContent', {})
            smsInfo = smsConfigInfo.get(str(citycode), None)
            if not smsInfo:
                self.chargeDataErrorMsg(chargeinfo, shortOrderId, 2)
                self.reportBi(Order.CLIENT_CANCELED, reportBiParams)
                TyContext.ftlog.info(
                    'TuYouPayHuiYuanBaoYue->charge_data User client not support Monthly VIP, iccid: [%s]'
                    % iccid)
                return self.return_mo(0, chargeInfo=chargeinfo)
            TyContext.ftlog.debug(
                'TuYouPayHuiYuanBaoYue->charge_data smsInfo is: ', smsInfo)
            sms_msg, spnumber = smsInfo['subscribe']
            autoReplyMsg = smsInfo['auto_reply']
            unsub_sms_msg, unsub_spnumber = smsInfo['unsubscribe']
            TyContext.ftlog.debug(
                'TuYouPayHuiYuanBaoYue->charge_data sms_msg:[%s] and spnumber:[%s] and antuReplyMsg:[%s].'
                % (sms_msg, spnumber, autoReplyMsg))

            # 获取自动回复功能的短信监听内容
            autoReplyListenContent = TyContext.Configure.get_global_item_json(
                'monthly_vip_sms_auto_reply_listen_content', {})
            listenContent = autoReplyListenContent[phoneType]
            messageContent = [autoReplyMsg, ""]
            messageContent += listenContent

            sms_msg = sms_msg + '_' + shortOrderId
            messages = []
            message1 = (spnumber, sms_msg, 0)
            message2 = ('', '', -1, messageContent)
            messages.append(message1)
            messages.append(message2)

        elif 0 == cmp(phoneType, 'chinaTelecom'):
            smsConfigInfo = TyContext.Configure.get_global_item_json(
                'chinaTelecom_monthly_smsContent', {})
            sms_msg, spnumber = smsConfigInfo['subscribe']
            autoReplyMsg = smsConfigInfo['auto_reply']
            unsub_sms_msg, unsub_spnumber = smsConfigInfo['unsubscribe']
            TyContext.ftlog.debug(
                'TuYouPayHuiYuanBaoYue->charge_data sms_msg:[%s] and spnumber:[%s] and antuReplyMsg:[%s].'
                % (sms_msg, spnumber, autoReplyMsg))

            # 获取自动回复功能的短信监听内容
            autoReplyListenContent = TyContext.Configure.get_global_item_json(
                'monthly_vip_sms_auto_reply_listen_content', {})
            listenContent = autoReplyListenContent[phoneType]
            messageContent = [autoReplyMsg, ""]
            messageContent += listenContent

            sms_msg = sms_msg + '_' + shortOrderId
            messages = []
            message1 = (spnumber, sms_msg, 0)
            message2 = ('', '', -1, messageContent)
            messages.append(message1)
            messages.append(message2)

        else:
            self.chargeDataErrorMsg(chargeinfo, shortOrderId, 1)
            return self.return_mo(0, chargeInfo=chargeinfo)

        # 联通和电信会走该逻辑
        TyContext.ftlog.debug(
            'TuYouPayHuiYuanBaoYue->charge_data unsub_sms_msg:[%s] and unsub_spnumber:[%s].'
            % (unsub_sms_msg, unsub_spnumber))
        TyContext.RedisPayData.execute(
            'SET', 'unsubMonthlySmsInfo:' + str(userId),
            self.getUnsubscribeSms(unsub_sms_msg, unsub_spnumber))
        if not ClientRevision(userId).support_type0_smspayinfo:
            payinfo = SmsPayInfo.getSmsPayInfo(1, sms_msg, spnumber)
            chargeinfo['chargeData'] = {'smsPayinfo': payinfo}
            return self.return_mo(0, chargeInfo=chargeinfo)
        no_hint = chargeinfo.get('nohint', None)
        payinfo = {'messages': messages}
        payinfo['support'] = 'true'
        if no_hint:
            payinfo['nohint'] = no_hint
        SmsPayInfo.fill_in_dialog_text(payinfo, chargeinfo['buttonName'],
                                       chargeinfo['diamondPrice'])
        chargeinfo['chargeData'] = {'smsPayinfo': payinfo}
        return self.return_mo(0, chargeInfo=chargeinfo)
Exemplo n.º 11
0
    def updateUserSessionInfo(cls, appId, userId, params):

        deviceId = cls.__get_param__(params, 'deviceId')
        clientId = cls.__get_param__(params, 'clientId')
        phoneType = cls.__get_param__(params, 'phoneType')
        detect_phonenumber = cls.__get_param__(params, 'detect_phonenumber')
        idfa = cls.__get_param__(params, 'idfa')
        iccid = cls.__get_param__(params, 'iccid')
        svninfo = cls.__get_param__(params, 'svninfo')
        snsInfo = cls.__get_param__(params, 'snsInfo')  # for h5

        datas = []
        if appId > 0:
            datas.append('sessionAppId')
            datas.append(appId)

        if len(deviceId) > 0:
            datas.append('sessionDevId')
            datas.append(deviceId)

        if len(clientId) > 0:
            datas.append('sessionClientId')
            datas.append(clientId)

        if svninfo:
            datas.append('sessionClientSdkRev')
            datas.append(ClientRevision.get_client_sdk_revision(svninfo))
        else:
            datas.append('sessionClientSdkRev')
            datas.append(3333)

        if len(idfa) > 0:
            datas.append('sessionIdfa')
            datas.append(idfa)

        if snsInfo:
            datas.append('sessionSnsInfo')
            datas.append(json.dumps(snsInfo))

        datas.append('sessionIccid')
        datas.append(iccid)

        clientIP = TyContext.RunHttp.get_client_ip()
        if clientIP and len(clientIP) > 0:
            datas.append('sessionClientIP')
            datas.append(clientIP)

        # 2014/12/5 客户端无卡时phoneType为空串,这时也要更新sessionPhoneType
        # 2015/2/27 客户端无卡时phoneType传other
        # 2015/2/27 绑定手机号时,客户端没有传输phoneType字段,此时不应更新sessionPhoneType
        is_check_bind = cls.__get_param__(params, 'bindOrderId')
        if not is_check_bind:
            datas.append('sessionPhoneType')
            datas.append(phoneType)

        if detect_phonenumber and len(detect_phonenumber) > 10:
            datas.append('detect_phonenumber')
            datas.append(detect_phonenumber)

        #         TyContext.ftlog.info('updateUserSessionInfo->userId=', userId, 'datas=', datas)
        if len(datas) > 0:
            TyContext.RedisUser.execute(userId, 'HMSET', 'user:' + str(userId),
                                        *datas)
Exemplo n.º 12
0
    def charge_data(cls, chargeinfo):
        yiconfig = TyContext.Configure.get_global_item_json('yipay_config', {})
        cls.merc_id = str(yiconfig['merc_id'])
        cls.yipay_appid = str(yiconfig['app_id'])
        cls.yipay_key = str(yiconfig['yipay_key'])
        cls.createorder_url = str(yiconfig['createorder_url'])

        userId = chargeinfo['uid']
        appId = chargeinfo['appId']
        phoneType = TyContext.UserSession.get_phone_type_name(
            chargeinfo['phoneType'])
        buttonId = chargeinfo['buttonId']
        price = int(float(chargeinfo['chargeTotal'])) * 100
        platformOrderId = chargeinfo['platformOrderId']
        if buttonId in yiconfig['monthly_prods']:
            is_monthly = '2'
        else:
            is_monthly = '0'
        response = cls._create_order(phoneType, userId, price, platformOrderId,
                                     is_monthly)
        status = response['status']
        msg = create_errmsg.get(status, response['msg'])
        if int(status) != 0:
            TyContext.ftlog.error('TuYouPayYi create_order failed for user',
                                  userId, 'orderid', platformOrderId, 'status',
                                  status, 'msg', msg)
            chargeinfo['chargeData'] = {}
            return
        res = response['res']
        sep = res.get('sms_separator', '@@@')
        sms_count = int(res['sms_count'])
        sms_count = sms_count if sms_count > 1 else 1  # 0/1 is 1
        sms_msg = base64.decodestring(res['sms_msg'])
        spnumber = res['spnumber']
        sms_interval = res.get('sms_interval', 1)
        if not sms_interval:
            sms_interval = 1000
        else:
            sms_interval = int(sms_interval) * 1000
        if sms_count > 1:
            sms_msgs = sms_msg.split(sep)
            spnumbers = spnumber.split(sep)
        else:
            sms_msgs = (sms_msg, )
            spnumbers = (spnumber, )

        if not ClientRevision(userId).support_type0_smspayinfo:
            if sms_count > 2:
                return
            elif sms_count == 2:
                payinfo = SmsPayInfo.getSmsPayInfo(3, sms_msgs[0],
                                                   spnumbers[0], sms_msgs[1],
                                                   spnumbers[1])
            elif sms_count == 1:
                payinfo = SmsPayInfo.getSmsPayInfo(1, sms_msg, spnumber)
            chargeinfo['chargeData'] = {'smsPayinfo': payinfo}
            return

        messages = []
        for i in xrange(sms_count):
            messages.append((spnumbers[i], sms_msgs[i], sms_interval))
        no_hint = chargeinfo.get('nohint', None)
        payinfo = SmsPayInfo.build_sms_payinfo(messages, nohint=no_hint)
        SmsPayInfo.fill_in_dialog_text(payinfo, chargeinfo['buttonName'],
                                       chargeinfo['diamondPrice'])
        chargeinfo['chargeData'] = {'smsPayinfo': payinfo}