|
@@ -1,687 +1,464 @@
|
|
|
package com.jzg.quotation.huatai.crawler.util;
|
|
package com.jzg.quotation.huatai.crawler.util;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
+import com.jzg.quotation.huatai.crawler.properties.HuaTaiCrawlerProperties;
|
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.http.*;
|
|
import org.springframework.http.*;
|
|
|
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
|
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
+import com.jzg.commons.util.StringUtils;
|
|
|
|
|
|
|
|
import javax.net.ssl.*;
|
|
import javax.net.ssl.*;
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.net.HttpURLConnection;
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.InetSocketAddress;
|
|
import java.net.InetSocketAddress;
|
|
|
import java.net.Proxy;
|
|
import java.net.Proxy;
|
|
|
|
|
+import java.security.SecureRandom;
|
|
|
import java.security.cert.X509Certificate;
|
|
import java.security.cert.X509Certificate;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 华泰爬虫登录工具类(单例+ThreadLocal线程隔离)
|
|
|
|
|
+ * 负责登录、Cookie维护、归属信息拉取、前置接口请求
|
|
|
|
|
+ */
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@Component
|
|
|
|
|
+@RequiredArgsConstructor
|
|
|
public class CookieUtils {
|
|
public class CookieUtils {
|
|
|
- private final ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
-
|
|
|
|
|
- private final String baseUrl = "https://cspxp.pc.ehuatai.com/htcsp";
|
|
|
|
|
-
|
|
|
|
|
- // 车辆信息
|
|
|
|
|
- private String licenseNo;
|
|
|
|
|
- private String vin;
|
|
|
|
|
- private String registerDate;
|
|
|
|
|
- private String energyType;
|
|
|
|
|
- private String modelCName;
|
|
|
|
|
- private String engineNo;
|
|
|
|
|
- private String seat;
|
|
|
|
|
- private String purchasePrice;
|
|
|
|
|
- private String vehicleUse;
|
|
|
|
|
- private String limitLoad;
|
|
|
|
|
- private String cartype;
|
|
|
|
|
- private String completeKerbMass;
|
|
|
|
|
- private String cimodelclass;
|
|
|
|
|
- private String motorTypeCode;
|
|
|
|
|
- private String motorUsageTypeCode;
|
|
|
|
|
- private String motortypecode;
|
|
|
|
|
-
|
|
|
|
|
- // 归属信息
|
|
|
|
|
- private String ywlyName;
|
|
|
|
|
- private String xstxCode;
|
|
|
|
|
- private String dlrCode;
|
|
|
|
|
- private String dlxyCode;
|
|
|
|
|
- private Map<String, Object> gsInfo = new HashMap<>();
|
|
|
|
|
-
|
|
|
|
|
- // cookies
|
|
|
|
|
- private String jsessionId = "";
|
|
|
|
|
- private String bigIpCookie = "";
|
|
|
|
|
-
|
|
|
|
|
- // 特殊账号列表
|
|
|
|
|
- private final List<String> specialUsers = Arrays.asList(
|
|
|
|
|
- "EA27000180", "EA27000401", "EA27000098", "EA27000076",
|
|
|
|
|
- "EA27000385", "EA27000336", "EA27000393", "EA27000182",
|
|
|
|
|
- "EA27000381", "EA27000394", "XN9279003"
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ private final HuaTaiCrawlerProperties crawlerProp;
|
|
|
|
|
+ private final ObjectMapper objectMapper;
|
|
|
|
|
+
|
|
|
|
|
+ // ====================== 全局常量统一管理 ======================
|
|
|
|
|
+ private static final String BASE_DOMAIN = "https://cspxp.pc.ehuatai.com/htcsp";
|
|
|
|
|
+ private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/125.0.0.0 Safari/537.36";
|
|
|
|
|
+ private static final String COOKIE_JSESSIONID = "JSESSIONID";
|
|
|
|
|
+ private static final String COOKIE_BIGIP = "BIGipServerypKFOfHGLAALYYraCSdVMw";
|
|
|
|
|
+
|
|
|
|
|
+ // 接口地址常量
|
|
|
|
|
+ private static final String URL_INDEX = BASE_DOMAIN + "/";
|
|
|
|
|
+ private static final String URL_CHECK_WEB = BASE_DOMAIN + "/ShakeHandsAction.do?cmd=checkWeb";
|
|
|
|
|
+ private static final String URL_GET_BRANCH = BASE_DOMAIN + "/ShakeHandsAction.do?cmd=getBranch";
|
|
|
|
|
+ private static final String URL_JUDGE_FORWARD = BASE_DOMAIN + "/ShakeHandsAction.do?cmd=judgeCanForwardNewPage";
|
|
|
|
|
+ private static final String URL_GET_MAC = BASE_DOMAIN + "/ShakeHandsAction.do?cmd=getMac";
|
|
|
|
|
+ private static final String URL_VERIFY_FLAG = BASE_DOMAIN + "/ShakeHandsAction.do?cmd=verificationFlag";
|
|
|
|
|
+ private static final String URL_GET_PROMPT = BASE_DOMAIN + "/ShakeHandsAction.do?cmd=getPrompt";
|
|
|
|
|
+ private static final String URL_CHECK_USER = BASE_DOMAIN + "/ShakeHandsAction.do?cmd=checkUser";
|
|
|
|
|
+ private static final String URL_LOGIN_WELCOME = BASE_DOMAIN + "/ShakeHandsAction.do?cmd=loginWelcom";
|
|
|
|
|
+ private static final String URL_MENU_CONTROL = BASE_DOMAIN + "/ShakeHandsAction.do?cmd=menuControl&ip=172.16.100.27&host=9000&menuCode=car_001&messageClickType=&mesFlag=";
|
|
|
|
|
+ private static final String URL_INIT_SALE_USER = BASE_DOMAIN + "/SaleInfoAction.do?cmd=initSaledUser";
|
|
|
|
|
+ private static final String URL_INIT_SALE_SYS = BASE_DOMAIN + "/SaleInfoAction.do?cmd=initSalesys";
|
|
|
|
|
+ private static final String URL_INIT_SELECT_SALE_ALL = BASE_DOMAIN + "/SaleInfoAction.do?cmd=initSelectSalesysall";
|
|
|
|
|
+ private static final String URL_CONFIRM_USER = BASE_DOMAIN + "/ShakeHandsAction.do?cmd=confirmUserVoByInitBySale";
|
|
|
|
|
+
|
|
|
|
|
+ // 正则常量
|
|
|
|
|
+ private static final Pattern PAT_COOKIE = Pattern.compile("([^;]+)=([^;]+)");
|
|
|
|
|
+ private static final Pattern PAT_COMPANY_JSON = Pattern.compile("var comPanyJson= (.*?);");
|
|
|
|
|
+
|
|
|
|
|
+ // ====================== 线程上下文封装(替代零散ThreadLocal变量) ======================
|
|
|
|
|
+ private static class CrawlContext {
|
|
|
|
|
+ // Cookie
|
|
|
|
|
+ String jsessionId = "";
|
|
|
|
|
+ String bigIpCookie = "";
|
|
|
|
|
+ // 归属信息
|
|
|
|
|
+ String ywlyName;
|
|
|
|
|
+ String xstxCode;
|
|
|
|
|
+ String dlrCode;
|
|
|
|
|
+ String dlxyCode;
|
|
|
|
|
+ Map<String, Object> gsInfo = new HashMap<>();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- private String quotationNo = "";
|
|
|
|
|
|
|
+ // 单一线程上下文容器
|
|
|
|
|
+ private final ThreadLocal<CrawlContext> threadCtx = ThreadLocal.withInitial(CrawlContext::new);
|
|
|
|
|
|
|
|
|
|
+ // ====================== 对外主入口 ======================
|
|
|
public Map<String, Object> mainFlow(String username, String pwd, String comCode,
|
|
public Map<String, Object> mainFlow(String username, String pwd, String comCode,
|
|
|
String useridName, String dlrCode, String dlxyCode, int maxQuoteNum) {
|
|
String useridName, String dlrCode, String dlxyCode, int maxQuoteNum) {
|
|
|
-
|
|
|
|
|
- RestTemplate restTemplate = getRestTemplate();
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ CrawlContext ctx = threadCtx.get();
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
try {
|
|
try {
|
|
|
- // 初始化车辆信息(示例数据)
|
|
|
|
|
- initCarInfo();
|
|
|
|
|
-
|
|
|
|
|
- // 登录
|
|
|
|
|
- Map<String, Object> loginResult = login(username, pwd, comCode);
|
|
|
|
|
- if (loginResult.get("code") != null && (int) loginResult.get("code") != 200) {
|
|
|
|
|
- System.out.println("华泰[" + username + "] 登录失败");
|
|
|
|
|
- Map<String, Object> result1 = new HashMap<>();
|
|
|
|
|
- result1.put("code", 400);
|
|
|
|
|
- result1.put("message", "用户名、密码错误");
|
|
|
|
|
- Map<String, Object> other = new HashMap<>();
|
|
|
|
|
- other.put("maxQuoteNum", maxQuoteNum);
|
|
|
|
|
- result1.put("other", other);
|
|
|
|
|
- return result1;
|
|
|
|
|
|
|
+ // 登录流程
|
|
|
|
|
+ Map<String, Object> loginResp = doLoginFlow(ctx, username, pwd, comCode);
|
|
|
|
|
+ if (!"200".equals(String.valueOf(loginResp.get("code")))) {
|
|
|
|
|
+ log.error("华泰账号[{}]登录失败:{}", username, loginResp.get("message"));
|
|
|
|
|
+ result.put("code", 400);
|
|
|
|
|
+ result.put("message", loginResp.get("message"));
|
|
|
|
|
+ result.put("other", Map.of("maxQuoteNum", maxQuoteNum));
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- Map<String, Object> cookies = (Map<String, Object>) loginResult.get("cookies");
|
|
|
|
|
- this.jsessionId = (String) cookies.get("JSESSIONID");
|
|
|
|
|
- this.bigIpCookie = (String) cookies.get("BIGipServerypKFOfHGLAALYYraCSdVMw");
|
|
|
|
|
-
|
|
|
|
|
- // 如果不是特殊账号,获取归属信息
|
|
|
|
|
- //if (!specialUsers.contains(username)) {
|
|
|
|
|
- // try {
|
|
|
|
|
- // getGuishu(comCode, useridName, dlrCode, dlxyCode);
|
|
|
|
|
- // } catch (Exception e) {
|
|
|
|
|
- // e.printStackTrace();
|
|
|
|
|
- // }
|
|
|
|
|
- //}
|
|
|
|
|
- getGuishu(comCode, useridName, dlrCode, dlxyCode);
|
|
|
|
|
-
|
|
|
|
|
- Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
|
- resultMap.put("code", 200);
|
|
|
|
|
- resultMap.put("message", "success");
|
|
|
|
|
- resultMap.put("cookies", "JSESSIONID="+this.jsessionId+"; BIGipServerypKFOfHGLAALYYraCSdVMw="+this.bigIpCookie+";");
|
|
|
|
|
- resultMap.put("comCode", loginResult.get("comcode"));
|
|
|
|
|
- resultMap.put("gsInfo", gsInfo);
|
|
|
|
|
- return resultMap;
|
|
|
|
|
|
|
+ // 缓存当前线程Cookie
|
|
|
|
|
+ ctx.jsessionId = (String) loginResp.get("JSESSIONID");
|
|
|
|
|
+ ctx.bigIpCookie = (String) loginResp.get(COOKIE_BIGIP);
|
|
|
|
|
+ // 拉取归属树gsInfo
|
|
|
|
|
+ fetchGsInfo(ctx, comCode, useridName, dlrCode, dlxyCode);
|
|
|
|
|
+ // 组装返回
|
|
|
|
|
+ String cookieStr = String.format("%s=%s; %s=%s",
|
|
|
|
|
+ COOKIE_JSESSIONID, ctx.jsessionId,
|
|
|
|
|
+ COOKIE_BIGIP, ctx.bigIpCookie);
|
|
|
|
|
+ result.put("code", 200);
|
|
|
|
|
+ result.put("message", "success");
|
|
|
|
|
+ result.put("cookies", cookieStr);
|
|
|
|
|
+ result.put("comCode", loginResp.get("comcode"));
|
|
|
|
|
+ result.put("gsInfo", ctx.gsInfo);
|
|
|
|
|
+ log.info("华泰账号[{}]登录前置流程完成", username);
|
|
|
|
|
+ return result;
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- Map<String, Object> result2 = new HashMap<>();
|
|
|
|
|
- result2.put("code", 500);
|
|
|
|
|
- result2.put("message", e.getMessage());
|
|
|
|
|
- return result2;
|
|
|
|
|
|
|
+ log.error("华泰爬虫mainFlow异常", e);
|
|
|
|
|
+ result.put("code", 500);
|
|
|
|
|
+ result.put("message", e.getMessage());
|
|
|
|
|
+ return result;
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ // 必须销毁,线程池防内存泄漏
|
|
|
|
|
+ threadCtx.remove();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // ====================== 公共工具方法 ======================
|
|
|
|
|
+ /** 统一构建带代理、忽略SSL的RestTemplate */
|
|
|
@NotNull
|
|
@NotNull
|
|
|
- public static RestTemplate getRestTemplate() {
|
|
|
|
|
|
|
+ public RestTemplate getRestTemplate() {
|
|
|
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory() {
|
|
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory() {
|
|
|
@Override
|
|
@Override
|
|
|
- protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws java.io.IOException {
|
|
|
|
|
- if (connection instanceof HttpsURLConnection) {
|
|
|
|
|
|
|
+ protected void prepareConnection(HttpURLConnection conn, String method) throws IOException {
|
|
|
|
|
+ if (conn instanceof HttpsURLConnection httpsConn) {
|
|
|
try {
|
|
try {
|
|
|
- TrustManager[] trustAllCerts = new TrustManager[]{
|
|
|
|
|
- new X509TrustManager() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public X509Certificate[] getAcceptedIssuers() {
|
|
|
|
|
- return new X509Certificate[0];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void checkClientTrusted(X509Certificate[] certs, String authType) {
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void checkServerTrusted(X509Certificate[] certs, String authType) {
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
- SSLContext sslContext = SSLContext.getInstance("TLS");
|
|
|
|
|
- sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
|
|
|
|
|
- ((HttpsURLConnection) connection).setSSLSocketFactory(sslContext.getSocketFactory());
|
|
|
|
|
- ((HttpsURLConnection) connection).setHostnameVerifier(new HostnameVerifier() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public boolean verify(String hostname, SSLSession session) {
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
|
|
+ trustAllSsl(httpsConn);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- super.prepareConnection(connection, httpMethod);
|
|
|
|
|
|
|
+ super.prepareConnection(conn, method);
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
-
|
|
|
|
|
- Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("172.24.144.226", 2025));//39.98.41.104
|
|
|
|
|
|
|
+ Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(crawlerProp.getProxyHostName(), crawlerProp.getProxyPort()));
|
|
|
factory.setProxy(proxy);
|
|
factory.setProxy(proxy);
|
|
|
-
|
|
|
|
|
- RestTemplate restTemplate = new RestTemplate(factory);
|
|
|
|
|
- return restTemplate;
|
|
|
|
|
|
|
+ return new RestTemplate(factory);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void initCarInfo() {
|
|
|
|
|
- Map<String, Object> dddd = new HashMap<>();
|
|
|
|
|
- dddd.put("frameNo", "LM8F7J3B0SC078844");
|
|
|
|
|
- dddd.put("transferFlagBi", false);
|
|
|
|
|
- dddd.put("transferFlag", false);
|
|
|
|
|
- dddd.put("cartype", "K31");
|
|
|
|
|
- dddd.put("licenseNo", "晋AFS6726");
|
|
|
|
|
- dddd.put("newEnergy", true);
|
|
|
|
|
- dddd.put("modelcname", "赛力斯SKE6520SSHEVA6S插电式增程混合动力多用途乘用车");
|
|
|
|
|
- dddd.put("purchasePrice", "469800");
|
|
|
|
|
- dddd.put("vinNo", "LM8F7J3B0SC078844");
|
|
|
|
|
- dddd.put("noLicenseFlag", false);
|
|
|
|
|
- dddd.put("enginedesc", "1.496");
|
|
|
|
|
- dddd.put("powerScale", "118");
|
|
|
|
|
- dddd.put("modelCode", "AIAACD0022");
|
|
|
|
|
- dddd.put("completeKerbMass", "2690");
|
|
|
|
|
- dddd.put("familyName", "问界M9");
|
|
|
|
|
- dddd.put("importFlag", "越野车类");
|
|
|
|
|
- dddd.put("loanStatus", false);
|
|
|
|
|
- dddd.put("property", "1");
|
|
|
|
|
- dddd.put("caryear", "202503");
|
|
|
|
|
- dddd.put("issueDate", "2025-06-19");
|
|
|
|
|
- dddd.put("registerDate", "2025-06-19");
|
|
|
|
|
- dddd.put("engineNo", "25634769");
|
|
|
|
|
- dddd.put("brandName", "AITO问界");
|
|
|
|
|
- dddd.put("usedCar", false);
|
|
|
|
|
- dddd.put("licenseTypeCode", "02");
|
|
|
|
|
- dddd.put("vehicleUse", "05");
|
|
|
|
|
- dddd.put("carnature", "02");
|
|
|
|
|
- dddd.put("seatCount", "5");
|
|
|
|
|
- dddd.put("energyType", "1");
|
|
|
|
|
- dddd.put("cimodelclass", "A0");
|
|
|
|
|
- dddd.put("outOfInsurance", false);
|
|
|
|
|
- dddd.put("vehicleweight", "3165");
|
|
|
|
|
-
|
|
|
|
|
- this.licenseNo = (String) dddd.get("licenseNo");
|
|
|
|
|
- this.vin = (String) dddd.get("vinNo");
|
|
|
|
|
- this.registerDate = (String) dddd.get("registerDate");
|
|
|
|
|
- this.energyType = (String) dddd.get("energyType");
|
|
|
|
|
- this.modelCName = (String) dddd.get("modelcname");
|
|
|
|
|
- this.engineNo = (String) dddd.get("engineNo");
|
|
|
|
|
- this.seat = (String) dddd.get("seatCount");
|
|
|
|
|
- this.purchasePrice = (String) dddd.get("purchasePrice");
|
|
|
|
|
- this.vehicleUse = (String) dddd.get("vehicleUse");
|
|
|
|
|
- this.limitLoad = (String) dddd.get("limitLoad");
|
|
|
|
|
- this.cartype = (String) dddd.get("cartype");
|
|
|
|
|
- this.completeKerbMass = (String) dddd.get("completeKerbMass");
|
|
|
|
|
- this.cimodelclass = (String) dddd.get("cimodelclass");
|
|
|
|
|
-
|
|
|
|
|
- if ("04".equals(this.vehicleUse)) {
|
|
|
|
|
- this.motorTypeCode = "H0";
|
|
|
|
|
- this.motorUsageTypeCode = "9D";
|
|
|
|
|
- } else if ("05".equals(this.vehicleUse)) {
|
|
|
|
|
- this.motorTypeCode = "A0";
|
|
|
|
|
- this.motorUsageTypeCode = "8A";
|
|
|
|
|
- } else if ("06".equals(this.vehicleUse)) {
|
|
|
|
|
- if ("A0".equals(this.cimodelclass)) {
|
|
|
|
|
- this.motorTypeCode = "A0";
|
|
|
|
|
- this.motorUsageTypeCode = "8C";
|
|
|
|
|
- } else if ("A1".equals(this.cimodelclass)) {
|
|
|
|
|
- this.motorTypeCode = "H0";
|
|
|
|
|
- this.motorUsageTypeCode = "8D";
|
|
|
|
|
- }
|
|
|
|
|
- } else if ("07".equals(this.vehicleUse)) {
|
|
|
|
|
- if ("A0".equals(this.cimodelclass)) {
|
|
|
|
|
- this.motorTypeCode = "A0";
|
|
|
|
|
- this.motorUsageTypeCode = "8B";
|
|
|
|
|
- } else if ("A1".equals(this.cimodelclass)) {
|
|
|
|
|
- this.motorTypeCode = "H0";
|
|
|
|
|
- this.motorUsageTypeCode = "8D";
|
|
|
|
|
- }
|
|
|
|
|
- } else if ("08".equals(this.vehicleUse)) {
|
|
|
|
|
- this.motorTypeCode = "H0";
|
|
|
|
|
- this.motorUsageTypeCode = "8D";
|
|
|
|
|
- }
|
|
|
|
|
- this.motortypecode = this.motorTypeCode;
|
|
|
|
|
|
|
+ /** 全局信任SSL工具,抽取公共 */
|
|
|
|
|
+ private void trustAllSsl(HttpsURLConnection conn) throws Exception {
|
|
|
|
|
+ TrustManager[] trustAll = new TrustManager[]{new X509TrustManager() {
|
|
|
|
|
+ @Override public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }
|
|
|
|
|
+ @Override public void checkClientTrusted(X509Certificate[] certs, String authType) {}
|
|
|
|
|
+ @Override public void checkServerTrusted(X509Certificate[] certs, String authType) {}
|
|
|
|
|
+ }};
|
|
|
|
|
+ SSLContext sslCtx = SSLContext.getInstance("TLS");
|
|
|
|
|
+ sslCtx.init(null, trustAll, new SecureRandom());
|
|
|
|
|
+ conn.setSSLSocketFactory(sslCtx.getSocketFactory());
|
|
|
|
|
+ conn.setHostnameVerifier((host, session) -> true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private HttpHeaders buildHeadersWithCookie() {
|
|
|
|
|
|
|
+ /** 通用构建基础请求头(无Cookie) */
|
|
|
|
|
+ private HttpHeaders buildBaseHeaders() {
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36");
|
|
|
|
|
- headers.set("Accept", "*/*");
|
|
|
|
|
|
|
+ headers.set("User-Agent", USER_AGENT);
|
|
|
headers.set("Accept-Language", "zh-CN,zh;q=0.9");
|
|
headers.set("Accept-Language", "zh-CN,zh;q=0.9");
|
|
|
headers.set("Connection", "keep-alive");
|
|
headers.set("Connection", "keep-alive");
|
|
|
- headers.set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
|
|
|
|
- headers.set("Origin", "https://cspxp.pc.ehuatai.com");
|
|
|
|
|
- headers.set("Referer", "https://cspxp.pc.ehuatai.com/htcsp/ShakeHandsAction.do?cmd=menuControl&ip=172.16.100.27&host=9000&menuCode=car_001&messageClickType=&mesFlag=");
|
|
|
|
|
|
|
+ headers.set("Cache-Control", "no-cache");
|
|
|
|
|
+ headers.set("Pragma", "no-cache");
|
|
|
|
|
+ return headers;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 表单JSON请求头(XHR) */
|
|
|
|
|
+ private HttpHeaders buildJsonHeaders(CrawlContext ctx) {
|
|
|
|
|
+ HttpHeaders headers = buildBaseHeaders();
|
|
|
|
|
+ headers.set("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
|
|
|
+ headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
|
|
|
|
+ headers.set("Origin", BASE_DOMAIN);
|
|
|
|
|
+ headers.set("Referer", BASE_DOMAIN + "/");
|
|
|
headers.set("X-Requested-With", "XMLHttpRequest");
|
|
headers.set("X-Requested-With", "XMLHttpRequest");
|
|
|
- String cookieStr = "JSESSIONID=" + jsessionId;
|
|
|
|
|
- if (!bigIpCookie.isEmpty()) {
|
|
|
|
|
- cookieStr += "; BIGipServerypKFOfHGLAALYYraCSdVMw=" + bigIpCookie;
|
|
|
|
|
- }
|
|
|
|
|
- headers.set("Cookie", cookieStr);
|
|
|
|
|
|
|
+ setCookieHeader(headers, ctx);
|
|
|
return headers;
|
|
return headers;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private HttpHeaders buildHtmlHeadersWithCookie() {
|
|
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
- headers.set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36");
|
|
|
|
|
- headers.set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
|
|
|
|
|
- headers.set("Accept-Language", "zh-CN,zh;q=0.9");
|
|
|
|
|
- headers.set("Cache-Control", "no-cache");
|
|
|
|
|
- headers.set("Connection", "keep-alive");
|
|
|
|
|
- headers.set("Pragma", "no-cache");
|
|
|
|
|
|
|
+ /** HTML页面请求头 */
|
|
|
|
|
+ private HttpHeaders buildHtmlHeaders(CrawlContext ctx) {
|
|
|
|
|
+ HttpHeaders headers = buildBaseHeaders();
|
|
|
|
|
+ headers.set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
|
|
|
headers.set("Upgrade-Insecure-Requests", "1");
|
|
headers.set("Upgrade-Insecure-Requests", "1");
|
|
|
- String cookieStr = "JSESSIONID=" + jsessionId;
|
|
|
|
|
- if (!bigIpCookie.isEmpty()) {
|
|
|
|
|
- cookieStr += "; BIGipServerypKFOfHGLAALYYraCSdVMw=" + bigIpCookie;
|
|
|
|
|
- }
|
|
|
|
|
- headers.set("Cookie", cookieStr);
|
|
|
|
|
|
|
+ setCookieHeader(headers, ctx);
|
|
|
return headers;
|
|
return headers;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void getGuishu(String comCode, String useridName, String dlrCode, String dlxyCode) throws Exception {
|
|
|
|
|
- System.out.println("开始获取归属树==================");
|
|
|
|
|
- RestTemplate restTemplate = getRestTemplate();
|
|
|
|
|
- HttpHeaders headers = buildHeadersWithCookie();
|
|
|
|
|
- MultiValueMap<String, String> data = new LinkedMultiValueMap<>();
|
|
|
|
|
- data.add("comcode", comCode);
|
|
|
|
|
- HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(data, headers);
|
|
|
|
|
- ResponseEntity<String> response = restTemplate.exchange(
|
|
|
|
|
- baseUrl + "/SaleInfoAction.do?cmd=initSaledUser", HttpMethod.POST, entity, String.class);
|
|
|
|
|
- System.out.println("归属树用户列表:initSaledUser:");
|
|
|
|
|
- String useridValue = "";
|
|
|
|
|
- String foundUseridName = "";
|
|
|
|
|
- List<Map<String, Object>> userList = objectMapper.readValue(response.getBody(), List.class);
|
|
|
|
|
- System.out.println("归属树用户列表:" + userList);
|
|
|
|
|
- for (Map<String, Object> item : userList) {
|
|
|
|
|
- if (useridName.equals(item.get("codecname"))) {
|
|
|
|
|
- foundUseridName = (String) item.get("codecname");
|
|
|
|
|
- useridValue = (String) item.get("codecode");
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ /** 统一填充Cookie到Header */
|
|
|
|
|
+ private void setCookieHeader(HttpHeaders headers, CrawlContext ctx) {
|
|
|
|
|
+ List<String> cookieList = new ArrayList<>();
|
|
|
|
|
+ if (StringUtils.hasText(ctx.jsessionId)) {
|
|
|
|
|
+ cookieList.add(COOKIE_JSESSIONID + "=" + ctx.jsessionId);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- headers = buildHeadersWithCookie();
|
|
|
|
|
- data = new LinkedMultiValueMap<>();
|
|
|
|
|
- data.add("comcode", comCode);
|
|
|
|
|
- entity = new HttpEntity<>(data, headers);
|
|
|
|
|
- ResponseEntity<String> respSalesys = restTemplate.exchange(
|
|
|
|
|
- baseUrl + "/SaleInfoAction.do?cmd=initSalesys", HttpMethod.POST, entity, String.class);
|
|
|
|
|
- Map<String, Object> salesysMap = objectMapper.readValue(respSalesys.getBody(), HashMap.class);
|
|
|
|
|
- System.out.println("归属树用户列表:salesysMap" + salesysMap);
|
|
|
|
|
- String channelOrign = (String) salesysMap.get("codecode");
|
|
|
|
|
- String newChannelOrign = (String) salesysMap.get("newcodecode");
|
|
|
|
|
-
|
|
|
|
|
- headers = buildHtmlHeadersWithCookie();
|
|
|
|
|
- HttpEntity<String> getEntity = new HttpEntity<>(headers);
|
|
|
|
|
- ResponseEntity<String> respMenu = restTemplate.exchange(
|
|
|
|
|
- baseUrl + "/ShakeHandsAction.do?cmd=menuControl&ip=172.16.100.27&host=9000&menuCode=car_001&messageClickType=&mesFlag=",
|
|
|
|
|
- HttpMethod.GET, getEntity, String.class);
|
|
|
|
|
- System.out.println("归属树用户列表:menuControl:");
|
|
|
|
|
- String comcodeGbdistrictcode = "";
|
|
|
|
|
- String comcodeName = "";
|
|
|
|
|
- Pattern pattern = Pattern.compile("var comPanyJson= (.*?);");
|
|
|
|
|
- Matcher matcher = pattern.matcher(respMenu.getBody());
|
|
|
|
|
- if (matcher.find()) {
|
|
|
|
|
- String jsonStr = matcher.group(1);
|
|
|
|
|
- List<Map<String, Object>> comPanyJsonList = objectMapper.readValue(jsonStr, List.class);
|
|
|
|
|
- for (Map<String, Object> zzz : comPanyJsonList) {
|
|
|
|
|
- if (comCode.equals(zzz.get("codecode"))) {
|
|
|
|
|
- comcodeGbdistrictcode = (String) zzz.get("codetype");
|
|
|
|
|
- comcodeName = (String) zzz.get("codecname");
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (StringUtils.hasText(ctx.bigIpCookie)) {
|
|
|
|
|
+ cookieList.add(COOKIE_BIGIP + "=" + ctx.bigIpCookie);
|
|
|
}
|
|
}
|
|
|
|
|
+ headers.set("Cookie", String.join("; ", cookieList));
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- headers = buildHeadersWithCookie();
|
|
|
|
|
- data = new LinkedMultiValueMap<>();
|
|
|
|
|
- data.add("comcode", comCode);
|
|
|
|
|
- data.add("codeCode", channelOrign);
|
|
|
|
|
- entity = new HttpEntity<>(data, headers);
|
|
|
|
|
- restTemplate.exchange(baseUrl + "/SaleInfoAction.do?cmd=initSelectSalesysall", HttpMethod.POST, entity, String.class);
|
|
|
|
|
- System.out.println("归属树用户列表:initSelectSalesysall");
|
|
|
|
|
- headers = buildHtmlHeadersWithCookie();
|
|
|
|
|
- getEntity = new HttpEntity<>(headers);
|
|
|
|
|
- restTemplate.exchange(
|
|
|
|
|
- baseUrl + "/ShakeHandsAction.do?cmd=menuControl&ip=172.16.100.27&host=9000&menuCode=car_001&messageClickType=&mesFlag=",
|
|
|
|
|
- HttpMethod.GET, getEntity, String.class);
|
|
|
|
|
-
|
|
|
|
|
- this.ywlyName = "代理业务";
|
|
|
|
|
- this.xstxCode = "0401";
|
|
|
|
|
- List<Map<String, Object>> codelist = new ArrayList<>();
|
|
|
|
|
- codelist.add(createCodeItem("直接业务", "0"));
|
|
|
|
|
- codelist.add(createCodeItem("代理业务", "1"));
|
|
|
|
|
- codelist.add(createCodeItem("经纪业务", "4"));
|
|
|
|
|
- codelist.add(createCodeItem("电销/网销", "6"));
|
|
|
|
|
- for (Map<String, Object> zzz : codelist) {
|
|
|
|
|
- if (this.ywlyName.equals(zzz.get("codecname"))) {
|
|
|
|
|
- this.ywlyName = (String) zzz.get("codecode");
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ /** 从Set-Cookie响应头解析并存入上下文 */
|
|
|
|
|
+ private void parseSetCookie(ResponseEntity<?> resp, CrawlContext ctx) {
|
|
|
|
|
+ List<String> setCookieList = resp.getHeaders().get("Set-Cookie");
|
|
|
|
|
+ if (CollectionUtils.isEmpty(setCookieList)) return;
|
|
|
|
|
+ for(String cookieRaw : setCookieList) {
|
|
|
|
|
+ Matcher m = PAT_COOKIE.matcher(cookieRaw);
|
|
|
|
|
+ if (!m.find()) continue;
|
|
|
|
|
+ String key = m.group(1);
|
|
|
|
|
+ String val = m.group(2);
|
|
|
|
|
+ switch (key) {
|
|
|
|
|
+ case COOKIE_JSESSIONID: ctx.jsessionId = val; break;
|
|
|
|
|
+ case COOKIE_BIGIP: ctx.bigIpCookie = val; break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- this.dlrCode = dlrCode;
|
|
|
|
|
- this.dlxyCode = dlxyCode;
|
|
|
|
|
-
|
|
|
|
|
- headers = new HttpHeaders();
|
|
|
|
|
- headers.set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
|
|
|
|
|
- headers.set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
|
|
|
|
|
- headers.set("Cache-Control", "no-cache");
|
|
|
|
|
- headers.set("Connection", "keep-alive");
|
|
|
|
|
- headers.set("Content-Type", "application/x-www-form-urlencoded");
|
|
|
|
|
- headers.set("Origin", "https://cspxp.pc.ehuatai.com");
|
|
|
|
|
- headers.set("Pragma", "no-cache");
|
|
|
|
|
- headers.set("Referer", "https://cspxp.pc.ehuatai.com/htcsp/ShakeHandsAction.do?cmd=menuControl&ip=172.16.100.27&host=9000&menuCode=car_001&messageClickType=&mesFlag=");
|
|
|
|
|
- headers.set("Upgrade-Insecure-Requests", "1");
|
|
|
|
|
- headers.set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36");
|
|
|
|
|
- String cookieStr = "JSESSIONID=" + jsessionId;
|
|
|
|
|
- if (!bigIpCookie.isEmpty()) {
|
|
|
|
|
- cookieStr += "; BIGipServerypKFOfHGLAALYYraCSdVMw=" + bigIpCookie;
|
|
|
|
|
- }
|
|
|
|
|
- headers.set("Cookie", cookieStr);
|
|
|
|
|
-
|
|
|
|
|
- data = new LinkedMultiValueMap<>();
|
|
|
|
|
- data.add("isTeamCarFlag", "");
|
|
|
|
|
- data.add("teamcarmodelcode", "");
|
|
|
|
|
- data.add("teamcarmodelname", "");
|
|
|
|
|
- data.add("salemdea", "");
|
|
|
|
|
- data.add("PRPDCODJson", "");
|
|
|
|
|
- data.add("state", "");
|
|
|
|
|
- data.add("comCodeInAgentsFlag", "0");
|
|
|
|
|
- data.add("wangdianNameFlag", "0");
|
|
|
|
|
- data.add("wangdianNameHid", "0");
|
|
|
|
|
- data.add("licenseNo", "");
|
|
|
|
|
- data.add("policyBI", "");
|
|
|
|
|
- data.add("policyCI", "");
|
|
|
|
|
- data.add("policyStatusBI", "");
|
|
|
|
|
- data.add("policyStatusCI", "");
|
|
|
|
|
- data.add("showEmploy", "");
|
|
|
|
|
- data.add("showEmployControl", "");
|
|
|
|
|
- data.add("businessature", "");
|
|
|
|
|
- data.add("comcode", comCode);
|
|
|
|
|
- data.add("comcode_name", comcodeName);
|
|
|
|
|
- data.add("comcode_gbcode", comcodeGbdistrictcode);
|
|
|
|
|
- data.add("userid", useridValue);
|
|
|
|
|
- data.add("userid_name", foundUseridName);
|
|
|
|
|
- data.add("businessNature", this.ywlyName);
|
|
|
|
|
- data.add("selectsalesys", "");
|
|
|
|
|
- data.add("salesys", this.xstxCode);
|
|
|
|
|
- data.add("channel", "04");
|
|
|
|
|
- data.add("channel_orign", channelOrign);
|
|
|
|
|
- data.add("newChannel", "saleSysDl");
|
|
|
|
|
- data.add("newChannel_orign", newChannelOrign);
|
|
|
|
|
- data.add("agentno_dl", this.dlrCode);
|
|
|
|
|
- data.add("agreementno_dl", this.dlxyCode);
|
|
|
|
|
- data.add("agentno_fdl", "");
|
|
|
|
|
- data.add("agreementno_fdl", "");
|
|
|
|
|
- data.add("agentno_jj", "");
|
|
|
|
|
- data.add("agreementno_jj", "");
|
|
|
|
|
- data.add("teamcode_value", "");
|
|
|
|
|
- data.add("teamcode_name", "");
|
|
|
|
|
- data.add("systemfor", "");
|
|
|
|
|
- data.add("usercodelifedot_text", "");
|
|
|
|
|
- data.add("usercodelife_value", "");
|
|
|
|
|
- data.add("usercodelife_name", "");
|
|
|
|
|
- data.add("usercodelife_text", "");
|
|
|
|
|
- data.add("phone_value", "");
|
|
|
|
|
- data.add("phone_name", "");
|
|
|
|
|
- data.add("carType", "baojia");
|
|
|
|
|
- data.add("quotationNo", "");
|
|
|
|
|
-
|
|
|
|
|
- entity = new HttpEntity<>(data, headers);
|
|
|
|
|
- restTemplate.exchange(baseUrl + "/ShakeHandsAction.do?cmd=confirmUserVoByInitBySale", HttpMethod.POST, entity, String.class);
|
|
|
|
|
- System.out.println("归属树用户列表:confirmUserVoByInitBySale");
|
|
|
|
|
- gsInfo.put("userid_name", foundUseridName);
|
|
|
|
|
- gsInfo.put("userid_value", useridValue);
|
|
|
|
|
- gsInfo.put("comcode_gbdistrictcode", comcodeGbdistrictcode);
|
|
|
|
|
- gsInfo.put("comcode_name", comcodeName);
|
|
|
|
|
- gsInfo.put("businessnature_value", this.ywlyName);
|
|
|
|
|
- gsInfo.put("salesys_value", this.xstxCode);
|
|
|
|
|
- gsInfo.put("channel_orign", channelOrign);
|
|
|
|
|
- gsInfo.put("newChannel_orign", newChannelOrign);
|
|
|
|
|
- System.out.println("归属树用户列表结束==============");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private Map<String, Object> createCodeItem(String name, String code) {
|
|
|
|
|
- Map<String, Object> item = new HashMap<>();
|
|
|
|
|
- item.put("codecname", name);
|
|
|
|
|
- item.put("codecode", code);
|
|
|
|
|
- return item;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private Map<String, Object> login(String uname, String pwd, String comCode) {
|
|
|
|
|
|
|
+ /** AES+RSA统一解密 */
|
|
|
|
|
+ private Map<String, Object> decryptResp(String body) {
|
|
|
try {
|
|
try {
|
|
|
- getCk();
|
|
|
|
|
-
|
|
|
|
|
- String comcode = getComcode(uname, comCode);
|
|
|
|
|
- if (comcode == null) {
|
|
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
|
|
- result.put("code", 400);
|
|
|
|
|
- result.put("message", "获取机构失败");
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return doLogin(uname, pwd, comcode);
|
|
|
|
|
|
|
+ Map<String, Object> map = objectMapper.readValue(body, Map.class);
|
|
|
|
|
+ String accessToken = (String) map.get("accessToken");
|
|
|
|
|
+ String data = (String) map.get("data");
|
|
|
|
|
+ String aesKey = HuaTaiCryptUtil.RSADecrypt(accessToken);
|
|
|
|
|
+ String realData = HuaTaiCryptUtil.AESDecrypt(data, aesKey);
|
|
|
|
|
+ return objectMapper.readValue(realData, Map.class);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
|
|
- result.put("code", 500);
|
|
|
|
|
- result.put("message", e.getMessage());
|
|
|
|
|
- return result;
|
|
|
|
|
|
|
+ log.warn("解密响应失败", e);
|
|
|
|
|
+ return new HashMap<>();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private HttpHeaders buildCommonHeaders() {
|
|
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
- headers.set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36");
|
|
|
|
|
- headers.set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
|
|
|
|
|
- headers.set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
|
|
|
|
|
- headers.set("Cache-Control", "no-cache");
|
|
|
|
|
- headers.set("Pragma", "no-cache");
|
|
|
|
|
- headers.set("Connection", "keep-alive");
|
|
|
|
|
- headers.set("Upgrade-Insecure-Requests", "1");
|
|
|
|
|
- return headers;
|
|
|
|
|
|
|
+ /** 构造下拉编码项 */
|
|
|
|
|
+ private Map<String, Object> buildCodeItem(String name, String code) {
|
|
|
|
|
+ return Map.of("codecname", name, "codecode", code);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private HttpHeaders buildJsonHeaders() {
|
|
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
- headers.set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36");
|
|
|
|
|
- headers.set("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
|
|
|
- headers.set("Accept-Language", "zh-CN,zh;q=0.9");
|
|
|
|
|
- headers.set("Cache-Control", "no-cache");
|
|
|
|
|
- headers.set("Pragma", "no-cache");
|
|
|
|
|
- headers.set("Connection", "keep-alive");
|
|
|
|
|
- headers.set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
|
|
|
|
- headers.set("Origin", "https://cspxp.pc.ehuatai.com");
|
|
|
|
|
- headers.set("Referer", "https://cspxp.pc.ehuatai.com/htcsp/");
|
|
|
|
|
- headers.set("X-Requested-With", "XMLHttpRequest");
|
|
|
|
|
- headers.set("Sec-Fetch-Dest", "empty");
|
|
|
|
|
- headers.set("Sec-Fetch-Mode", "cors");
|
|
|
|
|
- headers.set("Sec-Fetch-Site", "same-origin");
|
|
|
|
|
- headers.set("sec-ch-ua", "\"Google Chrome\";v=\"143\", \"Chromium\";v=\"143\", \"Not A(Brand)\";v=\"24\"");
|
|
|
|
|
- headers.set("sec-ch-ua-mobile", "?0");
|
|
|
|
|
- headers.set("sec-ch-ua-platform", "\"Windows\"");
|
|
|
|
|
- return headers;
|
|
|
|
|
|
|
+ // ====================== 内部流程拆分 ======================
|
|
|
|
|
+
|
|
|
|
|
+ /** 完整登录前置流程(获取初始Cookie+机构) */
|
|
|
|
|
+ private Map<String, Object> doLoginFlow(CrawlContext ctx, String username, String pwd, String inputComCode) {
|
|
|
|
|
+ RestTemplate rt = getRestTemplate();
|
|
|
|
|
+ // 1. 初始化页面Cookie
|
|
|
|
|
+ initBaseCookie(ctx, rt);
|
|
|
|
|
+ // 2. 获取机构编码
|
|
|
|
|
+ String fullComCode = fetchComCode(ctx, rt, username, inputComCode);
|
|
|
|
|
+ if (StringUtils.isBlank(fullComCode)) {
|
|
|
|
|
+ return Map.of("code", "400", "message", "获取机构信息失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 3. 提交账号密码正式登录
|
|
|
|
|
+ return submitLogin(ctx, rt, username, pwd, fullComCode);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void getCk() {
|
|
|
|
|
- System.out.println("获取Cookie开始==========");
|
|
|
|
|
- RestTemplate restTemplate = getRestTemplate();
|
|
|
|
|
- HttpHeaders headers = buildCommonHeaders();
|
|
|
|
|
- HttpEntity<String> entity = new HttpEntity<>(headers);
|
|
|
|
|
- ResponseEntity<String> response = restTemplate.exchange(
|
|
|
|
|
- baseUrl + "/", HttpMethod.GET, entity, String.class);
|
|
|
|
|
- extractCookies(response);
|
|
|
|
|
-
|
|
|
|
|
- headers = buildCommonHeaders();
|
|
|
|
|
- headers.set("Content-Type", "application/x-www-form-urlencoded");
|
|
|
|
|
- MultiValueMap<String, String> data = new LinkedMultiValueMap<>();
|
|
|
|
|
- data.add("ip", "cspxp.pc.ehuatai.com");
|
|
|
|
|
- HttpEntity<MultiValueMap<String, String>> postEntity = new HttpEntity<>(data, headers);
|
|
|
|
|
- ResponseEntity<String> postResp = restTemplate.exchange(
|
|
|
|
|
- baseUrl + "/ShakeHandsAction.do?cmd=checkWeb", HttpMethod.POST, postEntity, String.class);
|
|
|
|
|
- extractCookies(postResp);
|
|
|
|
|
- System.out.println("获取Cookie结束==========");
|
|
|
|
|
|
|
+ /** 访问首页、checkWeb 预拉取基础Cookie */
|
|
|
|
|
+ private void initBaseCookie(CrawlContext ctx, RestTemplate rt) {
|
|
|
|
|
+ log.info("开始拉取基础页面Cookie");
|
|
|
|
|
+ HttpHeaders baseHtml = buildHtmlHeaders(ctx);
|
|
|
|
|
+ // 访问首页
|
|
|
|
|
+ ResponseEntity<String> indexResp = rt.getForEntity(URL_INDEX, String.class, new HttpEntity<>(baseHtml));
|
|
|
|
|
+ parseSetCookie(indexResp, ctx);
|
|
|
|
|
+ // checkWeb提交
|
|
|
|
|
+ MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
|
|
|
|
|
+ param.add("ip", "cspxp.pc.ehuatai.com");
|
|
|
|
|
+ HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(param, baseHtml);
|
|
|
|
|
+ ResponseEntity<String> webResp = rt.postForEntity(URL_CHECK_WEB, entity, String.class);
|
|
|
|
|
+ parseSetCookie(webResp, ctx);
|
|
|
|
|
+ log.info("基础Cookie获取完成");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private String getComcode(String uname, String comCode) {
|
|
|
|
|
- System.out.println("获取机构开始==========");
|
|
|
|
|
- RestTemplate restTemplate = getRestTemplate();
|
|
|
|
|
- HttpHeaders headers = buildJsonHeaders();
|
|
|
|
|
- MultiValueMap<String, String> data = new LinkedMultiValueMap<>();
|
|
|
|
|
- data.add("username", uname);
|
|
|
|
|
- HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(data, headers);
|
|
|
|
|
- ResponseEntity<String> response = restTemplate.exchange(
|
|
|
|
|
- baseUrl + "/ShakeHandsAction.do?cmd=getBranch", HttpMethod.POST, entity, String.class);
|
|
|
|
|
- extractCookies(response);
|
|
|
|
|
- Map<String, Object> decrypted = htDecrypt(response.getBody());
|
|
|
|
|
- List<Map<String, Object>> comCodeList = (List<Map<String, Object>>) decrypted.get("comCodeList");
|
|
|
|
|
-
|
|
|
|
|
- String comcode = null;
|
|
|
|
|
- if (comCodeList != null) {
|
|
|
|
|
- for (Map<String, Object> item : comCodeList) {
|
|
|
|
|
- if (comCode.equals(item.get("comcode"))) {
|
|
|
|
|
- comcode = item.get("comcode") + "-" + item.get("comcname");
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (comcode == null && !comCodeList.isEmpty()) {
|
|
|
|
|
- comcode = comCodeList.get(0).get("comcode") + "-" + comCodeList.get(0).get("comcname");
|
|
|
|
|
|
|
+ /** 获取机构编码comcode */
|
|
|
|
|
+ private String fetchComCode(CrawlContext ctx, RestTemplate rt, String username, String inputComCode) {
|
|
|
|
|
+ log.info("开始拉取机构信息");
|
|
|
|
|
+ HttpHeaders jsonHeader = buildJsonHeaders(ctx);
|
|
|
|
|
+ MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
|
|
|
|
|
+ param.add("username", username);
|
|
|
|
|
+ ResponseEntity<String> branchResp = rt.postForEntity(URL_GET_BRANCH, new HttpEntity<>(param, jsonHeader), String.class);
|
|
|
|
|
+ parseSetCookie(branchResp, ctx);
|
|
|
|
|
+ Map<String, Object> decryptData = decryptResp(branchResp.getBody());
|
|
|
|
|
+ List<Map<String, Object>> comList = (List<Map<String, Object>>) decryptData.get("comCodeList");
|
|
|
|
|
+ if (CollectionUtils.isEmpty(comList)) return null;
|
|
|
|
|
+ String matchCode = null;
|
|
|
|
|
+ for (Map<String, Object> item : comList) {
|
|
|
|
|
+ String code = (String) item.get("comcode");
|
|
|
|
|
+ if (inputComCode.equals(code)) {
|
|
|
|
|
+ matchCode = code + "-" + item.get("comcname");
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- headers = buildJsonHeaders();
|
|
|
|
|
- HttpEntity<String> emptyEntity = new HttpEntity<>(headers);
|
|
|
|
|
- restTemplate.exchange(baseUrl + "/ShakeHandsAction.do?cmd=judgeCanForwardNewPage",
|
|
|
|
|
- HttpMethod.POST, emptyEntity, String.class);
|
|
|
|
|
-
|
|
|
|
|
- headers = buildJsonHeaders();
|
|
|
|
|
- data = new LinkedMultiValueMap<>();
|
|
|
|
|
- data.add("username", uname);
|
|
|
|
|
- entity = new HttpEntity<>(data, headers);
|
|
|
|
|
- restTemplate.exchange(baseUrl + "/ShakeHandsAction.do?cmd=getMac", HttpMethod.POST, entity, String.class);
|
|
|
|
|
-
|
|
|
|
|
- headers = buildJsonHeaders();
|
|
|
|
|
- data = new LinkedMultiValueMap<>();
|
|
|
|
|
- data.add("username", uname);
|
|
|
|
|
- data.add("customerIp", "cspxp.pc.ehuatai.com");
|
|
|
|
|
- data.add("messageType", "01");
|
|
|
|
|
- data.add("comcode", comcode);
|
|
|
|
|
- entity = new HttpEntity<>(data, headers);
|
|
|
|
|
- restTemplate.exchange(baseUrl + "/ShakeHandsAction.do?cmd=verificationFlag", HttpMethod.POST, entity, String.class);
|
|
|
|
|
-
|
|
|
|
|
- headers = buildJsonHeaders();
|
|
|
|
|
- data = new LinkedMultiValueMap<>();
|
|
|
|
|
- data.add("userName", uname);
|
|
|
|
|
- entity = new HttpEntity<>(data, headers);
|
|
|
|
|
- restTemplate.exchange(baseUrl + "/ShakeHandsAction.do?cmd=getPrompt", HttpMethod.POST, entity, String.class);
|
|
|
|
|
-
|
|
|
|
|
- System.out.println("获取机构结束==========");
|
|
|
|
|
- return comcode;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private Map<String, Object> doLogin(String uname, String pwd, String comcode) throws Exception {
|
|
|
|
|
- System.out.println("登录开始==========");
|
|
|
|
|
- RestTemplate restTemplate = getRestTemplate();
|
|
|
|
|
- HttpHeaders headers = buildJsonHeaders();
|
|
|
|
|
- MultiValueMap<String, String> data = new LinkedMultiValueMap<>();
|
|
|
|
|
- data.add("username", uname);
|
|
|
|
|
- data.add("password", pwd);
|
|
|
|
|
- data.add("ip", "csp.pc.ehuatai.com");
|
|
|
|
|
- data.add("comcode", comcode);
|
|
|
|
|
- data.add("mobile", "");
|
|
|
|
|
- data.add("verificationCode", "");
|
|
|
|
|
- data.add("weChatFlag", "");
|
|
|
|
|
- HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(data, headers);
|
|
|
|
|
- ResponseEntity<String> response = restTemplate.exchange(
|
|
|
|
|
- baseUrl + "/ShakeHandsAction.do?cmd=checkUser", HttpMethod.POST, entity, String.class);
|
|
|
|
|
- extractCookies(response);
|
|
|
|
|
-
|
|
|
|
|
- headers = new HttpHeaders();
|
|
|
|
|
- headers.set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
|
|
|
|
|
- headers.set("Accept-Language", "zh-CN,zh;q=0.9");
|
|
|
|
|
- headers.set("Cache-Control", "no-cache");
|
|
|
|
|
- headers.set("Connection", "keep-alive");
|
|
|
|
|
- headers.set("Content-Type", "application/x-www-form-urlencoded");
|
|
|
|
|
- headers.set("Origin", "https://cspxp.pc.ehuatai.com");
|
|
|
|
|
- headers.set("Pragma", "no-cache");
|
|
|
|
|
- headers.set("Referer", "https://cspxp.pc.ehuatai.com/htcsp/ShakeHandsAction.do?cmd=exitLogin");
|
|
|
|
|
- headers.set("Sec-Fetch-Dest", "document");
|
|
|
|
|
- headers.set("Sec-Fetch-Mode", "navigate");
|
|
|
|
|
- headers.set("Sec-Fetch-Site", "same-origin");
|
|
|
|
|
- headers.set("Sec-Fetch-User", "?1");
|
|
|
|
|
- headers.set("Upgrade-Insecure-Requests", "1");
|
|
|
|
|
- headers.set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36");
|
|
|
|
|
- headers.set("sec-ch-ua", "\"Google Chrome\";v=\"143\", \"Chromium\";v=\"143\", \"Not A(Brand)\";v=\"24\"");
|
|
|
|
|
- headers.set("sec-ch-ua-mobile", "?0");
|
|
|
|
|
- headers.set("sec-ch-ua-platform", "\"Windows\"");
|
|
|
|
|
-
|
|
|
|
|
- data = new LinkedMultiValueMap<>();
|
|
|
|
|
- data.add("username", uname);
|
|
|
|
|
- data.add("password", pwd);
|
|
|
|
|
- data.add("comcode", comcode);
|
|
|
|
|
- data.add("verificationCode", "");
|
|
|
|
|
- data.add("yanzhengtupianflag", "");
|
|
|
|
|
- data.add("brownVerb", "143.0.0.0");
|
|
|
|
|
- data.add("brownVern", "Chrome");
|
|
|
|
|
- data.add("bindflag", "");
|
|
|
|
|
- data.add("customerIp", "127.0.0.1");
|
|
|
|
|
- data.add("customerCity", "未知");
|
|
|
|
|
- data.add("userIsNowFlag", "");
|
|
|
|
|
- data.add("sendNecessityIpt", "X");
|
|
|
|
|
- data.add("wwaUserCode", "");
|
|
|
|
|
- data.add("weChatFlag", "");
|
|
|
|
|
- data.add("validStatus", "1");
|
|
|
|
|
- entity = new HttpEntity<>(data, headers);
|
|
|
|
|
- ResponseEntity<String> loginResp = restTemplate.exchange(
|
|
|
|
|
- baseUrl + "/ShakeHandsAction.do?cmd=loginWelcom", HttpMethod.POST, entity, String.class);
|
|
|
|
|
- extractCookies(loginResp);
|
|
|
|
|
-
|
|
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
|
|
- if (!loginResp.getBody().contains("请填写正确的用户名和密码")) {
|
|
|
|
|
- Map<String, Object> cookies = new HashMap<>();
|
|
|
|
|
- cookies.put("JSESSIONID", jsessionId);
|
|
|
|
|
- cookies.put("BIGipServerypKFOfHGLAALYYraCSdVMw", bigIpCookie);
|
|
|
|
|
- result.put("code", 200);
|
|
|
|
|
- result.put("cookies", cookies);
|
|
|
|
|
- result.put("comcode", comcode);
|
|
|
|
|
- result.put("message", "登录成功");
|
|
|
|
|
- } else {
|
|
|
|
|
- result.put("code", 400);
|
|
|
|
|
- result.put("message", "账号密码错误");
|
|
|
|
|
|
|
+ // 未匹配取第一条
|
|
|
|
|
+ if (matchCode == null) {
|
|
|
|
|
+ Map<String, Object> first = comList.get(0);
|
|
|
|
|
+ matchCode = first.get("comcode") + "-" + first.get("comcname");
|
|
|
}
|
|
}
|
|
|
- System.out.println("登录结束==========");
|
|
|
|
|
- return result;
|
|
|
|
|
|
|
+ // 前置一系列空接口
|
|
|
|
|
+ callEmptyJsonApi(ctx, rt, URL_JUDGE_FORWARD, null);
|
|
|
|
|
+ callEmptyJsonApi(ctx, rt, URL_GET_MAC, Map.of("username", username));
|
|
|
|
|
+ callEmptyJsonApi(ctx, rt, URL_VERIFY_FLAG, Map.of("username", username, "customerIp", "cspxp.pc.ehuatai.com", "messageType", "01", "comcode", matchCode));
|
|
|
|
|
+ callEmptyJsonApi(ctx, rt, URL_GET_PROMPT, Map.of("username", username));
|
|
|
|
|
+ log.info("机构信息获取完成:{}", matchCode);
|
|
|
|
|
+ return matchCode;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void extractCookies(ResponseEntity<String> response) {
|
|
|
|
|
- List<String> cookies = response.getHeaders().get("Set-Cookie");
|
|
|
|
|
- if (cookies != null) {
|
|
|
|
|
- for (String cookie : cookies) {
|
|
|
|
|
- if (cookie.contains("JSESSIONID=")) {
|
|
|
|
|
- jsessionId = extractCookieValue(cookie, "JSESSIONID");
|
|
|
|
|
- }
|
|
|
|
|
- if (cookie.contains("BIGipServerypKFOfHGLAALYYraCSdVMw=")) {
|
|
|
|
|
- bigIpCookie = extractCookieValue(cookie, "BIGipServerypKFOfHGLAALYYraCSdVMw");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ /** 无返回空接口统一调用 */
|
|
|
|
|
+ private void callEmptyJsonApi(CrawlContext ctx, RestTemplate rt, String url, Map<String, String> params) {
|
|
|
|
|
+ HttpHeaders jsonHeader = buildJsonHeaders(ctx);
|
|
|
|
|
+ MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
|
|
|
|
|
+ if (params != null) {
|
|
|
|
|
+ params.forEach(form::add);
|
|
|
}
|
|
}
|
|
|
|
|
+ HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(form, jsonHeader);
|
|
|
|
|
+ ResponseEntity<String> responseEntity = rt.postForEntity(url, requestEntity, String.class);
|
|
|
|
|
+ // 从本次请求的响应实体中获取Set-Cookie
|
|
|
|
|
+ parseSetCookie(responseEntity, ctx);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private String extractCookieValue(String cookieHeader, String name) {
|
|
|
|
|
- Pattern pattern = Pattern.compile(name + "=([^;]+)");
|
|
|
|
|
- Matcher matcher = pattern.matcher(cookieHeader);
|
|
|
|
|
- if (matcher.find()) {
|
|
|
|
|
- return matcher.group(1);
|
|
|
|
|
|
|
+ /** 提交账号密码登录 */
|
|
|
|
|
+ private Map<String, Object> submitLogin(CrawlContext ctx, RestTemplate rt, String user, String pwd, String fullComCode) {
|
|
|
|
|
+ log.info("正式登录提交:{}", user);
|
|
|
|
|
+ HttpHeaders jsonHeader = buildJsonHeaders(ctx);
|
|
|
|
|
+ MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
|
|
|
|
|
+ param.add("username", user);
|
|
|
|
|
+ param.add("password", pwd);
|
|
|
|
|
+ param.add("ip", "csp.pc.ehuatai.com");
|
|
|
|
|
+ param.add("comcode", fullComCode);
|
|
|
|
|
+ param.add("mobile", "");
|
|
|
|
|
+ param.add("verificationCode", "");
|
|
|
|
|
+ param.add("weChatFlag", "");
|
|
|
|
|
+ ResponseEntity<String> checkUserResp = rt.postForEntity(URL_CHECK_USER, new HttpEntity<>(param, jsonHeader), String.class);
|
|
|
|
|
+ parseSetCookie(checkUserResp, ctx);
|
|
|
|
|
+ // 跳转登录页
|
|
|
|
|
+ HttpHeaders htmlHeader = buildHtmlHeaders(ctx);
|
|
|
|
|
+ MultiValueMap<String, String> loginForm = new LinkedMultiValueMap<>();
|
|
|
|
|
+ loginForm.add("username", user);
|
|
|
|
|
+ loginForm.add("password", pwd);
|
|
|
|
|
+ loginForm.add("comcode", fullComCode);
|
|
|
|
|
+ loginForm.add("verificationCode", "");
|
|
|
|
|
+ loginForm.add("yanzhengtupianflag", "");
|
|
|
|
|
+ loginForm.add("brownVerb", "143.0.0.0");
|
|
|
|
|
+ loginForm.add("brownVern", "Chrome");
|
|
|
|
|
+ loginForm.add("bindflag", "");
|
|
|
|
|
+ loginForm.add("customerIp", "127.0.0.1");
|
|
|
|
|
+ loginForm.add("customerCity", "未知");
|
|
|
|
|
+ loginForm.add("userIsNowFlag", "");
|
|
|
|
|
+ loginForm.add("sendNecessityIpt", "X");
|
|
|
|
|
+ loginForm.add("wwaUserCode", "");
|
|
|
|
|
+ loginForm.add("weChatFlag", "");
|
|
|
|
|
+ loginForm.add("validStatus", "1");
|
|
|
|
|
+ ResponseEntity<String> loginPageResp = rt.postForEntity(URL_LOGIN_WELCOME, new HttpEntity<>(loginForm, htmlHeader), String.class);
|
|
|
|
|
+ parseSetCookie(loginPageResp, ctx);
|
|
|
|
|
+ String body = loginPageResp.getBody();
|
|
|
|
|
+ if (body != null && body.contains("请填写正确的用户名和密码")) {
|
|
|
|
|
+ return Map.of("code", "400", "message", "账号或密码错误");
|
|
|
}
|
|
}
|
|
|
- return "";
|
|
|
|
|
|
|
+ return Map.of(
|
|
|
|
|
+ "code", "200",
|
|
|
|
|
+ "comcode", fullComCode,
|
|
|
|
|
+ COOKIE_JSESSIONID, ctx.jsessionId,
|
|
|
|
|
+ COOKIE_BIGIP, ctx.bigIpCookie,
|
|
|
|
|
+ "message", "登录成功"
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private Map<String, Object> htDecrypt(String jsonBody) {
|
|
|
|
|
- try {
|
|
|
|
|
- Map<String, Object> map = objectMapper.readValue(jsonBody, HashMap.class);
|
|
|
|
|
- String accessToken = (String) map.get("accessToken");
|
|
|
|
|
- String data = (String) map.get("data");
|
|
|
|
|
- String aesKey = HuaTaiCryptUtil.RSADecrypt(accessToken);
|
|
|
|
|
- String decrypted = HuaTaiCryptUtil.AESDecrypt(data, aesKey);
|
|
|
|
|
- return objectMapper.readValue(decrypted, HashMap.class);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- return new HashMap<>();
|
|
|
|
|
|
|
+ /** 拉取归属树gsInfo核心逻辑 */
|
|
|
|
|
+ private void fetchGsInfo(CrawlContext ctx, String comCode, String useridName, String dlrCode, String dlxyCode) throws Exception {
|
|
|
|
|
+ log.info("开始拉取归属信息");
|
|
|
|
|
+ RestTemplate rt = getRestTemplate();
|
|
|
|
|
+ HttpHeaders jsonHeader = buildJsonHeaders(ctx);
|
|
|
|
|
+ // 1. initSaledUser
|
|
|
|
|
+ MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
|
|
|
|
|
+ form.add("comcode", comCode);
|
|
|
|
|
+ ResponseEntity<String> userListResp = rt.postForEntity(URL_INIT_SALE_USER, new HttpEntity<>(form, jsonHeader), String.class);
|
|
|
|
|
+ List<Map<String, Object>> userList = objectMapper.readValue(userListResp.getBody(), List.class);
|
|
|
|
|
+ String targetUserId = "";
|
|
|
|
|
+ String targetUserName = "";
|
|
|
|
|
+ for (Map<String, Object> item : userList) {
|
|
|
|
|
+ if (useridName.equals(item.get("codecname"))) {
|
|
|
|
|
+ targetUserName = (String) item.get("codecname");
|
|
|
|
|
+ targetUserId = (String) item.get("codecode");
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 2. initSalesys
|
|
|
|
|
+ form.clear();
|
|
|
|
|
+ form.add("comcode", comCode);
|
|
|
|
|
+ ResponseEntity<String> saleSysResp = rt.postForEntity(URL_INIT_SALE_SYS, new HttpEntity<>(form, jsonHeader), String.class);
|
|
|
|
|
+ Map<String, Object> saleSysMap = objectMapper.readValue(saleSysResp.getBody(), Map.class);
|
|
|
|
|
+ String channelOrig = (String) saleSysMap.get("codecode");
|
|
|
|
|
+ String newChannelOrig = (String) saleSysMap.get("newcodecode");
|
|
|
|
|
+ // 3. 菜单页面拿机构编码
|
|
|
|
|
+ HttpHeaders htmlHeader = buildHtmlHeaders(ctx);
|
|
|
|
|
+ ResponseEntity<String> menuResp = rt.getForEntity(URL_MENU_CONTROL, String.class, new HttpEntity<>(htmlHeader));
|
|
|
|
|
+ String comGbCode = "";
|
|
|
|
|
+ String comName = "";
|
|
|
|
|
+ Matcher m = PAT_COMPANY_JSON.matcher(menuResp.getBody());
|
|
|
|
|
+ if (m.find()) {
|
|
|
|
|
+ List<Map<String, Object>> comList = objectMapper.readValue(m.group(1), List.class);
|
|
|
|
|
+ for (Map<String, Object> item : comList) {
|
|
|
|
|
+ if (comCode.equals(item.get("codecode"))) {
|
|
|
|
|
+ comGbCode = (String) item.get("codetype");
|
|
|
|
|
+ comName = (String) item.get("codecname");
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 4. initSelectSalesysall
|
|
|
|
|
+ form.clear();
|
|
|
|
|
+ form.add("comcode", comCode);
|
|
|
|
|
+ form.add("codeCode", channelOrig);
|
|
|
|
|
+ rt.postForEntity(URL_INIT_SELECT_SALE_ALL, new HttpEntity<>(form, jsonHeader), String.class);
|
|
|
|
|
+ // 5. 二次菜单访问
|
|
|
|
|
+ rt.getForEntity(URL_MENU_CONTROL, String.class, new HttpEntity<>(htmlHeader));
|
|
|
|
|
+ // 固定业务渠道编码
|
|
|
|
|
+ String ywCode = "1";
|
|
|
|
|
+ String xstx = "0401";
|
|
|
|
|
+ List<Map<String, Object>> channelList = List.of(
|
|
|
|
|
+ buildCodeItem("直接业务", "0"),
|
|
|
|
|
+ buildCodeItem("代理业务", "1"),
|
|
|
|
|
+ buildCodeItem("经纪业务", "4"),
|
|
|
|
|
+ buildCodeItem("电销/网销", "6")
|
|
|
|
|
+ );
|
|
|
|
|
+ for (Map<String, Object> ch : channelList) {
|
|
|
|
|
+ if ("代理业务".equals(ch.get("codecname"))) {
|
|
|
|
|
+ ywCode = (String) ch.get("codecode");
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ // 6. 提交确认用户信息
|
|
|
|
|
+ MultiValueMap<String, String> submitForm = new LinkedMultiValueMap<>();
|
|
|
|
|
+ submitForm.add("comcode", comCode);
|
|
|
|
|
+ submitForm.add("comcode_name", comName);
|
|
|
|
|
+ submitForm.add("comcode_gbcode", comGbCode);
|
|
|
|
|
+ submitForm.add("userid", targetUserId);
|
|
|
|
|
+ submitForm.add("userid_name", targetUserName);
|
|
|
|
|
+ submitForm.add("businessNature", ywCode);
|
|
|
|
|
+ submitForm.add("salesys", xstx);
|
|
|
|
|
+ submitForm.add("channel_orign", channelOrig);
|
|
|
|
|
+ submitForm.add("newChannel_orign", newChannelOrig);
|
|
|
|
|
+ submitForm.add("agentno_dl", dlrCode);
|
|
|
|
|
+ submitForm.add("agreementno_dl", dlxyCode);
|
|
|
|
|
+ submitForm.add("carType", "baojia");
|
|
|
|
|
+ // 其余空参数统一填充
|
|
|
|
|
+ List<String> emptyKeys = List.of("isTeamCarFlag","teamcarmodelcode","quotationNo","policyBI","policyCI");
|
|
|
|
|
+ emptyKeys.forEach(k -> submitForm.add(k, ""));
|
|
|
|
|
+ rt.postForEntity(URL_CONFIRM_USER, new HttpEntity<>(submitForm, buildHtmlHeaders(ctx)), String.class);
|
|
|
|
|
+ // 拉取渠道编码后赋值到上下文
|
|
|
|
|
+ ctx.ywlyName = ywCode;
|
|
|
|
|
+ ctx.xstxCode = xstx;
|
|
|
|
|
+ ctx.dlrCode = dlrCode;
|
|
|
|
|
+ ctx.dlxyCode = dlxyCode;
|
|
|
|
|
+
|
|
|
|
|
+ // 回填gs
|
|
|
|
|
+ Map<String, Object> gs = new HashMap<>();
|
|
|
|
|
+ gs.put("userid_name", targetUserName);
|
|
|
|
|
+ gs.put("userid_value", targetUserId);
|
|
|
|
|
+ gs.put("comcode_gbdistrictcode", comGbCode);
|
|
|
|
|
+ gs.put("comcode_name", comName);
|
|
|
|
|
+ gs.put("businessnature_value", ctx.ywlyName);
|
|
|
|
|
+ gs.put("salesys_value", ctx.xstxCode);
|
|
|
|
|
+ gs.put("channel_orign", channelOrig);
|
|
|
|
|
+ gs.put("newChannel_orign", newChannelOrig);
|
|
|
|
|
+ ctx.gsInfo = gs;
|
|
|
|
|
+ log.info("归属信息拉取完成");
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|