#!/usr/bin/python # encoding:utf-8 import urllib2, json, urllib, hashlib def md5(str): m = hashlib.md5() m.update(str) return m.hexdigest() def makeSign(queryarr): queryarr = sorted(queryarr.items(),key=lambda e:e[0]) strs = "" for str in queryarr: strs += "%s" %str[1] return md5(strs) # 1、中石化加油卡充值接口 data = {} data["appkey"] = "your_appkey_here" data["fuelcard"] = "1000110000001234567" # 要充值的加油卡卡号 data["amount"] = 200 # 充值的金额 单位:元 data["outorderno"] = "" # 外部订单号 queryarr = {"fuelcard":data["fuelcard"],"outorderno":data["outorderno"],"amount":data["amount"]} sign = makeSign(queryarr) data["sign"] = sign url_values = urllib.urlencode(data) url = "https://api.jisuapi.com/fuelcardrecharge/recharge" + "?" + url_values request = urllib2.Request(url) result = urllib2.urlopen(request) jsonarr = json.loads(result.read()) if jsonarr["status"] != u"0": print jsonarr["msg"] exit() result = jsonarr["result"] print result["fuelcard"],result["amount"],result["totalfee"],result["outorderno"],result["orderno"],result["rechargestatus"]