Exemple #1
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)
Exemple #2
0
 def handle_order_tuyoo(self, mi):
     chargeInfo = self.get_charge_info(mi)
     out_trade_no = chargeInfo['platformOrderId']
     subject = chargeInfo['buttonName']
     total_fee = chargeInfo['chargeTotal']
     packageName = mi.getParamStr('packageName', "")
     appId = chargeInfo['appId']
     alipay_config = self.getPartnerParam(appId=appId, packageName=packageName, chargeType=chargeInfo['chargeType'])
     sParaTemp = {}
     if not alipay_config:
         sParaTemp["partner"] = self.PARTNER
         sParaTemp["seller_id"] = self.SELLER_ID
     else:
         sParaTemp["partner"] = alipay_config['partnerId']
         sParaTemp["seller_id"] = alipay_config['sellerId']
     sParaTemp["out_trade_no"] = out_trade_no
     sParaTemp["subject"] = subject
     sParaTemp["body"] = subject
     sParaTemp["total_fee"] = total_fee
     sParaTemp["notify_url"] = PayHelperV4.getSdkDomain() + "/v1/pay/alinewpay/callback"
     sParaTemp["service"] = "mobile.securitypay.pay"
     sParaTemp["payment_type"] = 1
     sParaTemp["_input_charset"] = 'utf-8'
     sParaTemp["it_b_pay"] = "30m"
     sParaTemp["return_url"] = "m.alipay.com"
     for k, v in sParaTemp.iteritems():
         sParaTemp[k] = '"' + str(v) + '"'
     pairs = filter(lambda x: x[1], sParaTemp.items())
     pairs.sort(lambda x, y: cmp(x[0], y[0]))
     text = '&'.join(['%s=%s' % (k, v) for k, v in pairs])
     otherData = {}
     otherData['sign'] = urllib.quote(self.rsaAliSign(text, alipay_config['partnerId']))
     otherData['sign_type'] = 'RSA'
     otherText = '&'.join(['%s="%s"' % (k, v) for k, v in otherData.iteritems()])
     text = text + '&' + otherText
     payData = {}
     payData['ali_config'] = text
     return self.return_mo(0, chargeInfo=chargeInfo, payData=payData)
Exemple #3
0
    def doIosCallbackVerify(cls, paydata, isSandBox, isMock=False):
        platformOrderId = paydata['platformOrder']
        userId = paydata['userId']
        receiptJsonStr = paydata['receiptJsonStr']
        if not receiptJsonStr or len(receiptJsonStr) < 200:
            return 'error-receipt'

        # documentation link: https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html
        if isMock:
            vrurl = PayHelperV4.getSdkDomain() + '/open/v3/mockios/verifyReceipt'
        elif isSandBox:
            vrurl = 'https://sandbox.itunes.apple.com/verifyReceipt'
        else:
            vrurl = 'https://buy.itunes.apple.com/verifyReceipt'

        TyContext.ftlog.debug('IOS->doIosCallbackVerify isSandBox=', isSandBox, 'url=', vrurl, 'datas=', paydata)

        paydata['iosurl'] = vrurl
        paydata['sandbox'] = isSandBox
        # verifying order can get errors like, "503 Service Unavailable",
        # TCPTimedOutError, etc. so retry 3 times. client will timeout after 8s,
        # so it is useless to retry longer. If sdk service restarts during the
        # process, client will get no response, in which case the client will
        # retry the callback.
        retries = 3
        while retries > 0:
            try:
                response, vrurl = TyContext.WebPage.webget(
                    vrurl, {}, None, receiptJsonStr, 'POST',
                    {'Content-type': 'text/json'})
                return cls.doIosCallbackVerifyDone(response, paydata)
            except Exception, e:
                TyContext.ftlog.error('IOS->doIosCallbackVerify webget failed.'
                                      ' exception', e, 'userId', userId,
                                      'platformOrder', platformOrderId)
                retries -= 1
Exemple #4
0
    def __get_prepayid_new(cls,
                           chargeInfo,
                           token,
                           wxappId,
                           wxpaySignKey,
                           partnerId,
                           partnerKey,
                           tradeType='APP',
                           openid=None):
        prepayUrl = cls.prepay_url_new + '?access_token=' + token
        notifyurl = PayHelperV4.getSdkDomain() + '/open/ve/pay/wxpay/callback'

        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)