|
@@ -1,5 +1,6 @@
|
|
|
package com.ruoyi.system.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.ruoyi.business.domain.ZwywLrJbxx;
|
|
|
import com.ruoyi.common.core.utils.StringUtils;
|
|
@@ -12,6 +13,16 @@ import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.net.ssl.HttpsURLConnection;
|
|
|
+import javax.net.ssl.SSLContext;
|
|
|
+import javax.net.ssl.SSLSocketFactory;
|
|
|
+import javax.net.ssl.TrustManager;
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.net.ConnectException;
|
|
|
+import java.net.URL;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -82,6 +93,12 @@ public class WlfwJkyjServiceImpl implements IWlfwJkyjService
|
|
|
return wlfwJkyjMapper.insert(wlfwJkyj);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public JSONObject device(WlfwJkyj wlfwJkyj) {
|
|
|
+ return httpsRequest("http://121.36.73.159:8090/setdevicePara",
|
|
|
+ "POST", "{}");
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 修改为老服务监控硬件信息
|
|
|
*
|
|
@@ -106,4 +123,56 @@ public class WlfwJkyjServiceImpl implements IWlfwJkyjService
|
|
|
return wlfwJkyjMapper.deleteBatchIds(Arrays.asList(ids));
|
|
|
}
|
|
|
|
|
|
+ public static JSONObject httpsRequest(String requestUrl, String requestMethod, String outputStr) {
|
|
|
+ JSONObject jsonObject = null;
|
|
|
+ try {
|
|
|
+ // 创建SSLContext对象,并使用我们指定的信任管理器初始化
|
|
|
+ TrustManager[] tm = {new MyX509TrustManager()};
|
|
|
+ SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
|
|
|
+ sslContext.init(null, tm, new java.security.SecureRandom());
|
|
|
+ // 从上述SSLContext对象中得到SSLSocketFactory对象
|
|
|
+ SSLSocketFactory ssf = sslContext.getSocketFactory();
|
|
|
+
|
|
|
+ URL url = new URL(requestUrl);
|
|
|
+ HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
|
|
|
+ conn.setSSLSocketFactory(ssf);
|
|
|
+
|
|
|
+ conn.setDoOutput(true);
|
|
|
+ conn.setDoInput(true);
|
|
|
+ conn.setUseCaches(false);
|
|
|
+ // 设置请求方式(GET/POST)
|
|
|
+ conn.setRequestMethod(requestMethod);
|
|
|
+
|
|
|
+ // 当outputStr不为null时向输出流写数据
|
|
|
+ if (null != outputStr) {
|
|
|
+ OutputStream outputStream = conn.getOutputStream();
|
|
|
+ // 注意编码格式
|
|
|
+ outputStream.write(outputStr.getBytes("UTF-8"));
|
|
|
+ outputStream.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 从输入流读取返回内容
|
|
|
+ InputStream inputStream = conn.getInputStream();
|
|
|
+ InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
|
|
|
+ BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
|
|
|
+ String str = null;
|
|
|
+ StringBuffer buffer = new StringBuffer();
|
|
|
+ while ((str = bufferedReader.readLine()) != null) {
|
|
|
+ buffer.append(str);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 释放资源
|
|
|
+ bufferedReader.close();
|
|
|
+ inputStreamReader.close();
|
|
|
+ inputStream.close();
|
|
|
+ inputStream = null;
|
|
|
+ conn.disconnect();
|
|
|
+ jsonObject = JSONObject.parseObject(buffer.toString());
|
|
|
+ } catch (ConnectException ce) {
|
|
|
+ System.out.println("连接超时:{}" + ce);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("请求异常:{}" + e);
|
|
|
+ }
|
|
|
+ return jsonObject;
|
|
|
+ }
|
|
|
}
|