|
@@ -35,10 +35,10 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
// 循环次数
|
|
// 循环次数
|
|
|
public static final int CIRCULATE_NUMBER = 3;
|
|
public static final int CIRCULATE_NUMBER = 3;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
private final RequestComponent requestComponent;
|
|
private final RequestComponent requestComponent;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
private final ZiJinCrawlerProperties ziJinCrawlerProperties;
|
|
private final ZiJinCrawlerProperties ziJinCrawlerProperties;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -59,9 +59,9 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
}
|
|
}
|
|
|
HttpHeaders headers = setHttpHeaders();
|
|
HttpHeaders headers = setHttpHeaders();
|
|
|
|
|
|
|
|
|
|
+ String requestUrl = RequestUrl.CAPTCHA.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()) + "?expirationType=H5";
|
|
|
Map<String, String> requestBody = new HashMap<>();
|
|
Map<String, String> requestBody = new HashMap<>();
|
|
|
requestBody.put("expirationType", "H5");
|
|
requestBody.put("expirationType", "H5");
|
|
|
- String requestUrl = RequestUrl.CAPTCHA.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()) + "?expirationType=H5";
|
|
|
|
|
// 请求
|
|
// 请求
|
|
|
String jsonString = JSON.toJSONString(requestBody);
|
|
String jsonString = JSON.toJSONString(requestBody);
|
|
|
ResponseEntity<ZiJinCrawlerCaptchaResponse> responseEntity = requestComponent.post(requestUrl, jsonString, ZiJinCrawlerCaptchaResponse.class, headers);
|
|
ResponseEntity<ZiJinCrawlerCaptchaResponse> responseEntity = requestComponent.post(requestUrl, jsonString, ZiJinCrawlerCaptchaResponse.class, headers);
|
|
@@ -71,7 +71,7 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
String captcha = captchaImg.split(",")[1].trim();
|
|
String captcha = captchaImg.split(",")[1].trim();
|
|
|
// 识别验证码的内容
|
|
// 识别验证码的内容
|
|
|
String captchaContent = CaptchaUtil.performOCR(captcha);
|
|
String captchaContent = CaptchaUtil.performOCR(captcha);
|
|
|
- log.info("验证码内容:{}",captchaContent);
|
|
|
|
|
|
|
+ log.info("验证码内容:{}", captchaContent);
|
|
|
ziJinCrawlerCaptchaResponse.setCaptchaContent(captchaContent);
|
|
ziJinCrawlerCaptchaResponse.setCaptchaContent(captchaContent);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -88,7 +88,7 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
* @return ZiJinCrawlerCommonLoginResponse
|
|
* @return ZiJinCrawlerCommonLoginResponse
|
|
|
*/
|
|
*/
|
|
|
public ZiJinCrawlerCommonLoginResponse commonLogin(ZiJinCrawlerCommonLoginRequest ziJinCrawlerCommonLoginRequest) throws IOException {
|
|
public ZiJinCrawlerCommonLoginResponse commonLogin(ZiJinCrawlerCommonLoginRequest ziJinCrawlerCommonLoginRequest) throws IOException {
|
|
|
- log.info("ziJinCrawlerCommonLoginRequest请求参数的值:{}",JSON.toJSONString(ziJinCrawlerCommonLoginRequest));
|
|
|
|
|
|
|
+ log.info("ziJinCrawlerCommonLoginRequest请求参数的值:{}", JSON.toJSONString(ziJinCrawlerCommonLoginRequest));
|
|
|
|
|
|
|
|
HttpHeaders httpHeaders = setHttpHeaders();
|
|
HttpHeaders httpHeaders = setHttpHeaders();
|
|
|
httpHeaders.setContentLength(144);
|
|
httpHeaders.setContentLength(144);
|
|
@@ -99,17 +99,21 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- *校验验证码
|
|
|
|
|
|
|
+ * 校验验证码并获取token
|
|
|
*
|
|
*
|
|
|
* @param ziJinCrawlerCheckCaptchaRequest
|
|
* @param ziJinCrawlerCheckCaptchaRequest
|
|
|
* @return ZiJinCrawlerCheckCaptchaResponse
|
|
* @return ZiJinCrawlerCheckCaptchaResponse
|
|
|
*/
|
|
*/
|
|
|
- public ZiJinCrawlerCheckCaptchaResponse checkCaptchaAndGetToken(ZiJinCrawlerCheckCaptchaRequest ziJinCrawlerCheckCaptchaRequest) throws IOException {
|
|
|
|
|
- log.info("ziJinCrawlerCheckCaptchaRequest请求参数的值:{}",JSON.toJSONString(ziJinCrawlerCheckCaptchaRequest));
|
|
|
|
|
|
|
+ public ZiJinCrawlerCheckCaptchaResponse checkCaptchaAndGetToken(ZiJinCrawlerCheckCaptchaRequest ziJinCrawlerCheckCaptchaRequest,String token) throws IOException {
|
|
|
|
|
+ log.info("ziJinCrawlerCheckCaptchaRequest请求参数的值:{}", JSON.toJSONString(ziJinCrawlerCheckCaptchaRequest));
|
|
|
|
|
|
|
|
HttpHeaders httpHeaders = setHttpHeaders();
|
|
HttpHeaders httpHeaders = setHttpHeaders();
|
|
|
httpHeaders.setContentLength(289);
|
|
httpHeaders.setContentLength(289);
|
|
|
- ResponseEntity<ZiJinCrawlerCheckCaptchaResponse> responseEntity = requestComponent.post(RequestUrl.CHECKCAPTCHAANDGETTOKEN.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()), ziJinCrawlerCheckCaptchaRequest, ZiJinCrawlerCheckCaptchaResponse.class, httpHeaders);
|
|
|
|
|
|
|
+ //需要单独设置这个
|
|
|
|
|
+ httpHeaders.set("Authorization", token);
|
|
|
|
|
+ httpHeaders.set("loginToken", token);
|
|
|
|
|
+ String jsonString = JSON.toJSONString(ziJinCrawlerCheckCaptchaRequest);
|
|
|
|
|
+ ResponseEntity<ZiJinCrawlerCheckCaptchaResponse> responseEntity = requestComponent.post(RequestUrl.CHECKCAPTCHAANDGETTOKEN.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()), jsonString, ZiJinCrawlerCheckCaptchaResponse.class, httpHeaders);
|
|
|
return responseEntity.getBody();
|
|
return responseEntity.getBody();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -117,15 +121,19 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
* 校验token
|
|
* 校验token
|
|
|
*
|
|
*
|
|
|
* @param ziJinCrawlerCheckTokenRequest
|
|
* @param ziJinCrawlerCheckTokenRequest
|
|
|
|
|
+ * @param token
|
|
|
* @return ZiJinCrawlerCheckTokenResponse
|
|
* @return ZiJinCrawlerCheckTokenResponse
|
|
|
*/
|
|
*/
|
|
|
- public ZiJinCrawlerCheckTokenResponse checkToken(ZiJinCrawlerCheckTokenRequest ziJinCrawlerCheckTokenRequest) throws IOException {
|
|
|
|
|
- log.info("ziJinCrawlerCheckTokenRequest请求参数的值:{}",JSON.toJSONString(ziJinCrawlerCheckTokenRequest));
|
|
|
|
|
|
|
+ public ZiJinCrawlerCheckTokenResponse checkToken(ZiJinCrawlerCheckTokenRequest ziJinCrawlerCheckTokenRequest,String token) throws IOException {
|
|
|
|
|
+ log.info("ziJinCrawlerCheckTokenRequest请求参数的值:{}", JSON.toJSONString(ziJinCrawlerCheckTokenRequest));
|
|
|
|
|
|
|
|
HttpHeaders httpHeaders = setHttpHeaders();
|
|
HttpHeaders httpHeaders = setHttpHeaders();
|
|
|
- //需要单独设置这个
|
|
|
|
|
httpHeaders.setContentLength(66);
|
|
httpHeaders.setContentLength(66);
|
|
|
- ResponseEntity<ZiJinCrawlerCheckTokenResponse> responseEntity = requestComponent.post(RequestUrl.CHECK_TOKEN.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()), ziJinCrawlerCheckTokenRequest, ZiJinCrawlerCheckTokenResponse.class, httpHeaders);
|
|
|
|
|
|
|
+ //需要单独设置这个
|
|
|
|
|
+ httpHeaders.set("Authorization", token);
|
|
|
|
|
+ httpHeaders.set("loginToken", token);
|
|
|
|
|
+ String jsonString = JSON.toJSONString(ziJinCrawlerCheckTokenRequest);
|
|
|
|
|
+ ResponseEntity<ZiJinCrawlerCheckTokenResponse> responseEntity = requestComponent.post(RequestUrl.CHECK_TOKEN.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()), jsonString, ZiJinCrawlerCheckTokenResponse.class, httpHeaders);
|
|
|
return responseEntity.getBody();
|
|
return responseEntity.getBody();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -175,6 +183,7 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
public ZiJinCrawlerCarResponse car(ZiJinCrawlerCarRequest ziJinCrawlerCarRequest, HttpHeaders headers) throws IOException {
|
|
public ZiJinCrawlerCarResponse car(ZiJinCrawlerCarRequest ziJinCrawlerCarRequest, HttpHeaders headers) throws IOException {
|
|
|
//设置headers
|
|
//设置headers
|
|
|
HttpHeaders httpHeaders = setHttpHeaders();
|
|
HttpHeaders httpHeaders = setHttpHeaders();
|
|
|
|
|
+
|
|
|
String jsonString = JSON.toJSONString(ziJinCrawlerCarRequest);
|
|
String jsonString = JSON.toJSONString(ziJinCrawlerCarRequest);
|
|
|
ResponseEntity<ZiJinCrawlerCarResponse> responseEntity = requestComponent.post(RequestUrl.CAR.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()), jsonString, ZiJinCrawlerCarResponse.class, httpHeaders);
|
|
ResponseEntity<ZiJinCrawlerCarResponse> responseEntity = requestComponent.post(RequestUrl.CAR.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()), jsonString, ZiJinCrawlerCarResponse.class, httpHeaders);
|
|
|
return responseEntity.getBody();
|
|
return responseEntity.getBody();
|
|
@@ -237,7 +246,7 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
HttpHeaders httpHeaders = setHttpHeaders();
|
|
HttpHeaders httpHeaders = setHttpHeaders();
|
|
|
String jsonString = JSON.toJSONString(ziJinCrawlerUnderwritingRequest);
|
|
String jsonString = JSON.toJSONString(ziJinCrawlerUnderwritingRequest);
|
|
|
ResponseEntity<ZiJinCrawlerUnderwritingResponse> responseEntity = requestComponent.post(RequestUrl.UNDERWRITING.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()), jsonString, ZiJinCrawlerUnderwritingResponse.class, httpHeaders);
|
|
ResponseEntity<ZiJinCrawlerUnderwritingResponse> responseEntity = requestComponent.post(RequestUrl.UNDERWRITING.getRequestUrl(ziJinCrawlerProperties.getBaseUrl()), jsonString, ZiJinCrawlerUnderwritingResponse.class, httpHeaders);
|
|
|
- return responseEntity.getBody();
|
|
|
|
|
|
|
+ return responseEntity.getBody();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -257,7 +266,6 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取支付链接
|
|
* 获取支付链接
|
|
|
*
|
|
*
|
|
@@ -377,6 +385,7 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取Cookie的值
|
|
* 获取Cookie的值
|
|
|
|
|
+ *
|
|
|
* @return String
|
|
* @return String
|
|
|
* @throws IOException
|
|
* @throws IOException
|
|
|
*/
|
|
*/
|
|
@@ -389,6 +398,7 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 设置HTTP请求头
|
|
* 设置HTTP请求头
|
|
|
|
|
+ *
|
|
|
* @return HttpHeaders
|
|
* @return HttpHeaders
|
|
|
* @throws IOException
|
|
* @throws IOException
|
|
|
*/
|
|
*/
|
|
@@ -398,7 +408,6 @@ public class ZiJinCrawlerRequestComponent {
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
//获取cookie的值
|
|
//获取cookie的值
|
|
|
String cookie = getCookie();
|
|
String cookie = getCookie();
|
|
|
- log.info("cookie的值:{}", cookie);
|
|
|
|
|
headers.set("Cookie", cookie);
|
|
headers.set("Cookie", cookie);
|
|
|
// 设置请求头
|
|
// 设置请求头
|
|
|
headers.set("Accept", "application/json, text/plain, */*, application/problem+json");
|
|
headers.set("Accept", "application/json, text/plain, */*, application/problem+json");
|