Beispiel #1
0
def parse_settle_data(data):
    #    <order>
    #    <tradnum>xxxxxx</tradnum>
    #    <expand>xxxxxxx</expand>
    #    <result>success</result>
    #    <checking>xxxxxxx</checking>
    #    </order>
    #        参数说明
    #    参数    参数说明
    #    tradnum    订单号
    #    expand    3.1.1中游戏方自定义参数
    #    result    同步结果:表示订单同步成功
    #    checking    验证信息,为MD5加密的参数拼接字符串: tradnum+expand+result +key
    #     key 为游戏密钥

    dom = minidom.parseString(data)
    order = dom.getElementsByTagName("order")[0]
    tradnum = getNodeTextByTagName(order, "tradnum")
    result = getNodeTextByTagName(order, "result")
    checking = getNodeTextByTagName(order, "checking")
    expand = getNodeTextByTagName(order, "expand")

    return {
        "tradnum": tradnum,
        "result": result,
        "checking": checking,
        "expand": expand
    }
Beispiel #2
0
def confirm_mycard_billing_fix(request):
    from services.alipay import getNodeTextByTagName
    xml_code = ''
#    '''
#    <BillingApplyRq><FatoryId>xxxxxx</FatoryId><TotalNum>2</TotalNum><Records>
#    <Record><ReturnMsgNo>1</ReturnMsgNo> <ReturnMsg></ReturnMsg> <TradeSeq>1210171504279954939D0B</TradeSeq>
#    </Record><Record>
#    <ReturnMsgNo>1</ReturnMsgNo> <ReturnMsg></ReturnMsg>
#    <TradeSeq>121017151329555432E415</TradeSeq>
#    </Record> </Records>
#    </BillingApplyRq>'''
    xml_data = request.POST.get('data',xml_code)
    print(xml_data)
    xml_dom = minidom.parseString(xml_data)
    orders = xml_dom.getElementsByTagName("Record")
    for order in orders:
        trade_no = getNodeTextByTagName(order,'TradeSeq')
        result_code = getNodeTextByTagName(order,'ReturnMsgNo')
        result_msg = getNodeTextByTagName(order,'ReturnMsg')

        print(trade_no,result_code,result_msg)

        if result_code == '1':
            pay_actions = PayAction.objects.filter(query_id=trade_no)

            if len(pay_actions) > 0:
                the_action = pay_actions[0]
                if the_action.pay_status == 0:
                    pay_channel = PayChannel.objects.using('read').get(id=the_action.pay_type)
                    check_url = 'https://b2b.mycard520.com.tw/MyCardBillingRESTSrv/MyCardBillingRESTSrv.svc/TradeQuery?AuthCode=%s'%the_action.remark
                    check_result = http_post(check_url) #查询充值结果
                    reb = re.compile('<[^<]+>')
                    check_result = reb.sub('',check_result)
                    #查詢結果代碼|查詢結果|交易結果
                    result_code,result_msg,check_code = check_result.split('|')

                    if result_code == '1' and check_code=='3' :
                        CPMemberId = the_action.pay_user;
                        confirm_url = 'https://b2b.mycard520.com.tw/MyCardBillingRESTSrv/MyCardBillingRESTSrv.svc/PaymentConfirm?CPCustId=%s&AuthCode=%s'%(CPMemberId,the_action.remark)
                        confirm_result = http_post(confirm_url) #申请扣款
                        confirm_result = reb.sub('',confirm_result)
                        #請款結果|請款訊息|智冠交易序號|連續扣款序號
                        result_data = confirm_result.split('|')
                        result_code = result_data[0]
                        result_msg = result_data[1] #order_id,loop_order_id 
                        if result_code == '1':
                            the_action.pay_status = 2
                            the_action.pay_amount = the_action.post_amount
                            the_action.pay_gold = pay_channel.get_gold(the_action.pay_amount)
                            the_action.extra = pay_channel.get_extra(the_action.pay_gold) 
                    else:
                        the_action.pay_status = -2

                    the_action.remark = result_msg

                    the_action.save(using='write')

    return render_to_response('pay/pay_post.html',{'pay_status':'SUCCESS'})
Beispiel #3
0
def parse_notify_data(data):
    '''
    通过minixml解析data
    '''
    dom = minidom.parseString(data)
    notify = dom.getElementsByTagName("SyncAppOrderReq")[0]
    TradeID = getNodeTextByTagName(notify, "TradeID")
    OrderID = getNodeTextByTagName(notify, "OrderID")
    TotalPrice = float(getNodeTextByTagName(notify, "TotalPrice"))
    ExData = getNodeTextByTagName(notify, "ExData")
    return TradeID, OrderID, TotalPrice, ExData
Beispiel #4
0
def check_order(query_id, pay_type, amount, cid):
    rcode = ''

    request_url = gash_cfg.get('checkorder_url')

    client = None
    if '' == rcode:
        rcode = '查单错误'

        from suds.client import Client
        client = Client(request_url, timeout=10)
        try:
            platform = get_platform(cid)
            print 'amount:::', amount
            trans = get_check_order_xml(query_id, pay_type, amount, platform)
            result = client.service.getResponse(data=trans)
            print 'check send code :::', trans
            print 'check order code:::%s' % result
            result = base64.decodestring(result)
        except Exception, ex:
            print 'check_order error ', ex

        try:
            result = minidom.parseString(result)

            r_trans = result.getElementsByTagName("TRANS")[0]

            rcode = getNodeTextByTagName(r_trans, "PAY_STATUS")
        except Exception, ex:
            rcode = 'parser xml error'
Beispiel #5
0
def parse_exchange_data(data):
    '''
    通过minixml解析data
    <order>
        <tradnum>xxxxxx</tradnum>
        <status>1</status>
        <checking>xxxxxxx</checking>
        <gamecode>xxxxxxxx</gamecode>
        <expand>xxxxxxxxxxx</expand>
    </order>
    tradnum    订单号:3.1.1中游戏方提供的订单号
    status    交易结果
    0 余额不足,兑换失败
    1.订单成功(游戏平台暂时扣除游戏币)
    2.验证错误
    3.游戏不存在
    4.用户不存在
    5.参数错误(pamt必须为整数)
    gamecode    游戏在游戏平台分配的编号
    expand    游戏方的扩展参数
    checking    验证信息,为MD5加密的参数拼接字符串: 
    tradnum+status+gamecode+expand+key     key 为游戏密钥

    '''
    dom = minidom.parseString(data)
    order = dom.getElementsByTagName("order")[0]
    tradnum = getNodeTextByTagName(order, "tradnum")
    status = getNodeTextByTagName(order, "status")
    checking = getNodeTextByTagName(order, "checking")
    gamecode = getNodeTextByTagName(order, "gamecode")
    expand = getNodeTextByTagName(order, "expand")

    return {
        "tradnum": tradnum,
        "status": status,
        "checking": checking,
        "gamecode": gamecode,
        "expand": expand
    }
Beispiel #6
0
def confirm_feiliu(request, pay_channel={}):
    from services.alipay import decrypt_with_rsa_feiliu, getNodeTextByTagName
    #print(request.GET,request.raw_post_data)
    product_id = ''
    result_msg = 0
    if request.method != 'POST':
        result_msg = '<?xml version="1.0" encoding="utf-8"?><Response><Ret>%d</Ret></Response>' % result_msg
        return {'amount': 0, 'result_msg': result_msg}
    else:
        post_data = request.raw_post_data

    try:
        product_id = pay_channel.get_config_value('product_id', '100003')
    except:
        result_msg = -1

    status = {
        '0': '销卡成功,订单成功',
        '1': '销卡成功,订单失败',
        '7': '卡号卡密或卡面额不符合规则',
        '1002': '本张卡密您提交过于频繁,请您稍后再试',
        '1003': '不支持的卡类型(比如电信地方卡)',
        '1004': '密码错误或充值卡无效',
        '1006': '充值卡无效',
        '1007': '卡内余额不足',
        '1008': '余额卡过期(有效期1个月)',
        '1010': '此卡正在处理中',
        '10000': '未知错误',
        '2005': '此卡已使用',
        '2006': '卡密在系统处理中',
        '2007': '该卡为假卡',
        '2008': '该卡种正在维护',
        '2009': '浙江省移动维护',
        '2010': '江苏省移动维护',
        '2011': '福建省移动维护',
        '2012': '辽宁省移动维护',
        '2013': '该卡已被锁定',
        '2014': '系统繁忙,请稍后再试',
        '3001': '卡不存在',
        '3002': '卡已使用过',
        '3003': '卡已作废',
        '3004': '卡已冻结',
        '3005': '卡未激活',
        '3006': '密码不正确',
        '3007': '卡正在处理中',
        '3101': '系统错误',
        '3102': '卡已过期'
    }

    xml_dom = minidom.parseString(post_data)
    root_dom = xml_dom.getElementsByTagName("Request")[0]

    order_id = getNodeTextByTagName(root_dom, 'FLOrderId')
    query_id = getNodeTextByTagName(root_dom, 'OrderId')
    #product_id = getNodeTextByTagName(root_dom,'ProductId')
    card_no = getNodeTextByTagName(root_dom, 'CardNO')
    amount = getNodeTextByTagName(root_dom, 'Amount')
    result = getNodeTextByTagName(root_dom, 'Ret')
    result_code = getNodeTextByTagName(root_dom, 'CardStatus')
    custom = getNodeTextByTagName(root_dom, 'MerPriv')
    sign = getNodeTextByTagName(root_dom, 'VerifyString')

    sign_str = '%s|%s|%s|%s|%s|%s|%s|%s' % (order_id, query_id, product_id,
                                            card_no, amount, result,
                                            result_code, custom)

    sign_str_src = decrypt_with_rsa_feiliu(sign)
    print(sign_str, sign_str_src)

    pay_amount = 0
    remark = ''
    if sign_str == sign_str:
        try:

            if int(result) == 1:
                pay_amount = float(amount) / 100
            else:
                pay_amount = 0
                remark = status.get(result_code, '未知错误')

            result_msg = 1
        except Exception, e:
            result_msg = -1
            print('confirm feiliu has error', e)
Beispiel #7
0
def pay_feiliu(pay_action, pay_channel={}, host_ip='service.fytxonline.com'):
    from services.alipay import encrypt_with_rsa_feiliu, getNodeTextByTagName
    product_id = '100003'
    company_id = '100004'
    channel_list = {
        '0000840000': '100002',
        '0000990000': '100003',
        '0001000000': '100004',
        '0001010000': '100005',
        '0001020000': '100006',
        "0001650000": "100661",
        "0001660000": "100662",
        "0001670000": "100663",
        "0001680000": "100664",
        "0001690000": "100665"
    }
    channel_id = channel_list.get(
        pay_action.channel_key,
        pay_channel.get_config_value(pay_action.channel_key, '100002'))
    '''
    pay_channel.link_id = 103
    pay_action.query_id = '10000410000001'
    pay_action.post_amount = 10
    pay_action.pay_amount = 100
    pay_action.card_no = '12295150269929492'
    pay_action.card_pwd = '151728418901161405'
    '''
    custom = ''

    #OrderId|ProductId|CompanyId|ChannelId|OrderType|Denomination|CardNO|CardPwd|Amount|MerPriv
    sign_str = u'%s|%s|%s|%s|%s|%s|%s|%s|%s|%s' % (
        pay_action.query_id, product_id, company_id, channel_id,
        pay_channel.link_id, pay_action.post_amount, pay_action.card_no,
        pay_action.card_pwd, pay_action.post_amount * 100, custom)

    sign = encrypt_with_rsa_feiliu(sign_str.encode('utf-8'))
    #print(sign_str,sign)
    post_data = '''<Request>
                        <OrderId>%s</OrderId>
                        <ProductId>%s</ProductId>
                        <CompanyId>%s</CompanyId>
                        <ChannelId>%s</ChannelId>
                        <OrderType>%s</OrderType>
                        <Denomination>%s</Denomination>
                        <CardNO>%s</CardNO>
                        <CardPwd>%s</CardPwd>
                        <Amount>%s</Amount>
                        <MerPriv>%s</MerPriv>
                        <VerifyString>%s</VerifyString>
                    </Request>''' % (
        pay_action.query_id, product_id, company_id, channel_id,
        pay_channel.link_id, pay_action.post_amount, pay_action.card_no,
        pay_action.card_pwd, pay_action.post_amount * 100, custom, sign)
    #print(post_data)
    pay_url = 'http://pay.feiliu.com/order/billinterfacepython'
    result_code = 0
    result_msg = ''
    #    if True:
    try:
        result = http_post(pay_url, post_data, 'xml')

        if result != '':
            xml_dom = minidom.parseString(result)
            xml_root = xml_dom.documentElement
            return_code = getNodeTextByTagName(xml_root, 'Ret')
            if return_code == '0':
                result_code = 1
            else:
                result_code = 0
            result_msg = getNodeTextByTagName(xml_root, 'RetMsg')
    except Exception, e:
        print('pay feiliu has error', e)
Beispiel #8
0
        print '1cmmm query_order error::'
        print ex
        try:
            order_status_xml = http_post(request_url, request_xml)
        except Exception, ex:
            print '2cmmm query_order error::'
            print ex

    try:

        print 'order_status_xml::'
        print order_status_xml
        order_status_xml = minidom.parseString(order_status_xml)
        r_trans = order_status_xml.getElementsByTagName(
            "Trusted2ServQueryResp")[0]
        rcode = getNodeTextByTagName(r_trans, "ReturnCode")

        rcode = int(rcode)
        remark = code_map.get(rcode, '查单未知错误')
        TotalPrice = 0
        ExData = ''
        if rcode == 0:
            result_code = 0
            TotalPrice = float(getNodeTextByTagName(r_trans, "TotalPrice"))
            ExData = getNodeTextByTagName(r_trans, "ExData")

    except Exception, ex:
        result_code = -1
        print 'cmmm query order parser xml error'
        print ex
Beispiel #9
0
def confirm_gash(request, pay_channel={}):
    # 取得回傳結果

    transData = request.POST.get('data')

    #print 'confirm code:::', transData

    #file_object = open('/data/gash_response_file.txt', 'w')
    #file_object.write(transData)
    #file_object.close()

    # 解析回傳結果
    trans = base64.decodestring(transData)

    #print 'trans:::', trans

    trans = minidom.parseString(trans)
    trans = trans.getElementsByTagName("TRANS")
    trans = trans[0]

    rcode = getNodeTextByTagName(trans, "RCODE")
    coid = getNodeTextByTagName(trans, "COID")
    cid = getNodeTextByTagName(trans, "CID")
    erpc = getNodeTextByTagName(trans, "ERPC")
    rrn = getNodeTextByTagName(trans, "RRN")
    cuid = getNodeTextByTagName(trans, "CUID")
    amount = getNodeTextByTagName(trans, "AMOUNT")
    #product_id = getNodeTextByTagName(trans, "PRODUCT_ID")
    paid = getNodeTextByTagName(trans, "PAID")
    #memo = getNodeTextByTagName(trans, "MEMO")

    platform = get_platform(cid)
    #cid = gash_cfg.get(platform).get('CID')
    #print (cid, coid, rrn, cuid, amount, rcode, platform)
    server_sign = get_erpc(cid, coid, rrn, cuid, amount, rcode, platform)

    #print 'sign begin:::'
    #print (erpc,server_sign)

    #自己用的参数
    pay_amount = 0
    order_id = ''
    result_msg = 'error'
    remark = ''
    query_id = coid
    link_id = ''
    if erpc == server_sign and erpc != "" and server_sign != "":

        if rcode == "0000":
            try:
                remark = json.dumps({
                    'coid': coid,
                    'paid': paid,
                    'amount': amount,
                    'cid': cid
                })
                settle_rcode = settle(coid, paid, amount, cid)
                settle_rcode = settle_rcode.strip()
                order_id = rrn
                if "0000" == settle_rcode:
                    print 'settle success:::'
                    gash_point = float(amount)

                    cuid = cuid.strip().upper()
                    link_id = cuid
                    if get_erp_id(paid) == 'PINHALL':
                        if cuid == 'MYR':
                            gash_point = gash_point * 9.6
                        elif cuid == 'HKD':
                            gash_point = gash_point * 0.38
                    pay_amount = gash_point
                    print ' final pay_amount:::', pay_amount
                    result_msg = '儲值成功'
                else:
                    pay_amount = 0
                    #remark = gash_cfg.get('error_msg').get(settle_rcode, '')
                    result_msg = '請款失敗: <!-- %s -->' % remark
            except Exception, ex:
                print 'gash comfirm error   ', coid, ex
                pay_amount = 0
                remark = ex
                result_msg = '系統內部錯誤 <!-- %s -->' % remark
        else:
            remark = gash_cfg.get('error_msg').get(rcode, '')
            result_msg = remark
Beispiel #10
0
        except:
            print 'soap request settle error ', query_id, ex
            return ''

    print 'settle send code ::', query_id, trans
    print 'settle code ::', query_id, result

    result = base64.decodestring(result)

    try:

        result = minidom.parseString(result)

        r_trans = result.getElementsByTagName("TRANS")[0]

        rcode = getNodeTextByTagName(r_trans, "RCODE")

    except Exception, ex:
        print 'settle xml parser error ', query_id, ex
        return ''

    return rcode


def check_order(query_id, pay_type, amount, cid):
    rcode = ''

    request_url = gash_cfg.get('checkorder_url')

    client = None
    if '' == rcode: