|
|
@@ -1,6 +1,5 @@
|
|
|
package com.jzg.quotation.zijin.crawler.component;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.google.zxing.NotFoundException;
|
|
|
import com.jzg.commons.exception.SystemException;
|
|
|
@@ -10,8 +9,6 @@ import com.jzg.quotation.zijin.crawler.entity.response.*;
|
|
|
import com.jzg.quotation.zijin.crawler.properties.ZiJinCrawlerProperties;
|
|
|
import com.jzg.quotation.zijin.crawler.util.*;
|
|
|
import com.jzg.quotation.commons.component.RequestComponent;
|
|
|
-import com.jzg.quotation.commons.service.ExteriorUtilsRequest;
|
|
|
-import com.jzg.quotation.commons.utils.RequestObjectConversion;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
@@ -38,12 +35,10 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
// 循环次数
|
|
|
public static final int CIRCULATE_NUMBER = 3;
|
|
|
|
|
|
- private final ZiJinCrawlerRequestComponent ziJinCrawlerRequestComponent;
|
|
|
-
|
|
|
+
|
|
|
private final RequestComponent requestComponent;
|
|
|
|
|
|
- private final ExteriorUtilsRequest exteriorUtilsRequest;
|
|
|
-
|
|
|
+
|
|
|
private final ZiJinCrawlerProperties ziJinCrawlerProperties;
|
|
|
|
|
|
/**
|
|
|
@@ -56,16 +51,20 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
ZiJinCrawlerCaptchaResponse ziJinCrawlerCaptchaResponse = null;
|
|
|
try {
|
|
|
if (frequency <= 0) {
|
|
|
- throw new SystemException("验证码请求频次异常");
|
|
|
+ //throw new SystemException("验证码请求频次异常");
|
|
|
+ ziJinCrawlerCaptchaResponse = new ZiJinCrawlerCaptchaResponse();
|
|
|
+ ziJinCrawlerCaptchaResponse.setRtnCode("500");
|
|
|
+ ziJinCrawlerCaptchaResponse.setRtnMsg("验证码请求频次异常");
|
|
|
+ return ziJinCrawlerCaptchaResponse;
|
|
|
}
|
|
|
-
|
|
|
HttpHeaders headers = setHttpHeaders();
|
|
|
|
|
|
Map<String, String> requestBody = new HashMap<>();
|
|
|
requestBody.put("expirationType", "H5");
|
|
|
String requestUrl = RequestUrl.CAPTCHA.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()) + "?expirationType=H5";
|
|
|
// 请求
|
|
|
- ResponseEntity<ZiJinCrawlerCaptchaResponse> responseEntity = requestComponent.post(requestUrl, requestBody, ZiJinCrawlerCaptchaResponse.class, headers);
|
|
|
+ String jsonString = JSON.toJSONString(requestBody);
|
|
|
+ ResponseEntity<ZiJinCrawlerCaptchaResponse> responseEntity = requestComponent.post(requestUrl, jsonString, ZiJinCrawlerCaptchaResponse.class, headers);
|
|
|
ziJinCrawlerCaptchaResponse = responseEntity.getBody();
|
|
|
log.info("获取验证码接口响应内容:{}", JSON.toJSONString(ziJinCrawlerCaptchaResponse));
|
|
|
String captchaImg = ziJinCrawlerCaptchaResponse.getCaptchaImg();
|
|
|
@@ -75,13 +74,28 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
log.info("验证码内容:{}",captchaContent);
|
|
|
ziJinCrawlerCaptchaResponse.setCaptchaContent(captchaContent);
|
|
|
} catch (Exception e) {
|
|
|
- frequency = frequency - 1;
|
|
|
- return captcha(frequency);
|
|
|
+ e.printStackTrace();
|
|
|
+ /*frequency = frequency - 1;
|
|
|
+ return captcha(frequency);*/
|
|
|
}
|
|
|
return ziJinCrawlerCaptchaResponse;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 公共登录
|
|
|
+ *
|
|
|
+ * @param ziJinCrawlerCommonLoginRequest
|
|
|
+ * @return ZiJinCrawlerCommonLoginResponse
|
|
|
+ */
|
|
|
+ public ZiJinCrawlerCommonLoginResponse commonLogin(ZiJinCrawlerCommonLoginRequest ziJinCrawlerCommonLoginRequest) throws IOException {
|
|
|
+ log.info("ziJinCrawlerCommonLoginRequest请求参数的值:{}",JSON.toJSONString(ziJinCrawlerCommonLoginRequest));
|
|
|
|
|
|
+ HttpHeaders httpHeaders = setHttpHeaders();
|
|
|
+ httpHeaders.setContentLength(144);
|
|
|
+ String jsonString = JSON.toJSONString(ziJinCrawlerCommonLoginRequest);
|
|
|
+ ResponseEntity<ZiJinCrawlerCommonLoginResponse> responseEntity = requestComponent.post(RequestUrl.COMMONLOGIN.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()), jsonString, ZiJinCrawlerCommonLoginResponse.class, httpHeaders);
|
|
|
+ return responseEntity.getBody();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -160,7 +174,7 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
*/
|
|
|
public ZiJinCrawlerCarResponse car(ZiJinCrawlerCarRequest ziJinCrawlerCarRequest, HttpHeaders headers) throws IOException {
|
|
|
//设置headers
|
|
|
- HttpHeaders httpHeaders = ziJinCrawlerRequestComponent.setHttpHeaders();
|
|
|
+ HttpHeaders httpHeaders = setHttpHeaders();
|
|
|
String jsonString = JSON.toJSONString(ziJinCrawlerCarRequest);
|
|
|
ResponseEntity<ZiJinCrawlerCarResponse> responseEntity = requestComponent.post(RequestUrl.CAR.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()), jsonString, ZiJinCrawlerCarResponse.class, httpHeaders);
|
|
|
return responseEntity.getBody();
|
|
|
@@ -175,7 +189,7 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
*/
|
|
|
public ZiJinCrawlerGetOrderNoResponse getOrderNo(ZiJinCrawlerGetOrderNoRequest ziJinCrawlerGetOrderNoRequest, HttpHeaders headers) throws IOException {
|
|
|
//设置headers
|
|
|
- HttpHeaders httpHeaders = ziJinCrawlerRequestComponent.setHttpHeaders();
|
|
|
+ HttpHeaders httpHeaders = setHttpHeaders();
|
|
|
String jsonString = JSON.toJSONString(ziJinCrawlerGetOrderNoRequest);
|
|
|
ResponseEntity<ZiJinCrawlerGetOrderNoResponse> responseEntity = requestComponent.post(RequestUrl.GET_ORDER_NUMBER.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()), jsonString, ZiJinCrawlerGetOrderNoResponse.class, httpHeaders);
|
|
|
return responseEntity.getBody();
|
|
|
@@ -190,7 +204,7 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
*/
|
|
|
public ZiJinCrawlerGetCarActualValueResponse getCarActualValue(ZiJinCrawlerGetCarActualValueRequest ziJinCrawlerGetCarActualValueRequest, HttpHeaders headers) throws IOException {
|
|
|
//设置headers
|
|
|
- HttpHeaders httpHeaders = ziJinCrawlerRequestComponent.setHttpHeaders();
|
|
|
+ HttpHeaders httpHeaders = setHttpHeaders();
|
|
|
String jsonString = JSON.toJSONString(ziJinCrawlerGetCarActualValueRequest);
|
|
|
ResponseEntity<ZiJinCrawlerGetCarActualValueResponse> responseEntity = requestComponent.post(RequestUrl.GET_ACTUAL_VALUE.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()), jsonString, ZiJinCrawlerGetCarActualValueResponse.class, httpHeaders);
|
|
|
return responseEntity.getBody();
|
|
|
@@ -205,7 +219,7 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
*/
|
|
|
public ZiJinCrawlerQuotationResponse quotation(ZiJinCrawlerQuotationRequest ziJinCrawlerQuotationRequest, HttpHeaders headers) throws IOException {
|
|
|
//设置headers
|
|
|
- HttpHeaders httpHeaders = ziJinCrawlerRequestComponent.setHttpHeaders();
|
|
|
+ HttpHeaders httpHeaders = setHttpHeaders();
|
|
|
String jsonString = JSON.toJSONString(ziJinCrawlerQuotationRequest);
|
|
|
ResponseEntity<ZiJinCrawlerQuotationResponse> post = requestComponent.post(RequestUrl.PRICE.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()), jsonString, ZiJinCrawlerQuotationResponse.class, httpHeaders);
|
|
|
return post.getBody();
|
|
|
@@ -220,7 +234,7 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
*/
|
|
|
public ZiJinCrawlerUnderwritingResponse underwriting(ZiJinCrawlerUnderwritingRequest ziJinCrawlerUnderwritingRequest, HttpHeaders headers) throws Exception {
|
|
|
//设置headers
|
|
|
- HttpHeaders httpHeaders = ziJinCrawlerRequestComponent.setHttpHeaders();
|
|
|
+ HttpHeaders httpHeaders = setHttpHeaders();
|
|
|
String jsonString = JSON.toJSONString(ziJinCrawlerUnderwritingRequest);
|
|
|
ResponseEntity<ZiJinCrawlerUnderwritingResponse> responseEntity = requestComponent.post(RequestUrl.UNDERWRITING.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()), jsonString, ZiJinCrawlerUnderwritingResponse.class, httpHeaders);
|
|
|
return responseEntity.getBody();
|
|
|
@@ -236,7 +250,7 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
*/
|
|
|
public ZiJinCrawlerImageUploadResponse uploadImage(ZiJinCrawlerImageUploadRequest ziJinCrawlerImageUploadRequest, HttpHeaders headers) throws Exception {
|
|
|
//设置headers
|
|
|
- HttpHeaders httpHeaders = ziJinCrawlerRequestComponent.setHttpHeaders();
|
|
|
+ HttpHeaders httpHeaders = setHttpHeaders();
|
|
|
String jsonString = JSON.toJSONString(ziJinCrawlerImageUploadRequest);
|
|
|
ResponseEntity<ZiJinCrawlerImageUploadResponse> responseEntity = requestComponent.post(RequestUrl.UPLOAD_IMAGE.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()), jsonString, ZiJinCrawlerImageUploadResponse.class, httpHeaders);
|
|
|
return responseEntity.getBody();
|
|
|
@@ -253,7 +267,7 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
*/
|
|
|
public ZiJinCrawlerPaymentLinkResponse payment(ZiJinCrawlerPaymentLinkRequest ziJinCrawlerPaymentLinkRequest, HttpHeaders headers) throws NotFoundException, IOException {
|
|
|
//设置headers
|
|
|
- HttpHeaders httpHeaders = ziJinCrawlerRequestComponent.setHttpHeaders();
|
|
|
+ HttpHeaders httpHeaders = setHttpHeaders();
|
|
|
String jsonString = JSON.toJSONString(ziJinCrawlerPaymentLinkRequest);
|
|
|
ResponseEntity<ZiJinCrawlerPaymentLinkResponse> responseEntity = requestComponent.post(RequestUrl.QRCODE.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()), ziJinCrawlerPaymentLinkRequest, ZiJinCrawlerPaymentLinkResponse.class, httpHeaders);
|
|
|
return responseEntity.getBody();
|
|
|
@@ -268,7 +282,7 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
*/
|
|
|
public ZiJinCrawlerQueryOrderStatusResponse queryOrderStatus(ZiJinCrawlerQueryOrderStatusRequest ziJinCrawlerQueryOrderStatusRequest, HttpHeaders headers) throws IOException {
|
|
|
//设置headers
|
|
|
- HttpHeaders httpHeaders = ziJinCrawlerRequestComponent.setHttpHeaders();
|
|
|
+ HttpHeaders httpHeaders = setHttpHeaders();
|
|
|
String jsonString = JSON.toJSONString(ziJinCrawlerQueryOrderStatusRequest);
|
|
|
ResponseEntity<ZiJinCrawlerQueryOrderStatusResponse> responseEntity = requestComponent.post(RequestUrl.QUERY_ORDER_STATUS.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()), ziJinCrawlerQueryOrderStatusRequest,
|
|
|
ZiJinCrawlerQueryOrderStatusResponse.class, httpHeaders);
|
|
|
@@ -338,7 +352,7 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
*/
|
|
|
public ZiJinCrawlerQueryCarPolicyListResponse queryCarPolicyList(ZiJinCrawlerQueryCarPolicyListRequest ziJinCrawlerQueryCarPolicyListRequest, HttpHeaders headers) throws IOException {
|
|
|
//设置headers
|
|
|
- HttpHeaders httpHeaders = ziJinCrawlerRequestComponent.setHttpHeaders();
|
|
|
+ HttpHeaders httpHeaders = setHttpHeaders();
|
|
|
String jsonString = JSON.toJSONString(ziJinCrawlerQueryCarPolicyListRequest);
|
|
|
ResponseEntity<ZiJinCrawlerQueryCarPolicyListResponse> responseEntity = requestComponent.post(RequestUrl.QUERY_CAR_POLICY_LIST.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()), jsonString, ZiJinCrawlerQueryCarPolicyListResponse.class, httpHeaders);
|
|
|
return responseEntity.getBody();
|
|
|
@@ -354,7 +368,7 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
*/
|
|
|
public ZiJinCrawlerDownloadPolicyResponse electronPolicyIODownload(ZiJinCrawlerDownloadPolicyRequest ziJinCrawlerDownloadPolicyRequest, HttpHeaders headers) throws IOException {
|
|
|
//设置headers
|
|
|
- HttpHeaders httpHeaders = ziJinCrawlerRequestComponent.setHttpHeaders();
|
|
|
+ HttpHeaders httpHeaders = setHttpHeaders();
|
|
|
String jsonString = JSON.toJSONString(ziJinCrawlerDownloadPolicyRequest);
|
|
|
ResponseEntity<ZiJinCrawlerDownloadPolicyResponse> responseEntity = requestComponent.post(RequestUrl.ELECTRON_POLICY_IO_DOWNLOAD.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()), jsonString, ZiJinCrawlerDownloadPolicyResponse.class, httpHeaders);
|
|
|
return responseEntity.getBody();
|
|
|
@@ -384,10 +398,11 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
//获取cookie的值
|
|
|
String cookie = getCookie();
|
|
|
+ log.info("cookie的值:{}", cookie);
|
|
|
headers.set("Cookie", cookie);
|
|
|
// 设置请求头
|
|
|
headers.set("Accept", "application/json, text/plain, */*, application/problem+json");
|
|
|
- headers.set("Accept-Encoding", "gzip, deflate, br, zstd");
|
|
|
+ //headers.set("Accept-Encoding", "gzip, deflate, br, zstd");
|
|
|
headers.set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
|
|
|
headers.set("Authorization", "1B0234C742C12BD632AA5027EB3A501A");
|
|
|
headers.set("Cache-Control", "no-cache");
|