当前位置:文档之家› 基于Python的游戏app充值api调用代码实例

基于Python的游戏app充值api调用代码实例

基于Python的游戏app充值api调用代码实例代码描述:基于Python的游戏app充值api调用代码实例代码平台:聚合数据#!/usr/bin/python# -*- coding: utf-8 -*-import json, urllibfrom urllib import urlencode#----------------------------------# 游戏充值调用示例代码-聚合数据# 在线接口文档:/docs/88#----------------------------------def main():#配置您申请的APPKeyappkey ="*********************"#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 ="/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 ="/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 ="/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 ="/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 ="/ofpay/game/order"params ={"cardid": "", #商品编码,对应接口3的cardid"cardnum": "", #购买数量"orderid": "", #订单号,8-32位数字字母组合"game_userid": "", #游戏玩家账号(game_userid=xxx@$xxx001 xxx@是通行证xxx001是玩家账号)"game_area": "", #游戏所在区域,没有则不填,具体参照接口4返回,URL Encode UTF8"game_srv": "", #游戏所在服务器,没有则不填,具体参照接口4返回,UR LEncode UTF8"key": appkey, #应用APPKEY(应用详细页查询)"sign": "", #校验值,md5(<b>OpenID</b>+key+cardid+ca rdnum+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 ="/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()。

相关主题