|
|
@@ -57,53 +57,14 @@ public class HengBangCrawlerRequestComponent {
|
|
|
if (frequency <= 0) {
|
|
|
throw new SystemException("验证码异常");
|
|
|
}
|
|
|
- HbCrawlerCaptchaRequest captchaRequest = new HbCrawlerCaptchaRequest();
|
|
|
// 请求
|
|
|
- HbCrawlerCaptchaResponse HbCrawlerCaptchaResponse = requestComponent.objectPost(RequestUrl.VERIFY_CODE.getRequestUrl(hbCrawlerProperties.getBaseUrl()), JSONObject.toJSONString(captchaRequest), "", HbCrawlerCaptchaResponse.class);
|
|
|
+ HbCrawlerCaptchaResponse HbCrawlerCaptchaResponse = requestComponent.objectPost(RequestUrl.VERIFY_CODE.getRequestUrl(hbCrawlerProperties.getBaseUrl()), new HbCrawlerCaptchaRequest(), "", HbCrawlerCaptchaResponse.class);
|
|
|
// 识别验证码
|
|
|
String s = exteriorUtilsRequest.captchaIdentify(HbCrawlerCaptchaResponse.getVerifyImg());
|
|
|
- try {
|
|
|
- int i = processCaptcha(s);
|
|
|
- s = String.valueOf(i);
|
|
|
- } catch (Exception e) {
|
|
|
- frequency = frequency - 1;
|
|
|
- return captcha(frequency);
|
|
|
- }
|
|
|
HbCrawlerCaptchaResponse.setVerifyCode(s);
|
|
|
return HbCrawlerCaptchaResponse;
|
|
|
}
|
|
|
|
|
|
- public int processCaptcha(String res) {
|
|
|
- // 检查字符串长度是否足够,并且第三个字符不是'='
|
|
|
- if (res.length() >= 3 && res.charAt(2) != '=') {
|
|
|
- char operator = res.charAt(1);
|
|
|
- try {
|
|
|
- int operand1 = Integer.parseInt(res.substring(0, 1));
|
|
|
- int operand2 = Integer.parseInt(res.substring(2, 3));
|
|
|
- // 注意:这里假设操作符和操作数都是有效的,实际应用中应该添加更多的错误处理
|
|
|
-
|
|
|
- switch (operator) {
|
|
|
- case '+':
|
|
|
- case 'f': // 通常'f'不是加法运算符,但根据原代码保留
|
|
|
- return operand1 + operand2;
|
|
|
- case 'x':
|
|
|
- case 'X':
|
|
|
- case '4': // 通常'4'不是乘法运算符,但保留以匹配原代码
|
|
|
- case '9': // 通常'9'也不是乘法运算符,但保留以匹配原代码
|
|
|
- return operand1 * operand2;
|
|
|
- case '-':
|
|
|
- case 'e': // 通常'e'不是减法运算符,但根据原代码保留
|
|
|
- case '=': // 通常'='不是减法运算符,但根据原代码保留
|
|
|
- case '2': // 通常'2'也不是减法运算符,但根据原代码保留
|
|
|
- return operand1 - operand2;
|
|
|
- // 如果操作符不匹配,则获取新的验证码图片(模拟)
|
|
|
- }
|
|
|
- } catch (NumberFormatException ignored) {
|
|
|
- }
|
|
|
- }
|
|
|
- throw new SystemException("");
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 登录次数
|
|
|
*
|
|
|
@@ -117,7 +78,7 @@ public class HengBangCrawlerRequestComponent {
|
|
|
HbCrawlerCaptchaResponse captchaResponse = captcha(RequestConstant.REQUEST_NUMBER);
|
|
|
// 登录存入缓存当中
|
|
|
HbCrawlerAuthenticateRequest authenticateRequest = new HbCrawlerAuthenticateRequest(captchaResponse, username, password);
|
|
|
- ResponseEntity<HbCrawlerAuthenticateResponse> responseEntity = requestComponent.objectPost(RequestUrl.AUTHENTICATE.getRequestUrl(hbCrawlerProperties.getBaseUrl()), JSONObject.toJSONString(authenticateRequest), HbCrawlerAuthenticateResponse.class);
|
|
|
+ ResponseEntity<HbCrawlerAuthenticateResponse> responseEntity = requestComponent.objectPost(RequestUrl.AUTHENTICATE.getRequestUrl(hbCrawlerProperties.getBaseUrl()), authenticateRequest, HbCrawlerAuthenticateResponse.class);
|
|
|
HbCrawlerAuthenticateResponse authenticateResponse = Optional.of(responseEntity)
|
|
|
.map(ResponseEntity::getBody)
|
|
|
.orElseThrow();
|