Merge branch 'master' of http://192.168.30.2:3000/bonus/cqdevicemgt
This commit is contained in:
commit
112265865b
|
|
@ -17,6 +17,7 @@ import java.io.*;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -26,11 +27,11 @@ public class HttpHelper {
|
||||||
System.out.println("JSONBody-=========:" + JSONBody);
|
System.out.println("JSONBody-=========:" + JSONBody);
|
||||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||||
HttpPost httpPost = new HttpPost(url);
|
HttpPost httpPost = new HttpPost(url);
|
||||||
httpPost.addHeader("Content-Type", "application/json");
|
httpPost.addHeader("Content-Type", "application/json; charset=UTF-8");
|
||||||
httpPost.setEntity(new StringEntity(JSONBody));
|
httpPost.setEntity(new StringEntity(JSONBody,StandardCharsets.UTF_8));
|
||||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||||
HttpEntity entity = response.getEntity();
|
HttpEntity entity = response.getEntity();
|
||||||
String responseContent = EntityUtils.toString(entity, "UTF-8");
|
String responseContent = EntityUtils.toString(entity, StandardCharsets.UTF_8);
|
||||||
response.close();
|
response.close();
|
||||||
httpClient.close();
|
httpClient.close();
|
||||||
return responseContent;
|
return responseContent;
|
||||||
|
|
|
||||||
|
|
@ -187,22 +187,21 @@ public class MaMachineServiceImpl implements MaMachineService {
|
||||||
if (maMachineList.isEmpty()){
|
if (maMachineList.isEmpty()){
|
||||||
throw new ServiceException(String.format(ExceptionDict.PARAM_IS_NULL_ERROR_MSG,"maMachineList"), ExceptionDict.PARAM_IS_NULL_ERROR);
|
throw new ServiceException(String.format(ExceptionDict.PARAM_IS_NULL_ERROR_MSG,"maMachineList"), ExceptionDict.PARAM_IS_NULL_ERROR);
|
||||||
}
|
}
|
||||||
//遍历推送,防止数据量过大
|
|
||||||
String content = JSONObject.toJSONString(maMachineList);
|
String content = JSONObject.toJSONString(maMachineList);
|
||||||
String encrypt;
|
String encrypt;
|
||||||
try {
|
try {
|
||||||
encrypt = RsaUtil.encryptByPublicKey(content, Constants.publicKey);
|
//encrypt = RsaUtil.encryptByPublicKey(content, Constants.publicKey);
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
map.put("body", encrypt);
|
map.put("body", content);
|
||||||
String body = JSONObject.toJSONString(map);
|
String body = JSONObject.toJSONString(map);
|
||||||
String data = HttpHelper.sendHttpPost(zlptUrl, body);
|
String data = HttpHelper.sendHttpPost(zlptUrl, body);
|
||||||
log.info("dataString-=========:" + data);
|
log.info("dataString-=========:" + data);
|
||||||
//对返回的结果进行处理
|
//对返回的结果进行处理
|
||||||
resultDataHandler(data);
|
// resultDataHandler(data);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
return AjaxResult.success("请求成功!");
|
return AjaxResult.error("推送失败!");
|
||||||
}
|
}
|
||||||
return AjaxResult.success("请求成功!");
|
return AjaxResult.success("请求成功!");
|
||||||
}
|
}
|
||||||
|
|
@ -211,22 +210,13 @@ public class MaMachineServiceImpl implements MaMachineService {
|
||||||
JSONObject object = JSONObject.parseObject(data);
|
JSONObject object = JSONObject.parseObject(data);
|
||||||
System.err.println(data);
|
System.err.println(data);
|
||||||
String code = object.getString("code");
|
String code = object.getString("code");
|
||||||
if ("200".equals(code)) {
|
if ("0".equals(code)) {
|
||||||
String dataResultString = object.getString("data");
|
String dataResultString = object.getString("data");
|
||||||
// 数据解密
|
// 数据解密
|
||||||
String dataArrayString = RsaUtil.decryptByPrivateKey(dataResultString, Constants.publicKey);
|
String dataArrayString = RsaUtil.decryptByPrivateKey(dataResultString, Constants.publicKey);
|
||||||
log.info("dataArrayString-=========:" + dataArrayString);
|
log.info("dataArrayString-=========:" + dataArrayString);
|
||||||
JSONArray dataArray = JSONArray.parseArray(dataArrayString);
|
|
||||||
if (dataArray != null && dataArray.size() > 0) {
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
throw new Exception("推送失败!");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue