|
@@ -10,6 +10,7 @@ import com.jzg.commons.entity.quote.vo.image.InsuranceImageVo;
|
|
|
import com.jzg.quotation.commons.service.ExteriorUtilsRequest;
|
|
import com.jzg.quotation.commons.service.ExteriorUtilsRequest;
|
|
|
import com.jzg.quotation.commons.standard.CrawlerRequestUrlStandard;
|
|
import com.jzg.quotation.commons.standard.CrawlerRequestUrlStandard;
|
|
|
import com.jzg.quotation.commons.utils.DateUtil;
|
|
import com.jzg.quotation.commons.utils.DateUtil;
|
|
|
|
|
+import com.jzg.quotation.commons.utils.ImageSizeUtil;
|
|
|
import com.jzg.quotation.zhongmei.api.constant.enums.ImageTypeEnum;
|
|
import com.jzg.quotation.zhongmei.api.constant.enums.ImageTypeEnum;
|
|
|
import com.jzg.quotation.zhongmei.api.entity.BaseRequestHead;
|
|
import com.jzg.quotation.zhongmei.api.entity.BaseRequestHead;
|
|
|
import com.jzg.quotation.zhongmei.api.entity.request.BaseRequest;
|
|
import com.jzg.quotation.zhongmei.api.entity.request.BaseRequest;
|
|
@@ -24,11 +25,14 @@ import com.jzg.quotation.zhongmei.crawler.properties.ZmCrawlerProperties;
|
|
|
import com.jzg.quotation.zhongmei.crawler.util.Base64Tool;
|
|
import com.jzg.quotation.zhongmei.crawler.util.Base64Tool;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import okhttp3.*;
|
|
|
|
|
+import org.apache.http.HttpResponse;
|
|
|
import org.redisson.api.RBucket;
|
|
import org.redisson.api.RBucket;
|
|
|
import org.redisson.api.RMap;
|
|
import org.redisson.api.RMap;
|
|
|
import org.redisson.api.RedissonClient;
|
|
import org.redisson.api.RedissonClient;
|
|
|
-import org.springframework.core.io.FileSystemResource;
|
|
|
|
|
import org.springframework.http.*;
|
|
import org.springframework.http.*;
|
|
|
|
|
+import org.springframework.http.MediaType;
|
|
|
|
|
+import org.springframework.http.client.MultipartBodyBuilder;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
import org.springframework.util.MultiValueMap;
|
|
@@ -41,9 +45,16 @@ import org.w3c.dom.Node;
|
|
|
import org.w3c.dom.NodeList;
|
|
import org.w3c.dom.NodeList;
|
|
|
import reactor.core.publisher.Mono;
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
|
|
+import java.io.*;
|
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.time.Duration;
|
|
import java.time.Duration;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.net.HttpURLConnection;
|
|
|
|
|
+import java.net.URL;
|
|
|
|
|
+import java.util.Scanner;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @description:
|
|
* @description:
|
|
@@ -307,64 +318,47 @@ public class ZmCrawlerRequestComponent {
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
public ZmCrawlerImageImportResponse importImage(ZmCrawlerImageImportRequest importRequest, List<InsuranceImageVo.ImageDTO> imageDTOS, List<String> cookies) {
|
|
public ZmCrawlerImageImportResponse importImage(ZmCrawlerImageImportRequest importRequest, List<InsuranceImageVo.ImageDTO> imageDTOS, List<String> cookies) {
|
|
|
- MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
|
|
|
|
|
- params.add("batchId", importRequest.getBatchId());
|
|
|
|
|
- params.add("batchVer", importRequest.getBatchVer());
|
|
|
|
|
- params.add("busiNo", importRequest.getBusiNo());
|
|
|
|
|
- params.add("appCode", importRequest.getAppCode());
|
|
|
|
|
-
|
|
|
|
|
- AtomicInteger index = new AtomicInteger(0);//标记数量
|
|
|
|
|
- Map<String, Object> imageMap = new HashMap<>();
|
|
|
|
|
- imageMap.put("base64", "data:image/jpeg;base64," + imageDTOS.get(0).getImageBase64Str());
|
|
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject imageMap = new JSONObject();
|
|
|
|
|
+ String base64Str = "data:image/jpeg;base64," + imageDTOS.get(0).getImageBase64Str();
|
|
|
|
|
+ imageMap.put("base64", base64Str);
|
|
|
imageMap.put("size", imageDTOS.get(0).getImageSize());
|
|
imageMap.put("size", imageDTOS.get(0).getImageSize());
|
|
|
imageMap.put("orginalName", imageDTOS.get(0).getImageName());
|
|
imageMap.put("orginalName", imageDTOS.get(0).getImageName());
|
|
|
- params.add("image" + (index.getAndAdd(1)), JSON.toJSONString(imageMap));
|
|
|
|
|
-// imageDTOS.forEach(image -> {
|
|
|
|
|
-//
|
|
|
|
|
-// });
|
|
|
|
|
-// HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
-// headers.set("Connection","keep-alive");
|
|
|
|
|
-// headers.set("Referer","https://image.chinacoal-ins.com/SunICMS/ecm-nview/image/webScan/webScanMain.jsp");
|
|
|
|
|
-// headers.set("Accept","*/*");
|
|
|
|
|
-// headers.set("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36");
|
|
|
|
|
-// headers.set("Cookie",cookies.get(1) + ";" + cookies.get(0));
|
|
|
|
|
-//// headers.set(HttpHeaders.CONTENT_TYPE,"multipart/form-data");
|
|
|
|
|
-// System.out.println(JSON.toJSONString(params));
|
|
|
|
|
-
|
|
|
|
|
- String response = webClient.post()
|
|
|
|
|
- .uri(RequestUrl.IMPORT_IMAGE.getUrl())
|
|
|
|
|
|
|
+ imageMap.put("exif", "");
|
|
|
|
|
+
|
|
|
|
|
+ MultiValueMap<String, Object> formData = new LinkedMultiValueMap<>();
|
|
|
|
|
+ formData.add("busiNo", importRequest.getBusiNo());
|
|
|
|
|
+ formData.add("appCode", importRequest.getAppCode());
|
|
|
|
|
+ formData.add("batchId", importRequest.getBatchId());
|
|
|
|
|
+ formData.add("batchVer", importRequest.getBatchVer());
|
|
|
|
|
+ formData.add("image0", imageMap.toJSONString());
|
|
|
|
|
+ formData.add("docCode", "UW_0302");
|
|
|
|
|
+
|
|
|
|
|
+ // 构建 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();
|
|
|
|
|
+ System.out.println(JSON.toJSONString(formData));
|
|
|
|
|
+ // 发送 POST 请求
|
|
|
|
|
+ String result = webClient.post()
|
|
|
|
|
+ .uri("/SunICMS/image/upload.action")
|
|
|
.contentType(MediaType.MULTIPART_FORM_DATA)
|
|
.contentType(MediaType.MULTIPART_FORM_DATA)
|
|
|
- .headers(headers -> {
|
|
|
|
|
-
|
|
|
|
|
-// headers.set(HttpHeaders.CONTENT_TYPE, "multipart/form-data; boundary=----WebKitFormBoundaryfnJkn2a7ZSkzt9B6"); // 或 application/json
|
|
|
|
|
- headers.set(HttpHeaders.ACCEPT, MediaType.ALL_VALUE); // 或 application/json
|
|
|
|
|
- headers.set(HttpHeaders.CONNECTION, "keep-alive");
|
|
|
|
|
- headers.set(HttpHeaders.REFERER, "https://image.chinacoal-ins.com/SunICMS/ecm-nview/image/webScan/webScanMain.jsp");
|
|
|
|
|
- headers.set(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");
|
|
|
|
|
- headers.add(HttpHeaders.COOKIE, cookies.get(1) + ";" + cookies.get(0));
|
|
|
|
|
|
|
+ .body(BodyInserters.fromMultipartData(formData))
|
|
|
|
|
+// .retrieve()
|
|
|
|
|
+ .exchangeToMono(response -> {
|
|
|
|
|
+ HttpStatusCode status = response.statusCode();
|
|
|
|
|
+ System.out.println("HTTP 状态码: " + status);
|
|
|
|
|
+ System.out.println("响应头: " + response.headers().asHttpHeaders());
|
|
|
|
|
+
|
|
|
|
|
+ return response.bodyToMono(String.class)
|
|
|
|
|
+ .doOnNext(body -> System.out.println("响应体内容:\n" + body));
|
|
|
})
|
|
})
|
|
|
- .body(BodyInserters.fromMultipartData(params)) // 替换为你构造的 MultipartBody
|
|
|
|
|
- .retrieve()
|
|
|
|
|
- .bodyToMono(String.class)
|
|
|
|
|
.block();
|
|
.block();
|
|
|
|
|
|
|
|
-// HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers);
|
|
|
|
|
-//
|
|
|
|
|
-// // 发送请求并接收响应
|
|
|
|
|
-// ResponseEntity<String> response = restTemplate.exchange(
|
|
|
|
|
-// RequestUrl.IMPORT_IMAGE.getUrl(),
|
|
|
|
|
-// HttpMethod.POST,
|
|
|
|
|
-// requestEntity,
|
|
|
|
|
-// String.class
|
|
|
|
|
-// );
|
|
|
|
|
-
|
|
|
|
|
- System.out.println(JSON.toJSONString(response));
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-// return requestComponent.formData(RequestUrl.IMPORT_IMAGE.getUrl(),
|
|
|
|
|
-// params, ZmCrawlerImageImportResponse.class, headers).getBody();
|
|
|
|
|
|
|
+ System.out.println("上传响应:\n" + result);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -920,30 +914,43 @@ 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);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|