<?php
require_once 'curl.func.php';
$appkey = 'your_appkey_here';//你的appkey
$fuelcard = '1000110000001234567';//要充值的加油卡卡号
$amount = 200;//充值的金额 单位:元
$outorderno = '';//外部订单号
$appsecret = 'ssssssssssss';
$queryarr = array('fuelcard'=>$fuelcard,'amount'=>$amount,'outorderno'=>$outorderno);
$sign = makeSign($queryarr, $appsecret);//md5(fuelcard,amount,outorderno按key排序)
$url = "https://api.jisuapi.com/fuelcardrecharge/recharge?appkey=$appkey&fuelcard=$fuelcard&amount=$amount&outorderno=$outorderno&sign=$sign";
$result = curlOpen($url, ['ssl'=>true]);
$jsonarr = json_decode($result, true);
//exit(var_dump($jsonarr));
if($jsonarr['status'] != 0)
{
echo $jsonarr['msg'];
exit();
}
$result = $jsonarr['result'];
echo $result['fuelcard'].' '.' '.$result['amount'].' '.$result['totalfee'].' '.$result['outorderno'].' '.$result['orderno'].' '.$result['rechargestatus'];
function makeSign($queryarr, $appsecret)
{
ksort($queryarr, SORT_STRING);
$str = implode($queryarr);
$str .= $appsecret;
//exit($str);
$str = md5($str);
return $str;
}
#!/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"]
package api.jisuapi.fuelcardrecharge;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import api.util.HttpUtil;
import net.sf.json.JSONObject;
public class Recharge {
public static final String APPKEY = "your_appkey_here";// 你的appkey
public static final String URL = "https://api.jisuapi.com/fuelcardrecharge/recharge";
public static final String fuelcard = "1000110000001234567";// 要充值的加油卡卡号
public static final String amount = "200";// 充值的金额 单位:元
public static final String outorderno = "";// 外部订单号
public static final String appsecret = "sssssssssss";
public static Map queryarr;
public static void Get() throws NoSuchAlgorithmException, UnsupportedEncodingException {
queryarr = new HashMap();
queryarr.put("amount", amount);
queryarr.put("fuelcard", fuelcard);
queryarr.put("outorderno", outorderno);
String sign = makeSign(queryarr, appsecret);// md5(fuelcard,type,amount,outorderno按key排序)
String result = null;
String url = URL + "?appkey=" + APPKEY + "&fuelcard=" + fuelcard + "&amount=" + amount
+ "&outorderno=" + outorderno + "&sign=" + sign;
try {
result = HttpUtil.sendGet(url, "utf-8");
JSONObject json = JSONObject.fromObject(result);
if (json.getInt("status") != 0) {
System.out.println(json.getString("msg"));
} else {
JSONObject resultarr = (JSONObject) json.opt("result");
String fuelcard = resultarr.getString("fuelcard");
String totalfee = resultarr.getString("totalfee");
String amount = resultarr.getString("amount");
String outorderno = resultarr.getString("outorderno");
String orderno = resultarr.getString("orderno");
String rechargestatus = resultarr.getString("rechargestatus");
System.out.println(fuelcard + " " + " " + amount + " " + outorderno + " " + orderno + " "
+ totalfee + " " + rechargestatus);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static String makeSign(Map queryarr, String appsecret)
throws NoSuchAlgorithmException, UnsupportedEncodingException {
TreeMap map = new TreeMap(queryarr);
Iterator ir = map.keySet().iterator();
String str = new String();
while (ir.hasNext()) {
Object key = ir.next();
str += map.get(key);
}
str += appsecret;
return getMd5(str.getBytes());
}
public static String getMd5(byte[] buffer) throws NoSuchAlgorithmException {
String s = null;
char hexDigist[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(buffer);
byte[] datas = md.digest(); // 16个字节的长整数
char[] str = new char[2 * 16];
int k = 0;
for (int i = 0; i < 16; i++) {
byte b = datas[i];
str[k++] = hexDigist[b >>> 4 & 0xf];// 高4位
str[k++] = hexDigist[b & 0xf];// 低4位
}
s = new String(str);
return s;
}
}