|
|
@@ -3,6 +3,7 @@ package com.jzg.quotation.zhongmei.crawler.component;
|
|
|
import cn.hutool.core.util.XmlUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.jzg.commons.entity.quote.vo.AttributionInformationVo;
|
|
|
import com.jzg.commons.exception.SystemException;
|
|
|
import com.jzg.quotation.commons.component.RequestComponent;
|
|
|
import com.jzg.quotation.commons.constant.CacheConstant;
|
|
|
@@ -10,6 +11,7 @@ import com.jzg.commons.entity.quote.vo.image.InsuranceImageVo;
|
|
|
import com.jzg.quotation.commons.service.ExteriorUtilsRequest;
|
|
|
import com.jzg.quotation.commons.standard.CrawlerRequestUrlStandard;
|
|
|
import com.jzg.quotation.commons.utils.DateUtil;
|
|
|
+import com.jzg.quotation.commons.utils.RequestObjectConversion;
|
|
|
import com.jzg.quotation.zhongmei.api.constant.enums.ImageTypeEnum;
|
|
|
import com.jzg.quotation.zhongmei.api.entity.BaseRequestHead;
|
|
|
import com.jzg.quotation.zhongmei.api.entity.request.BaseRequest;
|
|
|
@@ -27,11 +29,14 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.redisson.api.RBucket;
|
|
|
import org.redisson.api.RMap;
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
-import org.springframework.http.HttpHeaders;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.http.*;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.client.MultipartBodyBuilder;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+import org.springframework.web.reactive.function.BodyInserters;
|
|
|
import org.springframework.web.reactive.function.client.WebClient;
|
|
|
import org.w3c.dom.Document;
|
|
|
import org.w3c.dom.Element;
|
|
|
@@ -39,9 +44,14 @@ import org.w3c.dom.Node;
|
|
|
import org.w3c.dom.NodeList;
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
+import java.io.*;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.time.Duration;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
+import java.util.Scanner;
|
|
|
|
|
|
/**
|
|
|
* @description:
|
|
|
@@ -56,6 +66,7 @@ public class ZmCrawlerRequestComponent {
|
|
|
private final WebClient webClient;
|
|
|
|
|
|
private final RequestComponent requestComponent;
|
|
|
+ private final RestTemplate restTemplate;
|
|
|
|
|
|
private final RedissonClient redissonClient;
|
|
|
|
|
|
@@ -186,11 +197,17 @@ public class ZmCrawlerRequestComponent {
|
|
|
/**
|
|
|
* 获取授权信息
|
|
|
*
|
|
|
- * @param username 用户名
|
|
|
+ * @param attributionInformationVo 用户名
|
|
|
* @return 授权token
|
|
|
*/
|
|
|
- public String getAuthorization(String username) {
|
|
|
- return (String) redissonClient.getMap(CacheConstant.ZHONGMEI_AUTHORIZATION + username).get(AUTHORIZATION);
|
|
|
+ public String getAuthorization(AttributionInformationVo attributionInformationVo) {
|
|
|
+ String authorization = (String) redissonClient.getMap(CacheConstant.ZHONGMEI_AUTHORIZATION + attributionInformationVo.getUsername()).get(AUTHORIZATION);
|
|
|
+ if (!org.springframework.util.StringUtils.hasLength(authorization)) {
|
|
|
+ authorization = authenticate(attributionInformationVo.getUsername(),
|
|
|
+ attributionInformationVo.getPassword(),
|
|
|
+ ZmCrawlerRequestComponent.REQUEST_NUMBER);
|
|
|
+ }
|
|
|
+ return authorization;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -298,27 +315,39 @@ public class ZmCrawlerRequestComponent {
|
|
|
|
|
|
/**
|
|
|
* 导入影像
|
|
|
+ *
|
|
|
* @param importRequest
|
|
|
+ * @param cookies
|
|
|
* @return
|
|
|
*/
|
|
|
- public ZmCrawlerImageImportResponse importImage(ZmCrawlerImageImportRequest importRequest, List<InsuranceImageVo.ImageDTO> imageDTOS) {
|
|
|
- MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
|
|
|
- params.put("batchId", Collections.singletonList(importRequest.getBatchId()));
|
|
|
- params.put("batchVer", Collections.singletonList(importRequest.getBatchVer()));
|
|
|
- params.put("busiNo", Collections.singletonList(importRequest.getBusiNo()));
|
|
|
- params.put("appCode", Collections.singletonList(importRequest.getAppCode()));
|
|
|
-
|
|
|
- AtomicInteger index = new AtomicInteger(0);//标记数量
|
|
|
- imageDTOS.forEach(image -> {
|
|
|
- Map<String, Object> imageMap = new HashMap<>();
|
|
|
- imageMap.put("base64", image.getImageBase64Str());
|
|
|
- imageMap.put("size", image.getImageSize());
|
|
|
- imageMap.put("orginalName", image.getImageName());
|
|
|
- params.put("image" + (index.getAndAdd(1)), Collections.singletonList(imageMap));
|
|
|
- });
|
|
|
-
|
|
|
- return requestComponent.formData(RequestUrl.IMPORT_IMAGE.getRequestUrl(zmCrawlerProperties.getImageUrl()),
|
|
|
- params, ZmCrawlerImageImportResponse.class, null).getBody();
|
|
|
+ public ZmCrawlerImageImportResponse importImage(ZmCrawlerImageImportRequest importRequest, List<InsuranceImageVo.ImageDTO> imageDTOS, List<String> cookies) {
|
|
|
+
|
|
|
+ MultiValueMap<String, Object> formData = RequestObjectConversion.convertMultiValueMap(importRequest);
|
|
|
+ JSONObject imageMap = new JSONObject();
|
|
|
+ String base64Str = "data:image/jpeg;base64," + imageDTOS.get(0).getImageBase64Str();
|
|
|
+ imageMap.put("base64", base64Str);
|
|
|
+ imageMap.put("size", base64Str.length());
|
|
|
+ imageMap.put("orginalName", imageDTOS.get(0).getImageName());
|
|
|
+ imageMap.put("exif", "");
|
|
|
+ formData.add("image0", imageMap.toJSONString());
|
|
|
+
|
|
|
+ // 构建 WebClient 实例
|
|
|
+ WebClient webClient = WebClient.builder()
|
|
|
+ .baseUrl("https://image.chinacoal-ins.com")
|
|
|
+ .defaultHeader(HttpHeaders.COOKIE, cookies.get(1) + ";" + cookies.get(0))
|
|
|
+ .defaultHeader(HttpHeaders.USER_AGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36")
|
|
|
+ .defaultHeader(HttpHeaders.REFERER, "https://image.chinacoal-ins.com/SunICMS/ecm-nview/image/webScan/webScanMain.jsp")
|
|
|
+ .build();
|
|
|
+ // 发送 POST 请求
|
|
|
+ String response = webClient.post()
|
|
|
+ .uri("/SunICMS/image/upload.action")
|
|
|
+ .contentType(MediaType.MULTIPART_FORM_DATA)
|
|
|
+ .body(BodyInserters.fromValue(formData))
|
|
|
+ .retrieve()
|
|
|
+ .bodyToMono(String.class)
|
|
|
+ .block();
|
|
|
+ ZmCrawlerImageImportResponse res = JSON.parseObject(response).getJSONObject("0").toJavaObject(ZmCrawlerImageImportResponse.class);
|
|
|
+ return res;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -791,7 +820,10 @@ public class ZmCrawlerRequestComponent {
|
|
|
* @return
|
|
|
*/
|
|
|
public ZmCrawlerOrderStatusResponse orderStatusQuery(ZmCrawlerOrderStatusRequest orderStatusRequest) {
|
|
|
- return request(RequestUrl.ORDER_STATUS_QUERY, orderStatusRequest, ZmCrawlerOrderStatusResponse.class);
|
|
|
+ Mono<ZmCrawlerOrderStatusResponse> responseMono = requestComponent.postGbk(RequestUrl.ORDER_STATUS_QUERY.getRequestUrl(zmCrawlerProperties.getBaseUrl()),
|
|
|
+ Base64Tool.encode(JSONObject.toJSONString(orderStatusRequest)), ZmCrawlerOrderStatusResponse.class,new HttpHeaders());
|
|
|
+ ZmCrawlerOrderStatusResponse response = responseMono.block();
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -800,7 +832,10 @@ public class ZmCrawlerRequestComponent {
|
|
|
* @return
|
|
|
*/
|
|
|
public ZmCrawlerSubmitResponse submit(ZmCrawlerSubmitRequest submitRequest) {
|
|
|
- return request(RequestUrl.SUBMIT, submitRequest, ZmCrawlerSubmitResponse.class);
|
|
|
+ Mono<ZmCrawlerSubmitResponse> responseMono = requestComponent.postGbk(RequestUrl.SUBMIT.getRequestUrl(zmCrawlerProperties.getBaseUrl()),
|
|
|
+ Base64Tool.encode(JSONObject.toJSONString(submitRequest)), ZmCrawlerSubmitResponse.class,new HttpHeaders());
|
|
|
+ ZmCrawlerSubmitResponse response = responseMono.block();
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -809,7 +844,10 @@ public class ZmCrawlerRequestComponent {
|
|
|
* @return
|
|
|
*/
|
|
|
public ZmCrawlerCheckPaymentResponse checkPayment(ZmCrawlerCheckPaymentRequest checkPaymentRequest) {
|
|
|
- return request(RequestUrl.CHECK_PAYMENT, checkPaymentRequest, ZmCrawlerCheckPaymentResponse.class);
|
|
|
+ Mono<ZmCrawlerCheckPaymentResponse> responseMono = requestComponent.postGbk(RequestUrl.CHECK_PAYMENT.getRequestUrl(zmCrawlerProperties.getBaseUrl()),
|
|
|
+ Base64Tool.encode(JSONObject.toJSONString(checkPaymentRequest)), ZmCrawlerCheckPaymentResponse.class,new HttpHeaders());
|
|
|
+ ZmCrawlerCheckPaymentResponse response = responseMono.block();
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -818,7 +856,10 @@ public class ZmCrawlerRequestComponent {
|
|
|
* @return
|
|
|
*/
|
|
|
public ZmCrawlerFindZfTaskResponse findZfTask(ZmCrawlerFindZfTaskRequest findZfTaskRequest) {
|
|
|
- return request(RequestUrl.FIND_ZF_TASK, findZfTaskRequest, ZmCrawlerFindZfTaskResponse.class);
|
|
|
+ Mono<ZmCrawlerFindZfTaskResponse> responseMono = requestComponent.postGbk(RequestUrl.FIND_ZF_TASK.getRequestUrl(zmCrawlerProperties.getBaseUrl()),
|
|
|
+ Base64Tool.encode(JSONObject.toJSONString(findZfTaskRequest)), ZmCrawlerFindZfTaskResponse.class,new HttpHeaders());
|
|
|
+ ZmCrawlerFindZfTaskResponse response = responseMono.block();
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -827,7 +868,10 @@ public class ZmCrawlerRequestComponent {
|
|
|
* @return
|
|
|
*/
|
|
|
public ZmCrawlerOrderApplyResponse orderApply(ZmCrawlerOrderApplyRequest orderApplyRequest) {
|
|
|
- return request(RequestUrl.ORDER_APPLY, orderApplyRequest, ZmCrawlerOrderApplyResponse.class);
|
|
|
+ Mono<ZmCrawlerOrderApplyResponse> responseMono = requestComponent.postGbk(RequestUrl.ORDER_APPLY.getRequestUrl(zmCrawlerProperties.getBaseUrl()),
|
|
|
+ Base64Tool.encode(JSONObject.toJSONString(orderApplyRequest)), ZmCrawlerOrderApplyResponse.class,new HttpHeaders());
|
|
|
+ ZmCrawlerOrderApplyResponse response = responseMono.block();
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -836,7 +880,10 @@ public class ZmCrawlerRequestComponent {
|
|
|
* @return
|
|
|
*/
|
|
|
public ZmCrawlerOrderUpdateResponse orderUpdate(ZmCrawlerOrderUpdateRequest orderApplyRequest) {
|
|
|
- return request(RequestUrl.ORDER_UPDATE, orderApplyRequest, ZmCrawlerOrderUpdateResponse.class);
|
|
|
+ Mono<ZmCrawlerOrderUpdateResponse> responseMono = requestComponent.postGbk(RequestUrl.ORDER_UPDATE.getRequestUrl(zmCrawlerProperties.getBaseUrl()),
|
|
|
+ Base64Tool.encode(JSONObject.toJSONString(orderApplyRequest)), ZmCrawlerOrderUpdateResponse.class,new HttpHeaders());
|
|
|
+ ZmCrawlerOrderUpdateResponse response = responseMono.block();
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -845,7 +892,10 @@ public class ZmCrawlerRequestComponent {
|
|
|
* @return
|
|
|
*/
|
|
|
public ZmCrawlerGetQrCodeResponse getQrCode(ZmCrawlerGetQrCodeRequest qrCodeRequest) {
|
|
|
- return request(RequestUrl.ACHIEVE_QR_CODE, qrCodeRequest, ZmCrawlerGetQrCodeResponse.class );
|
|
|
+ Mono<ZmCrawlerGetQrCodeResponse> responseMono = requestComponent.postGbk(RequestUrl.ACHIEVE_QR_CODE.getRequestUrl(zmCrawlerProperties.getBaseUrl()),
|
|
|
+ Base64Tool.encode(JSONObject.toJSONString(qrCodeRequest)), ZmCrawlerGetQrCodeResponse.class,new HttpHeaders());
|
|
|
+ ZmCrawlerGetQrCodeResponse response = responseMono.block();
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -854,7 +904,10 @@ public class ZmCrawlerRequestComponent {
|
|
|
* @return
|
|
|
*/
|
|
|
public ZmCrawlerPolicyPrintResponse policyPrint(ZmCrawlerPolicyPrintRequest printRequest) {
|
|
|
- return request(RequestUrl.POLICY_PRINT, printRequest, ZmCrawlerPolicyPrintResponse.class );
|
|
|
+ Mono<ZmCrawlerPolicyPrintResponse> responseMono = requestComponent.postGbk(RequestUrl.POLICY_PRINT.getRequestUrl(zmCrawlerProperties.getBaseUrl()),
|
|
|
+ Base64Tool.encode(JSONObject.toJSONString(printRequest)), ZmCrawlerPolicyPrintResponse.class,new HttpHeaders());
|
|
|
+ ZmCrawlerPolicyPrintResponse response = responseMono.block();
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -869,31 +922,42 @@ public class ZmCrawlerRequestComponent {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
- System.out.println(Base64Tool.encode(JSONObject.toJSONString("{\n" +
|
|
|
- " \"head\": {\n" +
|
|
|
- " \"token\": \"sinhRNuIos20250624155233333oftJ29pr\",\n" +
|
|
|
- " \"transType\": \"Req\",\n" +
|
|
|
- " \"transCode\": \"ModelsQuery\",\n" +
|
|
|
- " \"source\": \"2\"\n" +
|
|
|
- " },\n" +
|
|
|
- " \"loginCom\": \"14091100\",\n" +
|
|
|
- " \"modelName\": \"宝马BMW7201AN轿车\",\n" +
|
|
|
- " \"brand\": \"\",\n" +
|
|
|
- " \"carYear\": \"\",\n" +
|
|
|
- " \"carType\": \"\",\n" +
|
|
|
- " \"deptcode\": \"\",\n" +
|
|
|
- " \"displacement\": \"\",\n" +
|
|
|
- " \"factory\": \"\",\n" +
|
|
|
- " \"purchasepricenottaxMin\": \"\",\n" +
|
|
|
- " \"purchasepricenottaxMax\": \"\",\n" +
|
|
|
- " \"motorMainType\": \"100\",\n" +
|
|
|
- " \"modelCode\": \"\",\n" +
|
|
|
- " \"planCode\": \"1379\",\n" +
|
|
|
- " \"vin\": \"LBVKY1105LSS79828\",\n" +
|
|
|
- " \"platModelCode\": \"\"\n" +
|
|
|
- " }")));
|
|
|
+ public void main(String[] args) throws IOException {
|
|
|
+ URL url = new URL("https://image.chinacoal-ins.com/SunICMS/image/upload.action");
|
|
|
+ HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
|
|
|
+ httpConn.setRequestMethod("POST");
|
|
|
+
|
|
|
+ httpConn.setRequestProperty("Accept", "*/*");
|
|
|
+ httpConn.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.9");
|
|
|
+ httpConn.setRequestProperty("Connection", "keep-alive");
|
|
|
+ httpConn.setRequestProperty("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundarysPT9lJRCIggU9p9g");
|
|
|
+ httpConn.setRequestProperty("Cookie", "lockMark=7949163776655031; skin-color=skin-db; initLeftWidth=257; JSESSIONID=TKmDo0fOt1Px11jeS2Wrn3-8w0rf9OFh_kSRI10VRfPWGTF9v-06!-1777400058");
|
|
|
+ httpConn.setRequestProperty("Origin", "https://image.chinacoal-ins.com");
|
|
|
+ httpConn.setRequestProperty("Referer", "https://image.chinacoal-ins.com/SunICMS/ecm-nview/image/webScan/webScanMain.jsp");
|
|
|
+ httpConn.setRequestProperty("Sec-Fetch-Dest", "empty");
|
|
|
+ httpConn.setRequestProperty("Sec-Fetch-Mode", "cors");
|
|
|
+ httpConn.setRequestProperty("Sec-Fetch-Site", "same-origin");
|
|
|
+ httpConn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36");
|
|
|
+ httpConn.setRequestProperty("sec-ch-ua", "\"Not=A?Brand\";v=\"99\", \"Chromium\";v=\"118\"");
|
|
|
+ httpConn.setRequestProperty("sec-ch-ua-mobile", "?0");
|
|
|
+ httpConn.setRequestProperty("sec-ch-ua-platform", "\"Windows\"");
|
|
|
+
|
|
|
+ httpConn.setDoOutput(true);
|
|
|
+ OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
|
|
|
+ String template = new String(
|
|
|
+ getClass().getClassLoader().getResourceAsStream("template.txt").readAllBytes(),
|
|
|
+ StandardCharsets.UTF_8
|
|
|
+ );
|
|
|
+ writer.write(template);
|
|
|
+ writer.flush();
|
|
|
+ writer.close();
|
|
|
+ httpConn.getOutputStream().close();
|
|
|
+
|
|
|
+ InputStream responseStream = httpConn.getResponseCode() / 100 == 2
|
|
|
+ ? httpConn.getInputStream()
|
|
|
+ : httpConn.getErrorStream();
|
|
|
+ Scanner s = new Scanner(responseStream).useDelimiter("A");
|
|
|
+ String response = s.hasNext() ? s.next() : "";
|
|
|
+ System.out.println(response);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|