HttpPost httpPost = new HttpPost("https://open.95516.com/open/access/1.0/backendToken");
CloseableHttpClient client = HttpClients.createDefault();
String respContent = null;
// appid
String appid = new String("a00000000000000000000000000000001");
// secret秘钥
String secret = new String("2aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0");
// json方式
JSONObject jsonParam = new JSONObject();
jsonParam.put("appId", appid);
// 生成随机字符串
String str = Utils.createNonceStr();
jsonParam.put("nonceStr", str);
// 时间戳
String date = String.valueOf(System.currentTimeMillis() / 1000);
jsonParam.put("timestamp", date);
// 生成签名
String waitSign = "appId=" + appid + "&nonceStr=" + str + "&secret=" + secret + "×tamp=" + date;
String sign = Utils.sha256(waitSign.getBytes());
jsonParam.put("signature", sign);
System.out.println(jsonParam.toString());
// 解决中文乱码问题
StringEntity entity = new StringEntity(jsonParam.toString(), "utf-8");
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json");
httpPost.setEntity(entity);
HttpResponse resp = client.execute(httpPost);
if (resp.getStatusLine().getStatusCode() == 200) {
HttpEntity he = resp.getEntity();
respContent = EntityUtils.toString(he, "UTF-8");
}
System.out.println(respContent);