|
|
@@ -1,142 +1,142 @@
|
|
|
-package com.jzg.quotation.zhongan.crawler.service;
|
|
|
-
|
|
|
-import com.jzg.quotation.commons.component.RequestComponent;
|
|
|
-import com.jzg.quotation.zhongan.crawler.model.entity.ZhongAnBizDocumentInfo;
|
|
|
-import com.jzg.quotation.zhongan.crawler.model.result.ZhongAnQueryCarInfoResult;
|
|
|
-import com.jzg.quotation.zhongan.crawler.model.result.ZhongAnQueryDocumentInfoResult;
|
|
|
-import com.jzg.quotation.zhongan.crawler.model.result.ZhongAnQueryPolicyDetailResult;
|
|
|
-import io.netty.channel.ChannelOption;
|
|
|
-import io.netty.handler.ssl.SslContextBuilder;
|
|
|
-import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
|
|
|
-import io.netty.handler.timeout.ReadTimeoutHandler;
|
|
|
-import io.netty.handler.timeout.WriteTimeoutHandler;
|
|
|
-import org.junit.jupiter.api.BeforeAll;
|
|
|
-import org.junit.jupiter.api.Test;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.http.HttpHeaders;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
-import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
|
|
-import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
|
|
|
-import org.springframework.web.reactive.function.client.WebClient;
|
|
|
-import reactor.core.publisher.Mono;
|
|
|
-import reactor.netty.http.client.HttpClient;
|
|
|
-import reactor.netty.resources.ConnectionProvider;
|
|
|
-
|
|
|
-import java.time.Duration;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
-
|
|
|
-public class ZhongAnAPIServiceTest {
|
|
|
- private static final Logger logger = LoggerFactory.getLogger(ZhongAnAPIServiceTest.class);
|
|
|
-
|
|
|
- private static ZhongAnAPIService zhongAnAPIService;
|
|
|
-
|
|
|
-
|
|
|
- @BeforeAll
|
|
|
- public static void before() {
|
|
|
- // 启用SSL调试(查看握手过程)
|
|
|
- //System.setProperty("javax.net.debug", "ssl:handshake");
|
|
|
-
|
|
|
- // 配置HTTP连接池
|
|
|
- ConnectionProvider connectionProvider = ConnectionProvider
|
|
|
- .builder("http")
|
|
|
- .maxConnections(500)
|
|
|
- .maxIdleTime(Duration.ofSeconds(30))
|
|
|
- .build();
|
|
|
-
|
|
|
- // 配置HTTP客户端
|
|
|
- HttpClient httpClient = reactor.netty.http.client.HttpClient
|
|
|
- .create(connectionProvider)
|
|
|
- .secure(ssl -> ssl.sslContext(
|
|
|
- SslContextBuilder.forClient()
|
|
|
- .trustManager(InsecureTrustManagerFactory.INSTANCE)
|
|
|
- ))
|
|
|
- .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000)
|
|
|
- .responseTimeout(Duration.ofSeconds(50))
|
|
|
- .doOnConnected(conn ->
|
|
|
- conn.addHandlerLast(new ReadTimeoutHandler(50)).addHandlerLast(new WriteTimeoutHandler(50)));
|
|
|
-
|
|
|
- WebClient.builder()
|
|
|
- .clientConnector(new ReactorClientHttpConnector(httpClient))
|
|
|
- .build();
|
|
|
- // 构建WebClient实例
|
|
|
- WebClient webClient = WebClient
|
|
|
- .builder()
|
|
|
- .clientConnector(new ReactorClientHttpConnector(httpClient))
|
|
|
- .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
|
|
- .defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
|
|
|
- .filter(ExchangeFilterFunction.ofRequestProcessor(
|
|
|
- clientRequest -> {
|
|
|
- // 打印请求头信息
|
|
|
- clientRequest
|
|
|
- .headers()
|
|
|
- .forEach((key, values) -> {
|
|
|
- logger.info("请求头: {}: {}", key, values);
|
|
|
- });
|
|
|
- return Mono.just(clientRequest);
|
|
|
- }
|
|
|
- ))
|
|
|
- .codecs(item->item.defaultCodecs().maxInMemorySize(10 * 1024 * 1024))
|
|
|
- .build();
|
|
|
-
|
|
|
-
|
|
|
- RequestComponent requestComponent = new RequestComponent(webClient);
|
|
|
-
|
|
|
- zhongAnAPIService = new ZhongAnAPIService();
|
|
|
- zhongAnAPIService.setRequestComponent(requestComponent);
|
|
|
-
|
|
|
-
|
|
|
- //ChengTaiAPIHelper.initAPI("https://b2b.champion-ic.com");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Test
|
|
|
- public void queryDocumentInfo() {
|
|
|
- String token = "zaLoginCookieKey=9b902b0ec92581f51587ce2a9da7019ec8f9582b1a43c0f437b9566049b486c2;";
|
|
|
- ZhongAnQueryDocumentInfoResult zhongAnQueryDocumentInfoResult = zhongAnAPIService.queryDocumentInfo(token, "291e19533f8ee5b20d8eaf64ec4f43b5");
|
|
|
-
|
|
|
- assertNotNull(zhongAnQueryDocumentInfoResult);
|
|
|
-
|
|
|
- List<ZhongAnBizDocumentInfo> bizDocumentInfo = zhongAnQueryDocumentInfoResult.getBizDocumentInfo();
|
|
|
-
|
|
|
- for (ZhongAnBizDocumentInfo bizDocument : bizDocumentInfo) {
|
|
|
- String url = "https://c.zhongan.com/open/bmw/n/query_controller/downloadDocument.json?orderNo=%s&fileName=%s&documentUrl=%s".formatted("291e19533f8ee5b20d8eaf64ec4f43b5",bizDocument.getDocumentName(), bizDocument.getDocumentUrl());
|
|
|
-
|
|
|
- System.out.println(url);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void queryPolicyDetail() {
|
|
|
- String token = "zaLoginCookieKey=9b902b0ec92581f51587ce2a9da7019ec8f9582b1a43c0f437b9566049b486c2;";
|
|
|
- String policyId = "bd162dd1260519fc39aa446aee32d9ab";
|
|
|
-
|
|
|
- ZhongAnQueryPolicyDetailResult result = zhongAnAPIService.queryPolicyDetail(token, policyId);
|
|
|
-
|
|
|
- assertNotNull(result);
|
|
|
-
|
|
|
- String policyStatus = result.getDatas().getPolicy().getVehiclePolicyDTO().getPolicyStatus();
|
|
|
- String policyStatusText = result.getDatas().getPolicy().getVehiclePolicyDTO().getPolicyStatusText();
|
|
|
-
|
|
|
- System.out.println(policyStatus);
|
|
|
- System.out.println(policyStatusText);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void queryCarInfo() {
|
|
|
- String token = "zaLoginCookieKey=9b902b0ec92581f51587ce2a9da7019ec8f9582b1a43c0f437b9566049b486c2;";
|
|
|
- String flowId = "FJ14309612196676b6cd4";
|
|
|
-
|
|
|
- ZhongAnQueryCarInfoResult result = zhongAnAPIService.queryCarInfo(token, flowId);
|
|
|
-
|
|
|
- assertNotNull(result);
|
|
|
-
|
|
|
- Map<String, Object> unknownFields = result.getUnknownFields();
|
|
|
-
|
|
|
- System.out.println();
|
|
|
- System.out.println(unknownFields);
|
|
|
- }
|
|
|
-}
|
|
|
+//package com.jzg.quotation.zhongan.crawler.service;
|
|
|
+//
|
|
|
+//import com.jzg.quotation.commons.component.RequestComponent;
|
|
|
+//import com.jzg.quotation.zhongan.crawler.model.entity.ZhongAnBizDocumentInfo;
|
|
|
+//import com.jzg.quotation.zhongan.crawler.model.result.ZhongAnQueryCarInfoResult;
|
|
|
+//import com.jzg.quotation.zhongan.crawler.model.result.ZhongAnQueryDocumentInfoResult;
|
|
|
+//import com.jzg.quotation.zhongan.crawler.model.result.ZhongAnQueryPolicyDetailResult;
|
|
|
+//import io.netty.channel.ChannelOption;
|
|
|
+//import io.netty.handler.ssl.SslContextBuilder;
|
|
|
+//import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
|
|
|
+//import io.netty.handler.timeout.ReadTimeoutHandler;
|
|
|
+//import io.netty.handler.timeout.WriteTimeoutHandler;
|
|
|
+//import org.junit.jupiter.api.BeforeAll;
|
|
|
+//import org.junit.jupiter.api.Test;
|
|
|
+//import org.slf4j.Logger;
|
|
|
+//import org.slf4j.LoggerFactory;
|
|
|
+//import org.springframework.http.HttpHeaders;
|
|
|
+//import org.springframework.http.MediaType;
|
|
|
+//import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
|
|
+//import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
|
|
|
+//import org.springframework.web.reactive.function.client.WebClient;
|
|
|
+//import reactor.core.publisher.Mono;
|
|
|
+//import reactor.netty.http.client.HttpClient;
|
|
|
+//import reactor.netty.resources.ConnectionProvider;
|
|
|
+//
|
|
|
+//import java.time.Duration;
|
|
|
+//import java.util.List;
|
|
|
+//import java.util.Map;
|
|
|
+//
|
|
|
+//import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
+//
|
|
|
+//public class ZhongAnAPIServiceTest {
|
|
|
+// private static final Logger logger = LoggerFactory.getLogger(ZhongAnAPIServiceTest.class);
|
|
|
+//
|
|
|
+// private static ZhongAnAPIService zhongAnAPIService;
|
|
|
+//
|
|
|
+//
|
|
|
+// @BeforeAll
|
|
|
+// public static void before() {
|
|
|
+// // 启用SSL调试(查看握手过程)
|
|
|
+// //System.setProperty("javax.net.debug", "ssl:handshake");
|
|
|
+//
|
|
|
+// // 配置HTTP连接池
|
|
|
+// ConnectionProvider connectionProvider = ConnectionProvider
|
|
|
+// .builder("http")
|
|
|
+// .maxConnections(500)
|
|
|
+// .maxIdleTime(Duration.ofSeconds(30))
|
|
|
+// .build();
|
|
|
+//
|
|
|
+// // 配置HTTP客户端
|
|
|
+// HttpClient httpClient = reactor.netty.http.client.HttpClient
|
|
|
+// .create(connectionProvider)
|
|
|
+// .secure(ssl -> ssl.sslContext(
|
|
|
+// SslContextBuilder.forClient()
|
|
|
+// .trustManager(InsecureTrustManagerFactory.INSTANCE)
|
|
|
+// ))
|
|
|
+// .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000)
|
|
|
+// .responseTimeout(Duration.ofSeconds(50))
|
|
|
+// .doOnConnected(conn ->
|
|
|
+// conn.addHandlerLast(new ReadTimeoutHandler(50)).addHandlerLast(new WriteTimeoutHandler(50)));
|
|
|
+//
|
|
|
+// WebClient.builder()
|
|
|
+// .clientConnector(new ReactorClientHttpConnector(httpClient))
|
|
|
+// .build();
|
|
|
+// // 构建WebClient实例
|
|
|
+// WebClient webClient = WebClient
|
|
|
+// .builder()
|
|
|
+// .clientConnector(new ReactorClientHttpConnector(httpClient))
|
|
|
+// .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
|
|
+// .defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
|
|
|
+// .filter(ExchangeFilterFunction.ofRequestProcessor(
|
|
|
+// clientRequest -> {
|
|
|
+// // 打印请求头信息
|
|
|
+// clientRequest
|
|
|
+// .headers()
|
|
|
+// .forEach((key, values) -> {
|
|
|
+// logger.info("请求头: {}: {}", key, values);
|
|
|
+// });
|
|
|
+// return Mono.just(clientRequest);
|
|
|
+// }
|
|
|
+// ))
|
|
|
+// .codecs(item->item.defaultCodecs().maxInMemorySize(10 * 1024 * 1024))
|
|
|
+// .build();
|
|
|
+//
|
|
|
+//
|
|
|
+// RequestComponent requestComponent = new RequestComponent(webClient);
|
|
|
+//
|
|
|
+// zhongAnAPIService = new ZhongAnAPIService();
|
|
|
+// zhongAnAPIService.setRequestComponent(requestComponent);
|
|
|
+//
|
|
|
+//
|
|
|
+// //ChengTaiAPIHelper.initAPI("https://b2b.champion-ic.com");
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void queryDocumentInfo() {
|
|
|
+// String token = "zaLoginCookieKey=9b902b0ec92581f51587ce2a9da7019ec8f9582b1a43c0f437b9566049b486c2;";
|
|
|
+// ZhongAnQueryDocumentInfoResult zhongAnQueryDocumentInfoResult = zhongAnAPIService.queryDocumentInfo(token, "291e19533f8ee5b20d8eaf64ec4f43b5");
|
|
|
+//
|
|
|
+// assertNotNull(zhongAnQueryDocumentInfoResult);
|
|
|
+//
|
|
|
+// List<ZhongAnBizDocumentInfo> bizDocumentInfo = zhongAnQueryDocumentInfoResult.getBizDocumentInfo();
|
|
|
+//
|
|
|
+// for (ZhongAnBizDocumentInfo bizDocument : bizDocumentInfo) {
|
|
|
+// String url = "https://c.zhongan.com/open/bmw/n/query_controller/downloadDocument.json?orderNo=%s&fileName=%s&documentUrl=%s".formatted("291e19533f8ee5b20d8eaf64ec4f43b5",bizDocument.getDocumentName(), bizDocument.getDocumentUrl());
|
|
|
+//
|
|
|
+// System.out.println(url);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void queryPolicyDetail() {
|
|
|
+// String token = "zaLoginCookieKey=9b902b0ec92581f51587ce2a9da7019ec8f9582b1a43c0f437b9566049b486c2;";
|
|
|
+// String policyId = "bd162dd1260519fc39aa446aee32d9ab";
|
|
|
+//
|
|
|
+// ZhongAnQueryPolicyDetailResult result = zhongAnAPIService.queryPolicyDetail(token, policyId);
|
|
|
+//
|
|
|
+// assertNotNull(result);
|
|
|
+//
|
|
|
+// String policyStatus = result.getDatas().getPolicy().getVehiclePolicyDTO().getPolicyStatus();
|
|
|
+// String policyStatusText = result.getDatas().getPolicy().getVehiclePolicyDTO().getPolicyStatusText();
|
|
|
+//
|
|
|
+// System.out.println(policyStatus);
|
|
|
+// System.out.println(policyStatusText);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void queryCarInfo() {
|
|
|
+// String token = "zaLoginCookieKey=9b902b0ec92581f51587ce2a9da7019ec8f9582b1a43c0f437b9566049b486c2;";
|
|
|
+// String flowId = "FJ14309612196676b6cd4";
|
|
|
+//
|
|
|
+// ZhongAnQueryCarInfoResult result = zhongAnAPIService.queryCarInfo(token, flowId);
|
|
|
+//
|
|
|
+// assertNotNull(result);
|
|
|
+//
|
|
|
+// Map<String, Object> unknownFields = result.getUnknownFields();
|
|
|
+//
|
|
|
+// System.out.println();
|
|
|
+// System.out.println(unknownFields);
|
|
|
+// }
|
|
|
+//}
|