用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - python代码库

基于Python的lol充值api调用代码实例

2016-05-31 作者: juhe举报

[python]代码库

#!/usr/bin/python
# -*- coding: utf-8 -*-
import json, urllib
from urllib import urlencode
 
#----------------------------------
# 游戏充值调用示例代码 - 聚合数据
# 在线接口文档:http://www.juhe.cn/docs/88
#----------------------------------
 
def main():
 
    #配置您申请的APPKey
    appkey = "*********************"
 
    #1.商品小类列表
    request1(appkey,"GET")
 
    #2.商品信息
    request2(appkey,"GET")
 
    #3.商品价格查询
    request3(appkey,"GET")
 
    #4.游戏直充区服查询
    request4(appkey,"GET")
 
    #5.游戏直充
    request5(appkey,"GET")
 
    #6.订单状态查询
    request6(appkey,"GET")
 
 
 
#商品小类列表
def request1(appkey, m="GET"):
    url = "http://op.juhe.cn/ofpay/game/cardlist"
    params = {
        "key" : appkey, #应用APPKEY(应用详细页查询)
 
    }
    params = urlencode(params)
    if m =="GET":
        f = urllib.urlopen("%s?%s" % (url, params))
    else:
        f = urllib.urlopen(url, params)
 
    content = f.read()
    res = json.loads(content)
    if res:
        error_code = res["error_code"]
        if error_code == 0:
            #成功请求
            print res["result"]
        else:
            print "%s:%s" % (res["error_code"],res["reason"])
    else:
        print "request api error"
 
#商品信息
def request2(appkey, m="GET"):
    url = "http://op.juhe.cn/ofpay/game/cardinfo"
    params = {
        "cardid" : "", #对应接口1的cardid
        "key" : appkey, #应用APPKEY(应用详细页查询)
 
    }
    params = urlencode(params)
    if m =="GET":
        f = urllib.urlopen("%s?%s" % (url, params))
    else:
        f = urllib.urlopen(url, params)
 
    content = f.read()
    res = json.loads(content)
    if res:
        error_code = res["error_code"]
        if error_code == 0:
            #成功请求
            print res["result"]
        else:
            print "%s:%s" % (res["error_code"],res["reason"])
    else:
        print "request api error"
 
#商品价格查询
def request3(appkey, m="GET"):
    url = "http://op.juhe.cn/ofpay/game/cardprice"
    params = {
        "cardid" : "", #对应接口2的cardid
        "key" : appkey, #应用APPKEY(应用详细页查询)
 
    }
    params = urlencode(params)
    if m =="GET":
        f = urllib.urlopen("%s?%s" % (url, params))
    else:
        f = urllib.urlopen(url, params)
 
    content = f.read()
    res = json.loads(content)
    if res:
        error_code = res["error_code"]
        if error_code == 0:
            #成功请求
            print res["result"]
        else:
            print "%s:%s" % (res["error_code"],res["reason"])
    else:
        print "request api error"
 
#游戏直充区服查询
def request4(appkey, m="GET"):
    url = "http://op.juhe.cn/ofpay/game/areaserver"
    params = {
        "cardid" : "", #对应接口3的cardid
        "key" : appkey, #应用APPKEY(应用详细页查询)
 
    }
    params = urlencode(params)
    if m =="GET":
        f = urllib.urlopen("%s?%s" % (url, params))
    else:
        f = urllib.urlopen(url, params)
 
    content = f.read()
    res = json.loads(content)
    if res:
        error_code = res["error_code"]
        if error_code == 0:
            #成功请求
            print res["result"]
        else:
            print "%s:%s" % (res["error_code"],res["reason"])
    else:
        print "request api error"
 
#游戏直充
def request5(appkey, m="GET"):
    url = "http://op.juhe.cn/ofpay/game/order"
    params = {
        "cardid" : "", #商品编码,对应接口3的cardid
        "cardnum" : "", #购买数量
        "orderid" : "", #订单号,8-32位数字字母组合
        "game_userid" : "", #游戏玩家账号(game_userid=xxx@162.com$xxx001 xxx@162.com是通行证xxx001是玩家账号)
        "game_area" : "", #游戏所在区域,没有则不填,具体参照接口4返回,URLEncode UTF8
        "game_srv" : "", #游戏所在服务器,没有则不填,具体参照接口4返回,URLEncode UTF8
        "key" : appkey, #应用APPKEY(应用详细页查询)
        "sign" : "", #校验值,md5(<b>OpenID</b>+key+cardid+cardnum+orderid+game_userid+game_area+game_srv)
 
    }
    params = urlencode(params)
    if m =="GET":
        f = urllib.urlopen("%s?%s" % (url, params))
    else:
        f = urllib.urlopen(url, params)
 
    content = f.read()
    res = json.loads(content)
    if res:
        error_code = res["error_code"]
        if error_code == 0:
            #成功请求
            print res["result"]
        else:
            print "%s:%s" % (res["error_code"],res["reason"])
    else:
        print "request api error"
 
#订单状态查询
def request6(appkey, m="GET"):
    url = "http://op.juhe.cn/ofpay/game/ordersta"
    params = {
        "orderid" : "", #商家订单号,8-32位字母数字组合
        "key" : appkey, #应用APPKEY(应用详细页查询)
 
    }
    params = urlencode(params)
    if m =="GET":
        f = urllib.urlopen("%s?%s" % (url, params))
    else:
        f = urllib.urlopen(url, params)
 
    content = f.read()
    res = json.loads(content)
    if res:
        error_code = res["error_code"]
        if error_code == 0:
            #成功请求
            print res["result"]
        else:
            print "%s:%s" % (res["error_code"],res["reason"])
    else:
        print "request api error"
 
 
 
if __name__ == '__main__':
    main()


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...