diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/RestUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/RestUtil.java index c3d7a35..4aed72b 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/RestUtil.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/RestUtil.java @@ -223,6 +223,11 @@ public class RestUtil { url += ("?" + asUrlVariables(variables)); } // 发送请求 + try { + SslUtils.ignoreSsl(); + } catch (Exception e) { + e.printStackTrace(); + } HttpEntity request = new HttpEntity<>(body, headers); return RT.exchange(url, method, request, responseType); } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/SslUtils.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/SslUtils.java new file mode 100644 index 0000000..329a502 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/SslUtils.java @@ -0,0 +1,53 @@ +package org.jeecg.common.util; + +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +public class SslUtils { + private static void trustAllHttpsCertificates() throws Exception { + TrustManager[] trustAllCerts = new TrustManager[1]; + TrustManager tm = new miTM(); + trustAllCerts[0] = tm; + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, null); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + } + static class miTM implements TrustManager,X509TrustManager { + public X509Certificate[] getAcceptedIssuers() { + return null; + } + public boolean isServerTrusted(X509Certificate[] certs) { + return true; + } + public boolean isClientTrusted(X509Certificate[] certs) { + return true; + } + public void checkServerTrusted(X509Certificate[] certs, String authType) + throws CertificateException { + return; + } + public void checkClientTrusted(X509Certificate[] certs, String authType) + throws CertificateException { + return; + } + } + /** + * 忽略HTTPS请求的SSL证书,必须在openConnection之前调用 + * @throws Exception + */ + public static void ignoreSsl() throws Exception{ + HostnameVerifier hv = new HostnameVerifier() { + public boolean verify(String urlHostName, SSLSession session) { + System.out.println("Warning: URL Host: " + urlHostName + " vs. " + session.getPeerHost()); + return true; + } + }; + trustAllHttpsCertificates(); + HttpsURLConnection.setDefaultHostnameVerifier(hv); + } +} diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/ApiController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/ApiController.java index b140188..4cd5dcf 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/ApiController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/ApiController.java @@ -157,7 +157,7 @@ public class ApiController { public JSONObject imgNotify() { String ss = "{\t\"requestId\":\"10001\",\t\"result\":{\t\t\"ocrResult\":[\t\t\t{\t\t\t\t\"tag\":\"hospitalName\",\t\t\t\t\"inputText\":\"仁和医院\",\t\t\t\t\"ocrText\":\"仁和医院\",\t\t\t\t\"ocrPrecisionRate\":0.8,\t\t\t\t\"sourceImage\":{\t\t\t\t\t\"fileName\":\"test1.png\",\t\t\t\t\t\"path\":\"/usr/local/ocr/test1.png\"\t\t\t\t},\t\t\t\t\"failureReason\":\"\"\t\t\t}\t\t],\t\t\"ruleValidation\":false,\t\t\"retrieveReviewCompliance\":\"80\",\t\t\"imageTagRetrievePercentage\":\"66.6\",\t\t\"failureReason\":\"医生名称不匹配\"\t}}"; JSONObject requestBody = JSONObject.parseObject(ss); - JSONObject semanticResponseJson = RestUtil.post("http://192.168.1.21:8686/api/task/image/ocr/callback", requestBody); + JSONObject semanticResponseJson = RestUtil.post("https://192.168.1.21:8686/api/task/image/ocr/callback", requestBody); return semanticResponseJson; /*String requestId = jsonObject.getString("requestId"); String fileName = jsonObject.getString("fileName");