java 数字转换流量_流量充值示例代码

流量充值

package api.jisuapi.flowrecharge;

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/flowrecharge/recharge";

public static final String mobile = "15158825888";

public static final String amount = "100M";// 1G请写成1024M

public static final String outorderno = "";

public static final String appsecret = "your_appsecret_here";

public static final String areatype = "";

public static Mapqueryarr;

public static void Get() throws NoSuchAlgorithmException, UnsupportedEncodingException {

queryarr = new HashMap();

queryarr.put("amount", amount);

queryarr.put("mobile", mobile);

queryarr.put("outorderno", outorderno);

queryarr.put("areatype", areatype);

String sign = makeSign(queryarr, appsecret);

String result = null;

String url = URL + "?appkey=" + APPKEY + "&mobile=" + mobile + "&amount=" + amount + "&outorderno=" + outorderno

+ "&sign=" + sign+ "&areatype=" + areatype;

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 mobile = resultarr.getString("mobile");

String totalfee = resultarr.getString("totalfee");

String amount = resultarr.getString("amount");

String outorderno = resultarr.getString("outorderno");

String orderno = resultarr.getString("orderno");

String areatype = resultarr.getString("areatype");

String rechargestatus = resultarr.getString("rechargestatus");

System.out.println(mobile + " " + amount + " " + outorderno + " " + orderno + " " + totalfee + " "

+ rechargestatus);

}

} catch (Exception e) {

e.printStackTrace();

}

}

public static String makeSign(Mapqueryarr, 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;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值