xuqiang пре 2 недеља
родитељ
комит
6083b000e1

+ 2 - 1
tenant/insurance/quotation-ansheng/src/main/java/com/jzg/quotation/ansheng/crawler/service/AnShengCrawlerLoginService.java

@@ -1,5 +1,6 @@
 package com.jzg.quotation.ansheng.crawler.service;
 
+import com.jzg.commons.entity.quote.vo.AttributionInformationVo;
 import com.jzg.quotation.ansheng.crawler.entity.request.DownloadTokenResult;
 
 public interface AnShengCrawlerLoginService {
@@ -13,6 +14,6 @@ public interface AnShengCrawlerLoginService {
     String login(String userName, String password);
 
 
-    DownloadTokenResult getObtainDownloadToken(String username, String password);
+    DownloadTokenResult getObtainDownloadToken(AttributionInformationVo attributionInformationVo);
 
 }

+ 7 - 3
tenant/insurance/quotation-ansheng/src/main/java/com/jzg/quotation/ansheng/crawler/service/impl/AnShengCrawlerLoginServiceImpl.java

@@ -1,6 +1,7 @@
 package com.jzg.quotation.ansheng.crawler.service.impl;
 
 import com.jzg.commons.constants.quote.enums.base.ExpenseRequestUrl;
+import com.jzg.commons.entity.quote.vo.AttributionInformationVo;
 import com.jzg.commons.entity.quote.vo.identify.SliderCaptchaVo;
 import com.jzg.commons.exception.SystemException;
 import com.jzg.quotation.ansheng.crawler.component.AnShengCrawlerCacheComponent;
@@ -8,6 +9,7 @@ import com.jzg.quotation.ansheng.crawler.component.AnShengCrawlerRequestComponen
 import com.jzg.quotation.ansheng.crawler.entity.request.*;
 import com.jzg.quotation.ansheng.crawler.entity.response.AnShengCrawlerVerifyResponse;
 import com.jzg.quotation.ansheng.crawler.service.AnShengCrawlerLoginService;
+import com.jzg.quotation.ansheng.crawler.utils.RSAUtils;
 import com.jzg.quotation.commons.service.ExteriorUtilsRequest;
 import lombok.RequiredArgsConstructor;
 import org.springframework.http.HttpHeaders;
@@ -66,7 +68,9 @@ public class AnShengCrawlerLoginServiceImpl implements AnShengCrawlerLoginServic
     }
 
     @Override
-    public DownloadTokenResult getObtainDownloadToken(String username, String password) {
+    public DownloadTokenResult getObtainDownloadToken(AttributionInformationVo attributionInformationVo) {
+        String username = attributionInformationVo.getUsername();
+        String password = attributionInformationVo.getPassword();
         // 构建请求头
         HttpHeaders headers = buildCommonHeaders();
         headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
@@ -78,7 +82,7 @@ public class AnShengCrawlerLoginServiceImpl implements AnShengCrawlerLoginServic
         // 表单参数
         MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
         formData.add("account", username);
-        formData.add("password", password);
+        formData.add("password", RSAUtils.encrypt(password));
         formData.add("phone", "");
         formData.add("agentCode", "");
         formData.add("verificationCode", "");
@@ -88,7 +92,7 @@ public class AnShengCrawlerLoginServiceImpl implements AnShengCrawlerLoginServic
         formData.add("dragSliderCode", dragCode != null ? dragCode : "");
         // 发起POST表单请求,使用项目已有的form请求方法
         LoginResp loginResp = anShengCrawlerRequestComponent.downloadToken( formData, urlParams,headers);
-        if (loginResp == null) {
+        if (loginResp == null || 0 != loginResp.getCode()) {
             DownloadTokenResult result = new DownloadTokenResult();
             result.setCode(400);
             result.setMessage("登录响应为空");

+ 1 - 3
tenant/insurance/quotation-ansheng/src/main/java/com/jzg/quotation/ansheng/crawler/service/impl/AnShengCrawlerQuoteProcessServiceImpl.java

@@ -58,9 +58,7 @@ public class AnShengCrawlerQuoteProcessServiceImpl implements AnShengCrawlerQuot
 
     @Override
     public DownloadTokenResult obtainDownloadToken(AttributionInformationVo attributionInformationVo) {
-        String username = attributionInformationVo.getUsername();
-        String password = attributionInformationVo.getPassword();
-        return anShengCrawlerLoginService.getObtainDownloadToken(username, password);
+        return anShengCrawlerLoginService.getObtainDownloadToken(attributionInformationVo);
     }
 
 }

+ 3 - 0
tenant/insurance/quotation-ansheng/src/main/java/com/jzg/quotation/ansheng/crawler/service/impl/AnShengCrawlerRequestImpl.java

@@ -577,6 +577,9 @@ public class AnShengCrawlerRequestImpl implements AnShengCrawlerRequest {
         DownloadPolicyResultVo downloadPolicyResultVo = new DownloadPolicyResultVo();
         AnShengCrawlerOrder anShengCrawlerOrder = anShengCrawlerOrderService.getById(downloadPolicyVo.getOrder().getOrdersNo());
         DownloadTokenResult obtainDownloadToken = anShengCrawlerQuoteProcessService.obtainDownloadToken(downloadPolicyVo.getOrder().getAttributionInformationVo());
+        if (200 != obtainDownloadToken.getCode()){
+            throw new SystemException("获取token失败,请联系管理员");
+        }
         // 缓存token,避免重复调用
         String loginToken = obtainDownloadToken.getToken();
         String bdToken = obtainDownloadToken.getBdToken();

+ 112 - 0
tenant/insurance/quotation-ansheng/src/main/java/com/jzg/quotation/ansheng/crawler/utils/RSAUtils.java

@@ -0,0 +1,112 @@
+package com.jzg.quotation.ansheng.crawler.utils;
+
+import javax.crypto.Cipher;
+import java.nio.charset.StandardCharsets;
+import java.security.KeyFactory;
+import java.security.PublicKey;
+import java.security.spec.X509EncodedKeySpec;
+import java.util.Base64;
+
+/**
+ * RSA加密工具类
+ *
+ * @author YourName
+ * @date 2026-08-25
+ */
+public class RSAUtils {
+
+    private static final String PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy+4Uy6zba9JeGu7LR7krxkQ+Ivt7MIl+jR/F0rCoPUDPlqvrKIQAeRlJ8txkLSskLAU9f2F2bjbUmzlBdrxVPz/mPIXA866SAd4ELTAdF3oltCa9yLPERLCLMEwUAjX2lUSS3gxAuXbIuPuVJQi1xQeV+VRiJulMFNjhlq86bRpsc7SZ0rMF3Ahc9WHxulcXofaDRLx+sTxzeTsZC3zCh5Dk2hnHaj7o2C/n8U6ZvfifKeB2kWZyoFlmgX8/6agSfkmdxuTw5CZk9qU/1k0ykg2N5whBfnaMbUD5P08KuU/eBIEriS7U7yQruVfovsgN+c2h4XPEcMG0WrqWZbRNpQIDAQAB";
+
+
+    private static volatile PublicKey publicKey;
+
+    /**
+     * 获取公钥
+     */
+    public static PublicKey getPublicKey() {
+        if (publicKey == null) {
+            synchronized (RSAUtils.class) {
+                if (publicKey == null) {
+                    publicKey = parsePublicKey();
+                }
+            }
+        }
+        return publicKey;
+    }
+
+    /**
+     * 解析公钥
+     */
+    private static PublicKey parsePublicKey() {
+        try {
+            byte[] keyBytes = Base64.getDecoder().decode(PUBLIC_KEY);
+            X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
+            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
+            return keyFactory.generatePublic(spec);
+        } catch (Exception e) {
+            throw new RuntimeException("解析RSA公钥失败", e);
+        }
+    }
+
+    /**
+     * RSA加密
+     *
+     * @param plaintext 明文
+     * @return Base64编码的密文
+     * @throws RuntimeException 加密失败时抛出
+     */
+    public static String encrypt(String plaintext) {
+        if (plaintext == null) {
+            throw new IllegalArgumentException("明文不能为null");
+        }
+
+        try {
+            Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
+            cipher.init(Cipher.ENCRYPT_MODE, getPublicKey());
+
+            byte[] encrypted = cipher.doFinal(plaintext.getBytes(StandardCharsets.UTF_8));
+            return Base64.getEncoder().encodeToString(encrypted);
+        } catch (Exception e) {
+            throw new RuntimeException("RSA加密失败", e);
+        }
+    }
+
+    /**
+     * RSA加密(带最大长度限制检查)
+     * RSA最大加密长度为 密钥长度/8 - 11(PKCS1Padding)
+     * 对于2048位密钥,最大加密长度为245字节
+     *
+     * @param plaintext 明文
+     * @return Base64编码的密文
+     * @throws IllegalArgumentException 明文过长时抛出
+     */
+    public static String encryptWithCheck(String plaintext) {
+        if (plaintext == null) {
+            throw new IllegalArgumentException("明文不能为null");
+        }
+
+        // 2048位密钥,PKCS1Padding最大加密长度为245字节
+        int maxLength = 245;
+        byte[] plainBytes = plaintext.getBytes(StandardCharsets.UTF_8);
+        if (plainBytes.length > maxLength) {
+            throw new IllegalArgumentException(
+                    String.format("明文长度超过最大加密长度限制:当前%d字节,最大%d字节",
+                            plainBytes.length, maxLength)
+            );
+        }
+
+        return encrypt(plaintext);
+    }
+
+    /**
+     * 验证公钥是否有效
+     */
+    public static boolean isPublicKeyValid() {
+        try {
+            return getPublicKey() != null;
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
+}