|
|
@@ -12,12 +12,23 @@ import com.jzg.quotation.taiping.crawler.properties.TaiPingCrawlerProperties;
|
|
|
import com.jzg.quotation.taiping.crawler.utils.AESEncryption;
|
|
|
import com.jzg.quotation.taiping.crawler.utils.VerifyCodeCreate;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import org.reactivestreams.Publisher;
|
|
|
import org.springframework.core.ParameterizedTypeReference;
|
|
|
+import org.springframework.core.io.buffer.DataBuffer;
|
|
|
+import org.springframework.core.io.buffer.DataBufferUtils;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.web.reactive.function.client.WebClient;
|
|
|
+import reactor.core.publisher.Mono;
|
|
|
|
|
|
+import java.nio.channels.WritableByteChannel;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
+import java.nio.file.StandardOpenOption;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Component
|
|
|
@@ -26,6 +37,8 @@ public class TaiPingCrawlerRequestComponent {
|
|
|
|
|
|
private final RequestComponent requestComponent;
|
|
|
|
|
|
+ private final WebClient webClient;
|
|
|
+
|
|
|
private final TaiPingCrawlerProperties taiPingCrawlerProperties;
|
|
|
|
|
|
public <Response> Response requestPost(RequestUrl requestUrl, Object body, ParameterizedTypeReference<Response> bodyTypeReference, HttpHeaders headers) {
|
|
|
@@ -49,6 +62,18 @@ public class TaiPingCrawlerRequestComponent {
|
|
|
}, new HttpHeaders());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取请求头
|
|
|
+ *
|
|
|
+ * @return 请求头信息
|
|
|
+ */
|
|
|
+ public HttpHeaders getHeaders() {
|
|
|
+ String cookie = getCookie();
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.set(HttpHeaders.COOKIE, cookie);
|
|
|
+ return headers;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取cookie
|
|
|
*
|
|
|
@@ -119,8 +144,7 @@ public class TaiPingCrawlerRequestComponent {
|
|
|
httpHeaders.set(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
|
|
|
|
|
|
String url = RequestUrl.LOGIN.getRequestUrl(taiPingCrawlerProperties.getUrl());
|
|
|
- ResponseEntity<TaiPingCrawlerBaseResponse<TaiPingCrawlerLoginData>> responseEntity = requestComponent.getWebClient()
|
|
|
- .post()
|
|
|
+ ResponseEntity<TaiPingCrawlerBaseResponse<TaiPingCrawlerLoginData>> responseEntity = webClient.post()
|
|
|
.uri(url)
|
|
|
.headers(RequestComponent.setHeaders(httpHeaders))
|
|
|
.bodyValue(multiValueMap)
|
|
|
@@ -157,7 +181,7 @@ public class TaiPingCrawlerRequestComponent {
|
|
|
* @param httpHeaders 请求头
|
|
|
* @return 订单号
|
|
|
*/
|
|
|
- public String orderCreate(TaiPingCrawlerFindSolutionCodeRequest request, HttpHeaders httpHeaders) {
|
|
|
+ public String orderCreate(TaiPingCrawlerCreateOrderRequest request, HttpHeaders httpHeaders) {
|
|
|
TaiPingCrawlerBaseResponse<String> response = requestPostStrDecrypt(RequestUrl.CREATE_ORDER, request, new TypeReference<>() {
|
|
|
}, httpHeaders);
|
|
|
return response.getData();
|
|
|
@@ -188,9 +212,6 @@ public class TaiPingCrawlerRequestComponent {
|
|
|
}, httpHeaders);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 提交验证
|
|
|
*
|
|
|
@@ -203,6 +224,31 @@ public class TaiPingCrawlerRequestComponent {
|
|
|
}, httpHeaders);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 上传影像
|
|
|
+ *
|
|
|
+ * @param request 上传影像请求信息
|
|
|
+ * @param httpHeaders 请求头
|
|
|
+ * @return 上传影像响应
|
|
|
+ */
|
|
|
+ public TaiPingCrawlerBaseResponse<String> imageIntoOneFile(TaiPingCrawlerImageIntoOneFileRequest request, HttpHeaders httpHeaders) {
|
|
|
+ return requestPostStrDecrypt(RequestUrl.IMAGE_INTO_ONE_FILE, request, new TypeReference<>() {
|
|
|
+ }, httpHeaders);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * ocr 识别影像
|
|
|
+ *
|
|
|
+ * @param request ocr识别影像请求信息
|
|
|
+ * @param httpHeaders 请求头
|
|
|
+ * @return ocr 识别影像返回信息
|
|
|
+ */
|
|
|
+ public TaiPingCrawlerBaseResponse<TaiPingCrawlerOCRResultConfirmData> ocrResultConfirm(TaiPingCrawlerOCRResultConfirmRequest request, HttpHeaders httpHeaders) {
|
|
|
+ return requestPostStrDecrypt(RequestUrl.IMAGE_INTO_ONE_FILE, request, new TypeReference<>() {
|
|
|
+ }, httpHeaders);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 提交核保
|
|
|
*
|
|
|
@@ -228,5 +274,75 @@ public class TaiPingCrawlerRequestComponent {
|
|
|
}, httpHeaders);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询订单
|
|
|
+ *
|
|
|
+ * @param request 查询订单请求
|
|
|
+ * @param httpHeaders 请求头
|
|
|
+ * @return 订单信息
|
|
|
+ */
|
|
|
+ public TaiPingCrawlerQueryListData.RecordsDTO queryList(TaiPingCrawlerQueryListRequest request, HttpHeaders httpHeaders) {
|
|
|
+ TaiPingCrawlerBaseResponse<TaiPingCrawlerQueryListData> response = requestPostStrDecrypt(RequestUrl.QUERY_LIST, request, new TypeReference<>() {
|
|
|
+ }, httpHeaders);
|
|
|
+ return response.getData().getRecords().get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void policyListQuery(String Str, HttpHeaders httpHeaders) {
|
|
|
+ // 报文信息
|
|
|
+ LinkedMultiValueMap<String, Object> multiValueMap = new LinkedMultiValueMap<>();
|
|
|
+ multiValueMap.add("insuredIdNoInput", "");
|
|
|
+ multiValueMap.add("insuredIdNo", "");
|
|
|
+ multiValueMap.add("carInfoType", "");
|
|
|
+ multiValueMap.add("carInfoInput", "");
|
|
|
+ multiValueMap.add("licenseNo", "");
|
|
|
+ multiValueMap.add("frameNo", "");
|
|
|
+ multiValueMap.add("engineNo", "");
|
|
|
+ multiValueMap.add("carInfoType1", "");
|
|
|
+ multiValueMap.add("frameNo1", "");
|
|
|
+ multiValueMap.add("engineNo1", "");
|
|
|
+ multiValueMap.add("rand", "");
|
|
|
+ multiValueMap.add("randMsg", "");
|
|
|
+ multiValueMap.add("visitType", "b2c");
|
|
|
+ // 请求头
|
|
|
+ httpHeaders.set(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
|
|
|
+ ResponseEntity<String> responseEntity = webClient.post()
|
|
|
+ .uri(taiPingCrawlerProperties.getUrl() + RequestUrl.POLICY_LIST_QUERY.getUri())
|
|
|
+ .headers(RequestComponent.setHeaders(httpHeaders))
|
|
|
+ .bodyValue(multiValueMap)
|
|
|
+ .retrieve()
|
|
|
+ .toEntity(String.class)
|
|
|
+ .block();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void getCarPolicyFile(){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载非车险保单
|
|
|
+ *
|
|
|
+ * @param orderNo 订单号
|
|
|
+ * @param filePath 文件位置
|
|
|
+ * @param httpHeaders 请求头
|
|
|
+ */
|
|
|
+ public void downloadFC(String orderNo, String filePath, HttpHeaders httpHeaders) {
|
|
|
+ Path outputPath = Paths.get(filePath);
|
|
|
+ try (WritableByteChannel outputChannel = Files.newByteChannel(outputPath, StandardOpenOption.CREATE, StandardOpenOption.WRITE);) {
|
|
|
+ webClient.get()
|
|
|
+ .uri(taiPingCrawlerProperties.getUrl() + RequestUrl.DOWNLOAD_FC.uri() + orderNo)
|
|
|
+ .headers(RequestComponent.setHeaders(httpHeaders))
|
|
|
+ .accept(MediaType.APPLICATION_OCTET_STREAM)
|
|
|
+ .retrieve()
|
|
|
+ .bodyToFlux(DataBuffer.class)
|
|
|
+ .flatMap(dataBuffer -> {
|
|
|
+ Publisher<DataBuffer> publisher = Mono.just(dataBuffer);
|
|
|
+ return DataBufferUtils.write(publisher, outputChannel);
|
|
|
+ })
|
|
|
+
|
|
|
+ .blockLast();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new SystemException("文件下载失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|