String hwLoginUrlPost= ConfigSet.GetConfig(“HWloginUrl”);
String username= ConfigSet.GetConfig(“HWusername”);
String pwd= ConfigSet.GetConfig(“HWpwd”);
String accessKey= ConfigSet.GetConfig(“HWaccessKey”);
String timestamp = “1585185782183”; //时间戳
Map<String, String> postParams = new HashMap<String, String>();
postParams.put(“userName”, username);
postParams.put(“timestamp”, timestamp);
postParams.put(“password”, pwd);
postParams.put(“sign”, DataUtil.getSign(username, pwd, accessKey, timestamp));
//获取token
String token="";
StringEntity requestEntity = null;
HttpResponse response = null;
HttpEntity httpEntity = null;
String token_result = null;
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(hwLoginUrlPost);
Map<String, Object> checkMap = new HashMap<String, Object>();
String json = JSON.toJSONString(postParams);
try {
requestEntity = new StringEntity(json, "utf-8");
httppost.addHeader("Content-Type", "application/json;charset=UTF-8");
httppost.setEntity(requestEntity);
response = httpclient.execute(httppost);
httpEntity = response.getEntity();
token_result = EntityUtils.toString(httpEntity, "UTF-8");
checkMap = JSON.parseObject(token_result);
if (checkMap != null && (int) checkMap.get("code") == 200) {
token = (String) checkMap.get("data");
}
} catch (Exception e) {
nc.bs.logging.Logger.error("获取token失败:"+e);
}