示例#1
0
def get_qqv3(app_secret, get_url, params, is_post=False):
    query_host = 'http://openapi.3g.qq.com'
    #    query_host = 'http://119.147.19.43'
    import hmac, hashlib, base64
    method_str = 'GET'
    if is_post:
        method_str = 'POST'
    sign = '%s&%s&%s' % (method_str, urllib.quote(
        get_url, ''), urllib.quote(params, ''))
    #    print(params,sign)
    hashed = hmac.new('%s&' % app_secret, sign, hashlib.sha1)
    sign = base64.encodestring(hashed.digest())
    sign = urllib.quote(sign[:-1], '')
    if is_post:
        params = '%s&sig=%s' % (params, sign)
        get_url = '%s%s' % (query_host, get_url)
        #        print(get_url)
        result = http_post(get_url, params, timeout_param=5)
    else:
        get_url = '%s%s?%s&sig=%s' % (query_host, get_url, params, sign)
        #        print(get_url)
        result = http_post(get_url, timeout_param=5)


#    print(result,get_url,params)
    return result
示例#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'})
示例#3
0
def query_a360(request):
    g = lambda x, y: request.POST.get(x, y)
    code = g('code', '')
    t = g('t', '')
    client_id = 'cb26fca917fa06404ad43fbd5f68b2b1'
    client_secret = 'd922f3b4d08aa5fb3f29aeb592213d15'
    if 'c1wan' == t:
        client_id = '296b209cdc14817feb19adf4dfca7e61'
        client_secret = '24ff2c281606b475a7f3cede20f09565'
    elif 'youai360bssg' == t:
        client_id = g('client_id', '24903cebad0aa882443fc8cfd24650ae')
        client_secret = 'f450b94ce27a05f0700cc01cb546857f'

    request_url = 'https://openapi.360.cn/oauth2/access_token'
    userinfo_url = 'https://openapi.360.cn/user/me.json'

    grant_type = 'authorization_code'  #定值
    redirect_uri = 'oob'  #定值

    request_url = '%s?grant_type=%s&code=%s&client_id=%s&client_secret=%s&redirect_uri=%s' % (
        request_url, grant_type, code, client_id, client_secret, redirect_uri)

    result_code = 1
    result_msg = ''
    link_key = ''
    sign = ''
    access_token = ''
    try:
        data_result = http_post(request_url)
        data_result = json.loads(data_result)
        access_token = data_result.get('access_token', '')  #Access Token 值
        expires_in = data_result.get('expires_in', '')  #Access Token 的有效期 以秒计
        refresh_token = data_result.get('refresh_token',
                                        '')  #用于刷新 Access Token的 Token, 有效期 14天
        scope = data_result.get(
            'scope', '')  #Access Token 最终的访问范围,即用户实际授予的权限列表当前只 支持值 basic

        #查询用户信息
        #access_token  Y  授权的 access token
        #fields   N  允许应用自定义返回字段,多个属性之间用英文半角逗号作为分   隔符。不传递此参数则缺省返回 id,name,avatar
        #?access_token=12345678983b38aabcdef387453ac8133ac3263987654321&fields=id,name,avatar,sex,area
        if access_token != '':
            userinfo_url = '%s?access_token=%s&fields=id' % (userinfo_url,
                                                             access_token)
            user_info = http_post(userinfo_url)
            user_info = json.loads(user_info)
            link_key = user_info.get('id', '')
            if link_key != '':
                result_code = 0
        else:
            result_msg = u'会话已过期,请重新登陆'

        timestamp = int(time.time())
        mykey = 'boluoboluomi'
        sign = md5(('%s%s%s') % (link_key, timestamp, mykey))
    except Exception, ex:
        result_msg = 'internal error'
        print ex
示例#4
0
def pay_mycard(the_action, pay_channel={}, host_ip='service.fytxonline.com'):
    #from suds.client import Client
    result_code = 0
    result_msg = ''

    key1 = pay_channel.get_config_value('key1', 'mycardFGPG')
    key2 = pay_channel.get_config_value('key2', 'qwer2571')
    #    if True:
    try:
        sign = '%s%s%s%s' % (key1, pay_channel.link_id, the_action.query_id,
                             key2)
        sign = hash256(sign)
        query_data = 'facId=%s&facTradeSeq=%s&hash=%s' % (
            pay_channel.link_id, the_action.query_id, sign)
        query_url = 'http://test.b2b.mycard520.com.tw/MyCardInservices/Auth?%s' % query_data
        result = http_post(query_url)
        result = json.loads(result)
        print(query_url, result)
        auth_code = result.get('AuthCode', None)
        if result.get('ReturnMsgNo', 0) == 1 and auth_code != None:

            sign = '%s%s%s%s%s%s%s' % (key1, pay_channel.link_id, auth_code,
                                       the_action.pay_user, the_action.card_no,
                                       the_action.card_pwd, key2)
            sign = hash256(sign)

            query_data = 'facId=%s&authCode=%s&facMemId=%s&cardId=%s&cardPwd=%s&hash=%s' % (
                pay_channel.link_id, auth_code, the_action.pay_user,
                urllib.quote(the_action.card_no),
                urllib.quote(the_action.card_pwd), sign)
            query_url = 'http://test.b2b.mycard520.com.tw/MyCardInservices/Confirm?%s' % query_data

            result = http_post(query_url)
            print(query_url, result)
            result = json.loads(result)

            if result.get('ReturnMsgNo', 0) == 1:
                the_action.order_id = the_action.card_no
                the_action.pay_status = 2
                the_action.pay_amount = float(result.get('CardPoint', 0))
                the_action.pay_gold = pay_channel.get_gold(
                    the_action.pay_amount)
                the_action.extra = pay_channel.get_extra(the_action.pay_gold)

                result_code = 1
            else:
                the_action.pay_status = -2
        else:
            the_action.pay_status = -2

        the_action.remark = result.get('ReturnMsg', '')  #.encode('utf-8')
        the_action.save(using='write')
        result_msg = the_action.remark
    except Exception, e:
        result_code = -1
        print('pay mycard has error', e)
示例#5
0
def pay_mycard_billing_go(request,action_id=0):
    action_id = int(action_id)
    pay_amount = int(request.GET.get('pay_amount','10'))
    server_code = request.GET.get('server_code','')

    the_action = PayAction.objects.get(id=action_id)
    pay_channel = PayChannel.objects.using('read').get(id=the_action.pay_type)
    the_action.post_amount = pay_amount
    the_action.remark = server_code
    the_action.save(using='write')

    #http://test.b2b.mycard520.com.tw/MyCardBillingRESTSrv/MyCardBillingRESTSrv.svc/Auth/SPS0124691/0001/150
    #http://test.b2b.mycard520.com.tw/MyCardBillingRESTSrv/MyCardBillingRESTSrv.svc/ProductsQuery/FGPG
    #http://test.b2b.mycard520.com.tw/MyCardBillingRESTSrv/MyCardBillingRESTSrv.svc/PaymentsQuery/FGPG/FGPG50
    #http://test.b2b.mycard520.com.tw/MyCardBilling/?AuthCode=395EEA9448BCA7EFF32F6FA16337B8F2A995600E6E964F02
    auth_url = 'https://b2b.mycard520.com.tw/MyCardBillingRESTSrv/MyCardBillingRESTSrv.svc/Auth/%s/%s/%s'%(server_code,the_action.query_id,pay_amount)
    auth_result = http_post(auth_url)
    print(auth_result)
    reb = re.compile('<[^<]+>')
    auth_result = reb.sub('',auth_result)
    result_code,result_msg,order_id,auth_code = auth_result.split('|')

    if result_code=='1':
        the_action.order_id = order_id
        the_action.remark = auth_code
        the_action.save(using='write')
        pay_url = 'http://www.mycard520.com.tw/MyCardBilling/?AuthCode=%s'%auth_code
        return HttpResponseRedirect(pay_url)
    else:
        return render_to_response('pay/confirm_mycard_billing.html',locals())
示例#6
0
def query_order(TradeID,
                OrderID,
                AppID='300002904622',
                request_url='http://ospd.mmarket.com:8089/trust'):

    result_code = 1
    TotalPrice = 0
    ExData = ''
    remark = ''

    #0:测试订单
    #1:正式订单

    #    <?xml version=\"1.0\"
    #    standalone=\"yes\"?><Trusted2ServQueryReq><MsgType>Trusted2ServQueryReq
    #    </MsgType><Version>1.0.0</Version><OrderID>********</OrderID><AppID>300
    #    00*******</AppID><OrderType>1</OrderType></Trusted2ServQueryReq>
    code_map = {
        0: "用户已订购,存在对应订单 ",
        2: "用户未订购,不存在对应订单",
        11: "没有授权调用该能力 ",
        12: "能力服务忙 ",
        13: "其他,平台未知错误 ",
        17: "数字签名不正确 ",
        18: "请求能力不存在 ",
        19: "应用不存在"
    }

    request_xml = '<?xml version="1.0" encoding="UTF-8"?><Trusted2ServQueryReq><MsgType>%s</MsgType><Version>%s</Version><AppID>%s</AppID><OrderID>%s</OrderID><TradeID>%s</TradeID><OrderType>%s</OrderType></Trusted2ServQueryReq>'

    request_xml = request_xml % ('Trusted2ServQueryReq', '1.0.0', AppID,
                                 OrderID, TradeID, 0)

    order_status_xml = ''
    try:
        order_status_xml = http_post(request_url, request_xml)
    except Exception, ex:
        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
示例#7
0
def pay_alipay_web_new(pay_action,
                       pay_channel={},
                       host_ip='service.fytxonline.com'):
    from services.alipay import sign_with_rsa, decrypt_with_rsa
    pay_url = ''

    private_key = pay_channel.get_config_value(
        'private_key', '''-----BEGIN RSA PRIVATE KEY-----
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBANQR95kNNrHo4glxvmdEn1Bma5U24NgOLl1EMF+4Ciw4fOC8TZzjw7rXqgRgI6NWXdDOmN2B140LNjXBly7Beq3qKOHhrWinzseRONkGU3wPeJO5VNjnCWU1m8fXilMhQHaHfdjvAh4aiZV1QZVewmjG7qs6iUaM1UxvprhzraKRAgMBAAECgYEAmROnD7k0A9PAZWTPNaeY/+YOPhTw08PYv8XazR0Bas4Thf0mYNsfi5zkwmfLEbnj2jdmrG1u9AZlyQPGZx+Ntu6ukzQk4NfKWLfKyOIB4OJ+rNeGZBiSir5j8C5+iMjOZQBAzdEJOwCx9B13bwP5RWHUmUZ8dLvdxt7+6djDSAECQQD5LviTQ9xP3bSchPVyjvhkz152PAlwC7uR4y46+xb2feaN0qu+zhXx18jSmNwojMWn24s1eu68ujrI0jCoKxxBAkEA2d8XmpXPP6XqUzPLF0lUyiBSB2lQp9JMSOlCAbKvS+Tk/NR/ufy0JmqfNrjkAnvv4lBKoqzPGpwLYYJS9UUyUQJAAm0Aon5goK5p2bQ5p3nY1TJnmwMOnHagxtTNWGmlWZT0L6FDZsIe2JHfNJ2kVwi3y+CJRGYD+PZfKCFTs+9ngQJAI0TC/Go9527DVP6wZK+hQysiPELnJJOdd7wSzFWRnPaLvwXjO0dWHlXqOiCKAIDxnzAiNN1GlWcnTHydU0kFUQJAa54pvMY6XYQoSbsFfjL2v5Xl1NyqJRTekThpzrm+GDHh592PWvkupppNHAezvaassfgb2/iJTk+foMFfPC6Szw==
-----BEGIN RSA PRIVATE KEY-----''')
    partner = pay_channel.get_config_value('partner', '2088801536938559')
    seller = pay_channel.get_config_value('seller', '*****@*****.**')

    subject = pay_channel.get_config_value('subject', '风云天下金币充值')

    req_data = '''<direct_trade_create_req><subject>%s</subject><out_trade_no>%s</out_trade_no><total_fee>%d</total_fee><seller_account_name>%s</seller_account_name><call_back_url>http://%s/service/callback/alipay_web_new</call_back_url><notify_url>http://%s/service/confirm/alipay_web_new</notify_url><out_user>%d</out_user></direct_trade_create_req>''' % (
        subject, pay_action.query_id, pay_action.post_amount, seller, host_ip,
        host_ip, pay_action.pay_user)

    post_data = 'format=xml&partner=%s&req_data=%s&req_id=%d&sec_id=0001&service=alipay.wap.trade.create.direct&v=2.0' % (
        partner, req_data, int(time.time() * 10))

    sign = sign_with_rsa(post_data, private_key)
    sign = urllib2.quote(sign)
    post_data = '%s&sign=%s' % (post_data, sign)

    query_url = 'http://wappaygw.alipay.com/service/rest.htm'

    result = http_post(query_url, post_data)
    #    print(post_data,result)
    if result.find('res_error') == -1:
        result = ('{"%s"}' % result).replace('=', '":"').replace('&', '","')
        result = json.loads(result).get('res_data', '')

        result = urllib2.unquote(result)
        result = decrypt_with_rsa(result, private_key)
        print(result)
        reb = re.compile('<[^<]+>')
        result = reb.sub('', result)
        print(result)

        req_data = '<auth_and_execute_req><request_token>%s</request_token></auth_and_execute_req>' % result

        post_data = 'format=xml&partner=%s&req_data=%s&sec_id=0001&service=alipay.wap.auth.authAndExecute&v=2.0' % (
            partner, req_data)

        sign = sign_with_rsa(post_data, private_key)
        sign = urllib2.quote(sign)
        post_data = '%s&sign=%s' % (post_data, sign)
        pay_url = '%s?%s' % (query_url, post_data)
    else:
        pass
    return (0, pay_url)
示例#8
0
def confirm_so_cayenne(request, pay_channel={}):
    g = lambda x, y: request.GET.get(x, request.POST.get(x, y))
    server_id = int(g('serverID', 0))
    player_id = int(g('playerID', 0))
    result_list = []
    orderID = g('orderID', '')
    print 'get param server_id:%d' % server_id
    print 'get param player_id:%d' % player_id

    print 'get request:%s' % request
    request_url = 'http://gameapi.wasabiiapps.com.tw/gameserver/query_consume.json'
    print 'start post'
    print orderID
    print 'end get orders'
    orders = [{}]
    orders[0]['order-id'] = orderID
    #    orders_str = '%s'% orders
    orders_str = 'orders[0][order-id]'
    #    return result_list
    #    result = http_post(request_url, '&orders=%s&order-id=%s' % (urllib.quote_plus(orders, ''), urllib.quote_plus(order_id, '')) )
    print 'request_url is %s' % request_url
    print 'orders_str is %s' % orders_str
    #    result = http_post(request_url, '%s' % (urllib.quote_plus(orders_str, '')) )
    result = http_post(request_url,
                       '&%s=%s' % (urllib.quote_plus(orders_str, ''), orderID))
    print 'get post:%s' % result
    order_list = get_order_list(result)

    currency = 0
    amount = 0
    remark = ''
    result_msg = ''
    if type(order_list) == int:
        result_msg = '%s' % order_list
    else:
        for item in order_list:
            order_id = item.get('order-id')
            amount = int(item.get('consume-point'), 10) / 5.0
            #            amount = item.get('item-amount', '')
            remark = ''
            result_msg = 0
            result_list.append({
                'server_id': server_id,
                'currency': currency,
                'player_id': player_id,
                'order_id': order_id,
                'amount': amount,
                'remark': remark,
                'result_msg': result_msg
            })

    return result_list
示例#9
0
def pay_alipay_web(pay_action,
                   pay_channel={},
                   host_ip='service.fytxonline.com'):
    from services.alipay import sign_with_rsa_ali, decrypt_with_rsa_ali
    pay_url = ''

    partner = pay_channel.get_config_value('partner', '2088801536938559')
    seller = pay_channel.get_config_value('seller', '*****@*****.**')

    subject = pay_channel.get_config_value('subject', '风云天下金币充值')

    req_data = '''<direct_trade_create_req><subject>%s</subject><out_trade_no>%s</out_trade_no><total_fee>%d</total_fee><seller_account_name>%s</seller_account_name><call_back_url>http://%s/service/callback/alipay_web</call_back_url><notify_url>http://%s/service/confirm/alipay_web</notify_url><out_user>%d</out_user></direct_trade_create_req>''' % (
        subject, pay_action.query_id, pay_action.post_amount, seller, host_ip,
        host_ip, pay_action.pay_user)

    post_data = 'format=xml&partner=%s&req_data=%s&req_id=%d&sec_id=0001&service=alipay.wap.trade.create.direct&v=2.0' % (
        partner, req_data, int(time.time() * 10))

    sign = sign_with_rsa_ali(post_data)
    sign = urllib2.quote(sign)
    post_data = '%s&sign=%s' % (post_data, sign)

    query_url = 'http://wappaygw.alipay.com/service/rest.htm'

    result = http_post(query_url, post_data)
    #    print(post_data,result)
    if result.find('res_error') == -1:
        result = ('{"%s"}' % result).replace('=', '":"').replace('&', '","')
        result = json.loads(result).get('res_data', '')

        result = urllib2.unquote(result)
        result = decrypt_with_rsa_ali(result)
        print(result)
        reb = re.compile('<[^<]+>')
        result = reb.sub('', result)
        print(result)

        req_data = '<auth_and_execute_req><request_token>%s</request_token></auth_and_execute_req>' % result

        post_data = 'format=xml&partner=%s&req_data=%s&sec_id=0001&service=alipay.wap.auth.authAndExecute&v=2.0' % (
            partner, req_data)

        sign = sign_with_rsa_ali(post_data)
        sign = urllib2.quote(sign)
        post_data = '%s&sign=%s' % (post_data, sign)
        pay_url = '%s?%s' % (query_url, post_data)
    else:
        pass
    return (0, pay_url)
示例#10
0
def return_data(appid, mac, idfa):
    result_msg = "fail"
    #http://e.domob.cn/track/ow/api?appId=531266294&udid=7C:AB:A3:D6:E7:81&ifa=511F7987-6E2F-423A-BFED-E4C52CB5A6DC&acttime=1391502359&returnFormat=1
    try:
        request_url = 'http://e.domob.cn/track/ow/api/postback?appId=%s&udid=%s&ifa=%s&acttime=%s&returnFormat=1&sign=%s' % (appid, mac, idfa, int(time.time()), getDomobSign(appid, mac, '', idfa, '', 'cebbdcbd989326661878649d6565f719'))
        request_data = http_post(request_url, timeout_param = 5) 
        json_data = json.loads(request_data)
        status = json_data.get('success', False)
        message = json_data.get('message', '')
        if status:
            result_msg = "success"
        else:
            result_msg = message
        
    except Exception, ex:
        print 'dianru error ', ex
        result_msg = "internal error"
示例#11
0
def query_songgang(request):
    '''客户端给的充值成功消息
    /service/query/songgang?orderId=502_526385358_1404200092771&transId=PPK237301685&itemChange=fal
se&payName=%E9%87%91%E5%B8%81&amount=60.0&paymentID=38&serverId=502&playerId=526385358
    CHECKCODE規則:MD5(TransactionKey+”*”+SHOPID+”*”+ORDERID+”*”+TransactionKey)
    '''
    check_url = 'http://www.pay168.com.tw/purepay/online/CheckTransStatus.aspx'
    app_key = 'sx#Ud#S4YR6t5P6*st'
    request.POST._mutable = True  #
    request.GET._mutable = True  #可以是使用reuqest.GET.setlist('key',value)方法
    SHOPID = 13121601
    rq = request.REQUEST

    ORDERID = rq.get('orderId', '')
    transId = rq.get('transId', '')
    itemChange = rq.get('itemChange', '')
    payName = rq.get('payName', '')
    amount = rq.get('amount', '')
    paymentID = rq.get('paymentID', '')
    serverId = rq.get('serverId', '')
    playerId = rq.get('playerId', '')

    CHECKCODE = md5('%s*%s*%s*%s' % (app_key, SHOPID, ORDERID, app_key))
    query_data = 'SHOPID=%s&ORDERID=%s&CHECKCODE=%s' % (SHOPID, ORDERID,
                                                        CHECKCODE)
    check_url = '%s?%s' % (check_url, query_data)
    response = http_post(check_url, query_data)
    r = convert_songgong_response(response)
    print r
    if r.get('TRANSACTIONSTATUS',
             '') == '0' and serverId and playerId:  #设置回调的参数
        transactionID = r.get('TRANSACTIONID', '')

        request.POST.setlist('payName', [payName])
        request.POST.setlist('payDesc', ['%s_%s' % (serverId, playerId)])
        request.POST.setlist('itemCode', [''])
        request.POST.setlist('money', [amount])
        request.POST.setlist('orderId', [ORDERID])
        request.POST.setlist('transactionID', [transactionID])
        request.POST.setlist('itemChange', [itemChange])
        sign = md5('%s%s%s' % (transactionID, app_key, amount))
        request.POST.setlist('Sig', [sign])
        return confirm(request, 'songgang')
    return HttpResponse('0')
示例#12
0
def confirm_paypal(request, pay_channel={}):
    pp_url = pay_channel.get_config_value(
        'pp_url', 'https://www.sandbox.paypal.com/cgi-bin/webscr')
    #print(request.POST)
    newparams = {}
    for key in request.POST.keys():
        newparams[key] = request.POST.get(key, '').encode('utf-8')

    newparams["cmd"] = "_notify-validate"
    print(newparams)
    params = urllib.urlencode(newparams)
    result_msg = 'fail'

    #    print(params)
    pay_amount = 0
    server_id, player_id = (0, 0)
    order_id = ''
    try:
        ret = http_post(pp_url, params)
        print('response', ret)

        server_id, player_id = newparams.get('custom', '').split('-')

        server_id = int(server_id)
        player_id = int(player_id)

        order_id = newparams.get('txn_id', '')
        if ret != "VERIFIED":

            print(" verified send back ok\n")

            if newparams.get('payment_status', '') == 'Completed':
                pay_amount = float(newparams.get('mc_gross', '0'))

            result_msg = '200 OK'

        else:
            print(" ERROR did not verify\n")
    except Exception, e:
        print('confirm paypal has error', e)
示例#13
0
def confirm_kuaiyong(request, pay_channel):
    public_key = pay_channel.get_config_value("key", default_public_key)
    verify_url = "http://service.yhzbonline.com/service/query/kuaiyong"

    #print request.POST
    p = lambda x, y='': request.POST.get(x, y)
    notify_data = p("notify_data")
    orderid = p("orderid")
    dealseq = p("dealseq")
    uid = p("uid")
    subject = p("subject")
    ver = p("v")
    sign = p("sign")

    server_id = player_id = pay_amount = 0
    order_id = remark = result_msg = ""

    try:
        pub_key = get_m2c_pub(public_key)
        nd = decrypt(notify_data, pub_key)
        nd = url_decode(nd) if nd else {}

        sign_con = "dealseq=" + dealseq + "&notify_data=" + notify_data + "&orderid=" + orderid + "&subject=" \
                   + subject + "&uid=" + uid + "&v=" + ver

        verify_result = http_post(
            verify_url, "data=%s&sign=%s" %
            (base64.b64encode(sign_con), urllib.quote(sign)))
        if int(verify_result) == 1:
            extra_info = dealseq.split("_")
            server_id = int(extra_info[0])
            player_id = int(extra_info[1])
            order_id = orderid
            pay_amount = float(nd["fee"])
            result_msg = "success"
        else:
            result_msg = "fail"
    except Exception, e:
        import traceback
        traceback.print_exc()
示例#14
0
def do_exchangerecharge(userid, server_id, player_id, ip, pids_str,
                        currenttime, now_date, app_key):

    request_url = 'http://local.rrgdev.org/u.exchangerecharge.php'

    print 'exchangerechange begin:::'

    pdata = global_param(server_id, currenttime, now_date)

    sign = ''
    sign = sign + 'areaid=%s' % pdata['areaid']
    sign = sign + 'currenttime=%s' % pdata['currenttime']
    sign = sign + 'domain=%s' % pdata['domain']
    sign = sign + 'gamecode=%s' % pdata['gamecode']
    sign = sign + 'ip=%s' % ip
    sign = sign + 'pids=%s' % pids_str
    sign = sign + 'platformid=%s' % pdata['platformid']
    sign = sign + 'serverid=%s' % pdata['serverid']
    sign = sign + 'timestamp=%s' % pdata['timestamp']
    sign = sign + 'userid=%s' % userid
    sign = sign + app_key

    sign = md5(sign)

    #私有参数
    pdata['userid'] = userid
    pdata['pids'] = pids_str
    pdata['ip'] = ip
    pdata['sig'] = sign

    post_data = urllib.urlencode(pdata)

    result_data = http_post(request_url, post_data)

    #    file_object = open('/data/renren_exchangerecharge.log', 'w')
    #    file_object.write(result_data)
    #    file_object.close()
    #    print 'exchangerechange end:::'
    return get_order_list(result_data)
示例#15
0
def settle(query_id, status, gamecode, key, settle_url):
    sign = md5('%s%s%s' % (query_id, status, key))
    post_data = '''<?xml version="1.0" encoding="GBK"?>
                    <order>
                    <tradnum>%s</tradnum>
                    <status>%s</status>
                    <checking>%s</checking>
                    <gamecode>%s</gamecode>
                    </order>''' % (query_id, status, sign, gamecode)

    try:
        print 'settle post_data:::', post_data
        result_data = http_post(settle_url, post_data)
        print 'settle result_data:::', result_data
        result_data = result_data.replace('GBK', 'utf-8')
        result_data = parse_settle_data(result_data)
        if query_id == result_data['tradnum'] and 'success' == result_data[
                'result']:
            return True
        return False

    except Exception, ex:
        print ex
        print 'settle error'
示例#16
0
def confirm_mycard_billing(request,pay_channel={}):

    trade_no = request.POST.get('TradeSeq','')
    result_code = request.POST.get('ReturnMsgNo','')
    result_msg = request.POST.get('ReturnMsg','')
    auth_code = request.POST.get('AuthCode','')
    pay_actions = []
    try:
        if trade_no!='' and result_code == '1':
            pay_actions = PayAction.objects.filter(query_id=trade_no)

            if len(pay_actions) > 0:
                the_action = pay_actions[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'%auth_code
                check_result = http_post(check_url) #查询充值结果
                reb = re.compile('<[^<]+>')
                check_result = reb.sub('',check_result)
                print(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,auth_code)
                    confirm_result = http_post(confirm_url) #申请扣款
                    confirm_result = reb.sub('',confirm_result)
                    print(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' and the_action.pay_status < 2:
                        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) 
                        result_msg = '儲值成功!'
                else:
                    the_action.pay_status = -2

                the_action.remark = result_msg

                the_action.save(using='write')
        else:
            if len(pay_actions) > 0:
                the_action = pay_actions[0]
                the_action.pay_status = -2
                the_action.remark = result_msg
                the_action.save(using='write')

            try:
                result_msg = urllib.unquote(result_msg)
                result_msg = result_msg.decode('utf-8')
            except Exception,e:
                result_msg = '儲值失敗.'
                print('recv msg mycard billing has error',e)
    except Exception,e:
        result_msg = '發生未知錯誤!'
        print('confirm mycard billing has error',e)
示例#17
0
def confirm_renren(request, pay_channel={}):

    result_list = []

    now_date = datetime.datetime.now()

    #查询用户订单信息
    request_url = 'http://local.rrgdev.org/u.queryrecharge.php'

    #20120912212950
    currenttime = now_date.strftime('%Y%m%d%H%M%S')

    app_key = pay_channel.get_config_value('app_id',
                                           '4F6944A57CD2879A42FCB20F6A1C1B5C')

    #私有参数
    ip = request.META['REMOTE_ADDR']
    player_id = int(request.GET.get('playerid', 0))
    server_id = int(request.GET.get('serverid', 0))

    err_msg = ''
    userid = None
    try:
        userid = getPlayer(server_id, player_id)
    except:
        err_msg = '用户无效'
        print 'error:::player_id not find'

    if None != userid:

        pdata = global_param(server_id, currenttime, now_date)

        sign = ''
        sign = sign + 'areaid=%s' % pdata['areaid']
        sign = sign + 'currenttime=%s' % pdata['currenttime']
        sign = sign + 'domain=%s' % pdata['domain']
        sign = sign + 'gamecode=%s' % pdata['gamecode']
        sign = sign + 'ip=%s' % ip
        #sign = sign + 'method=%s' % 'u.queryrecharge'
        sign = sign + 'platformid=%s' % pdata['platformid']
        sign = sign + 'serverid=%s' % pdata['serverid']
        sign = sign + 'timestamp=%s' % pdata['timestamp']
        sign = sign + 'userid=%s' % userid
        sign = sign + app_key

        sign = md5(sign)

        pdata['ip'] = ip
        pdata['userid'] = userid
        pdata['sig'] = sign

        post_data = urllib.urlencode(pdata)
        try:
            #print 'requset_url:::', request_url
            #print 'post_data:::', post_data
            result_data = http_post(request_url, post_data)
            #print 'result_data:::', result_data


#            file_object = open('/data/renren_response_file.txt', 'w')
#            file_object.write(result_data)
#            file_object.close()
        except Exception, ex:
            print 'query user order error'
            print ex
            err_msg = '网络出问题'

        order_list = get_order_list(result_data)

        if '' == err_msg:
            if type(order_list) == int:
                err_msg = error_map.get(order_list)
            else:
                #                file_object = open('/data/renren_order.log', 'w')
                #                file_object.write(result_data)
                #                file_object.close()

                #pids = ','.join([item.get('id') for item in order_list])

                pids = []
                for item in order_list:
                    pids.append(item.get('id'))
                    order_id = item.get('order_id')
                    currency = item.get('currency', '')
                    amount = 0
                    remark = ''
                    result_msg = '充值失败,请重新请款'
                    result_list.append({
                        'server_id': server_id,
                        'currency': currency,
                        'player_id': player_id,
                        'order_id': order_id,
                        'amount': amount,
                        'remark': remark,
                        'result_msg': result_msg
                    })
                try:
                    pids = ','.join(pids)

                    try:
                        finish_order_list = do_exchangerecharge(
                            userid, server_id, player_id, ip, pids,
                            currenttime, now_date, app_key)
                    except Exception, ex:
                        print 'exchangerecharge error:'
                        print ex
                        err_msg = '网络出问题'

                    if '' == err_msg:
                        if type(finish_order_list) == int:
                            err_msg = error_map.get(finish_order_list)
                        else:

                            result_msg = 'success'
                            result_list = []
                            for item in finish_order_list:
                                order_id = item.get('order_id')
                                amount = float(item.get('amount', 0))
                                f_currency = item.get('currency', '')
                                amount = filter_amount_by_currency(
                                    f_currency, amount, pay_channel)
                                remark = ''
                                result_list.append({
                                    'server_id': server_id,
                                    'player_id': player_id,
                                    'order_id': order_id,
                                    'amount': amount,
                                    'remark': remark,
                                    'result_msg': result_msg
                                })
                except Exception, ex:
                    print 'internal error'
                    print ex
示例#18
0
                    <gamecode>%s</gamecode>
                    <tradnum>%s</tradnum>
                    <expand>%s</expand>
                    <pamt>%s</pamt>
                    <checking>%s</checking>
                    </order>
                    ''' % (the_action.card_no, gamecode, the_action.query_id,
                           '', pamt, sing)

    result_data = '1'

    order_status = ''
    try:
        print 'exchange_url:::', exchange_url
        print 'post_data:::', post_data
        result_data = http_post(exchange_url, post_data)
        print 'result_data:::', result_data
        result_data = result_data.replace('GBK', 'utf-8')
        result_data = parse_exchange_data(result_data)
        msg_map = {
            "0": "余额不足,兑换失败",
            "1": "订单成功(游戏平台暂时扣除游戏币)",
            "2": "验证错误",
            "3": "游戏不存在",
            "4": "用户不存在"
        }

        if the_action.query_id == result_data[
                'tradnum'] and gamecode == result_data['gamecode']:
            order_status = str(result_data['status'])
            if '1' == order_status:
示例#19
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)
示例#20
0
def pay_yeepay(pay_action, pay_channel={}, host_ip='service.fytxonline.com'):
    #    merchant_id = 10011733833
    #    merchant_key = 'GL257oHr34C5QM6o1Yf79sj56Cak907F5IMUy945IM832NvEj0D82B6qe83N'
    merchant_id = pay_channel.get_config_value('merchant_id', 10011847951)
    merchant_key = pay_channel.get_config_value(
        'merchant_key',
        'Z4eahK78Vz41418G3k7b26psaY23QGW29K5121W43Q00p5TLIANc4QcI283q')
    merchant_key = merchant_key.encode('ascii')
    product_name = pay_channel.get_config_value('product_name', 'gold')
    pay_type_key = pay_channel.get_config_value('pay_type_key', 'yeepay')
    confirm_url = '%s/service/confirm/%s' % (host_ip, pay_type_key)
    status = {
        '-1': '签名较验失败或未知错误',
        '1': '提交成功',
        '2': '卡密成功处理过或者提交卡号过于频繁',
        '5': '卡数量过多,目前最多支持10张卡',
        '11': '订单号重复',
        '66': '支付金额有误',
        '95': '支付方式未开通',
        '112': '业务状态不可用,未开通此类卡业务',
        '8001': '卡面额组填写错误',
        '8002': '卡号密码为空或者数量不相等'
    }

    if pay_channel == None:
        pay_channel = PayChannel.objects.using('read').get(
            id=pay_action.pay_type)

    data = [
        '', ('p0_Cmd', 'ChargeCardDirect'), ('p1_MerId', merchant_id),
        ('p2_Order', pay_action.query_id),
        ('p3_Amt', '%.2f' % pay_action.post_amount), ('p4_verifyAmt', 'false'),
        ('p5_Pid', product_name), ('p6_Pcat', ''), ('p7_Pdesc', ''),
        ('p8_Url', confirm_url), ('pa_MP', 'None'),
        ('pa7_cardAmt', '%.2f' % pay_action.post_amount),
        ('pa8_cardNo', pay_action.card_no),
        ('pa9_cardPwd', pay_action.card_pwd),
        ('pd_FrpId', pay_channel.link_id), ('pr_NeedResponse', '1')
    ]
    #print(data)
    origin_str = reduce(lambda x, y: "%s%s" % (x, urlquote(y[1])), data)

    origin_str = origin_str.encode("GBK")
    #print(origin_str)
    mac = hmac.new(merchant_key)
    mac.update(origin_str)
    sign_str = mac.hexdigest()
    query = "".join([
        "https://www.yeepay.com/app-merchant-proxy/command.action?",
        reduce(lambda x, y: "%s&%s=%s" % (x, y[0], urlquote(y[1])),
               data).lstrip("&"), "&hmac=", sign_str
    ])

    query = query.encode("GBK")
    result_code = 0
    result = ''
    try:
        result = http_post(query)
        for item in result.split('\n'):
            if item.split('=')[0] == 'r1_Code':
                result_code = item.split('=')[1]
                break
        result = status.get(result_code, '')
        result_code = int(result_code)
        print(query, result_code, result)
    except Exception, e:
        print('pay yeepay error:', e)