فهرست منبع

增加获取cookie接口

xusonglin 3 سال پیش
والد
کامیت
9dafa60a13

+ 4 - 2
src/main/java/com/jkcredit/info/query/InfoQueryApplication.java

@@ -3,14 +3,16 @@ package com.jkcredit.info.query;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
 @EnableEurekaClient
 @SpringBootApplication
+@EnableScheduling
 public class InfoQueryApplication {
 
     public static void main(String[] args) {
-//        System.setProperty("https.proxyHost", "127.0.0.1");
-//        System.setProperty("https.proxyPort", "9986");
+        System.setProperty("https.proxyHost", "127.0.0.1");
+        System.setProperty("https.proxyPort", "9986");
         SpringApplication.run(InfoQueryApplication.class, args);
     }
 

+ 5 - 0
src/main/java/com/jkcredit/info/query/controller/InfoQueryController.java

@@ -34,6 +34,11 @@ public class InfoQueryController {
         return informationQueryService.loadCookie();
     }
 
+    @PostMapping("/getNewCookie")
+    public CommonResponseObject getNewCookie() {
+        return informationQueryService.getNewCookie();
+    }
+
     @PostMapping("/test")
     public String test() {
         System.out.println(123);

+ 2 - 0
src/main/java/com/jkcredit/info/query/service/InformationQueryService.java

@@ -11,4 +11,6 @@ public interface InformationQueryService {
     CommonResponseObject query(String keyWord, String type);
 
     CommonResponseObject loadCookie();
+
+    CommonResponseObject getNewCookie();
 }

+ 12 - 0
src/main/java/com/jkcredit/info/query/service/impl/InformationQueryServiceImpl.java

@@ -216,6 +216,18 @@ public class InformationQueryServiceImpl implements InformationQueryService {
         }
     }
 
+    @Override
+    public CommonResponseObject getNewCookie() {
+        String requestId = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())
+                + UUID.randomUUID().toString();
+        String cookie = CookieUtil.getNewCookie();
+        if (StringUtils.isBlank(cookie)) {
+            return CommonResponseObject.failed("查询失败", CommonConstant.NETWORK_DISABLED, getLocalHost(), requestId);
+        } else {
+            return CommonResponseObject.success(new ArrayList<>(), getLocalHost(), requestId);
+        }
+    }
+
     private String getLocalHost() {
         InetAddress address = null;
         try {

+ 19 - 0
src/main/java/com/jkcredit/info/query/task/LoadCookieTask.java

@@ -0,0 +1,19 @@
+package com.jkcredit.info.query.task;
+
+import com.jkcredit.info.query.util.CookieUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author xusonglin
+ * @version V1.0
+ **/
+@Slf4j
+@Component
+public class LoadCookieTask {
+    @Scheduled(cron = "0 0/30 * * * ?", zone = "Asia/Shanghai")
+    public void loadCookie() {
+        CookieUtil.getNewCookie();
+    }
+}

+ 11 - 0
src/main/java/com/jkcredit/info/query/util/CookieUtil.java

@@ -38,6 +38,17 @@ public class CookieUtil {
         return getCookie();
     }
 
+    public static String getNewCookie() {
+        String responseContext = HttpUtil.doGetLoadCookie(cookieUrl);
+        log.info("getNewCookie:{}", responseContext);
+        if (StringUtils.isNotBlank(responseContext)) {
+            HttpUtil.doGet(authenticationCookieUrl, getCookie());
+            return getCookie();
+        } else {
+            return "";
+        }
+    }
+
     public static String getCookie() {
         String cookie = "";
         ConcurrentHashMap<String, List<Cookie>> cookieStore = CookieConcurrentHashMapUtil.getInstance();

+ 2 - 1
src/main/java/com/jkcredit/info/query/util/HttpUtil.java

@@ -29,6 +29,7 @@ public class HttpUtil {
                 .readTimeout(3000, TimeUnit.MILLISECONDS)
                 .writeTimeout(3000, TimeUnit.MILLISECONDS)
                 .sslSocketFactory(SSLSocketClient.getSocketFactory(), SSLSocketClient.getX509TrustManager())
+                .hostnameVerifier(SSLSocketClient.getHostnameVerifier())
                 .build();
         String responseContext = "";
         try {
@@ -52,7 +53,7 @@ public class HttpUtil {
                 .connectTimeout(3000, TimeUnit.MILLISECONDS)
                 .readTimeout(3000, TimeUnit.MILLISECONDS)
                 .writeTimeout(3000, TimeUnit.MILLISECONDS)
-                .sslSocketFactory(SSLSocketClient.getSocketFactory())
+                .sslSocketFactory(SSLSocketClient.getSocketFactory(), SSLSocketClient.getX509TrustManager())
                 .hostnameVerifier(SSLSocketClient.getHostnameVerifier())
                 .build();
         String responseContext = "";