he2802 2 سال پیش
والد
کامیت
ab37b18c03

+ 1 - 0
zhongzheng-admin/src/main/resources/application-dev.yml

@@ -176,6 +176,7 @@ officialPush:
     token: 0ca175b9c0f726a831d895e26933246
 
 
+
 distributionOldPay:
     host: http://gdxypx.xy.com/System/BussinessApi/AddRedPackData
 

+ 37 - 7
zhongzheng-common/src/main/java/com/zhongzheng/common/utils/http/HttpUtils.java

@@ -9,6 +9,8 @@ import org.apache.http.client.entity.UrlEncodedFormEntity;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClientBuilder;
@@ -21,6 +23,8 @@ import org.slf4j.LoggerFactory;
 import javax.net.ssl.*;
 import java.io.*;
 import java.net.*;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
 import java.security.cert.X509Certificate;
 import java.util.*;
 
@@ -112,7 +116,12 @@ public class HttpUtils
         return result.toString();
     }
     public static String postFormBody(String url, Map<String, String> paramMap) throws IOException{
-        return post(url, paramMap, null);
+        try{
+            String result = post(url, paramMap, null);
+            return result;
+        }catch (Exception e){
+            return null;
+        }
 
     }
 
@@ -470,7 +479,7 @@ public class HttpUtils
      * @return 请求返回的数据
      * @throws IOException 读写异常
      */
-    private static String post(String url, Map<String, String> paramMap, String encoding) throws IOException {
+    private static String post(String url, Map<String, String> paramMap, String encoding) throws IOException, NoSuchAlgorithmException, KeyManagementException {
         log.debug("http 请求 url: {} , 请求参数: {}", url, appendUrl("", paramMap).replace("?", ""));
         encoding = encoding == null ? UTF8 : encoding;
         // 创建post方式请求对象
@@ -512,11 +521,28 @@ public class HttpUtils
      * @throws IOException 读写异常
      */
     private static <T> T post(String url, HttpPost httpPost, String encoding, DataParse<T> dataParse)
-            throws IOException {
+            throws IOException, NoSuchAlgorithmException, KeyManagementException {
+        TrustManager[] trustAllCerts = new TrustManager[] {
+                new X509TrustManager() {
+                    public X509Certificate[] getAcceptedIssuers() {
+                        return null;
+                    }
+                    public void checkClientTrusted(X509Certificate[] certs, String authType) {
+                        // don't check
+                    }
+                    public void checkServerTrusted(X509Certificate[] certs, String authType) {
+                        // don't check
+                    }
+                }
+        };
+
+        SSLContext ctx = SSLContext.getInstance("TLS");
+        ctx.init(null, trustAllCerts, null);
+        LayeredConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(ctx);
         T result = null;
         CloseableHttpResponse response = null;
         // 创建httpclient对象
-        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
+        CloseableHttpClient httpClient = HttpClientBuilder.create().setSSLSocketFactory(sslSocketFactory).build();
 
         // 执行请求操作,并拿到结果(同步阻塞)
         response = sendRequestAndGetResult(url, httpClient, httpPost);
@@ -599,8 +625,12 @@ public class HttpUtils
     }
 
     public static String postFormBodyHeader(String url, Map<String, String> paramMap, Map<String, String> headersMap, Header[] header) throws IOException{
-        return postHearder(url, paramMap, null, headersMap, header);
-
+        try{
+            String result = postHearder(url, paramMap, null, headersMap, header);
+            return result;
+        }catch (Exception e){
+            return null;
+        }
     }
 
     /**
@@ -612,7 +642,7 @@ public class HttpUtils
      * @return 请求返回的数据
      * @throws IOException 读写异常
      */
-    private static String postHearder(String url, Map<String, String> paramMap, String encoding, Map<String, String> headersMap, Header[] header) throws IOException {
+    private static String postHearder(String url, Map<String, String> paramMap, String encoding, Map<String, String> headersMap, Header[] header) throws IOException, NoSuchAlgorithmException, KeyManagementException {
         log.debug("http 请求 url: {} , 请求参数: {}", url, appendUrl("", paramMap).replace("?", ""));
         encoding = encoding == null ? UTF8 : encoding;
         // 创建post方式请求对象

+ 2 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/grade/service/impl/ClassGradeServiceImpl.java

@@ -68,6 +68,8 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.io.IOException;
 import java.math.BigDecimal;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;

+ 4 - 2
zhongzheng-system/src/main/java/com/zhongzheng/modules/grade/service/impl/ClassGradeUserServiceImpl.java

@@ -68,6 +68,8 @@ import org.springframework.util.CollectionUtils;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.math.BigDecimal;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
 import java.util.*;
 import java.util.stream.Collectors;
 import java.util.zip.ZipOutputStream;
@@ -604,7 +606,7 @@ public class ClassGradeUserServiceImpl extends ServiceImpl<ClassGradeUserMapper,
                 return respone;
             }
         } catch (IOException e) {
-            throw new CustomException("请求错误");
+            throw new CustomException("学时推送请求错误"+e.getMessage());
         }
     }
 
@@ -738,7 +740,7 @@ public class ClassGradeUserServiceImpl extends ServiceImpl<ClassGradeUserMapper,
                 return respone;
             }
         } catch (IOException e) {
-            throw new CustomException("请求错误");
+            throw new CustomException("请求错误"+e.getMessage());
         }
     }
 

+ 2 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/grade/service/impl/UserPeriodServiceImpl.java

@@ -74,6 +74,8 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.io.IOException;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
 import java.text.DecimalFormat;
 import java.util.*;
 import java.util.concurrent.TimeUnit;