1
0

2 کامیت‌ها 5a73cf8452 ... 59108e45f6

نویسنده SHA1 پیام تاریخ
  吴树波 59108e45f6 Merge remote-tracking branch 'origin/saas-api' into saas-api 2 هفته پیش
  吴树波 981a23fb20 修复 2 هفته پیش

+ 25 - 8
fs-service/src/main/java/com/fs/comm/service/CommSmsSendService.java

@@ -110,11 +110,11 @@ public class CommSmsSendService {
             throw new ServiceException("客户不存在");
         }
         String targetPhone = StringUtils.isNotBlank(param.getPhone()) ? param.getPhone() : customer.getMobile();
-        checkSmsBlacklist(companyId, targetPhone);
+        checkCustomerSmsBlacklist(companyId, targetPhone);
         if (companyUserId != null) {
             CompanyUser companyUser = companyUserService.selectCompanyUserById(companyUserId);
             if (companyUser != null && StringUtils.isNotBlank(companyUser.getPhonenumber())) {
-                checkSmsBlacklist(companyId, companyUser.getPhonenumber());
+                checkSalesSmsBlacklist(companyId, companyUser.getPhonenumber());
             }
         }
 
@@ -298,14 +298,14 @@ public class CommSmsSendService {
             for (Long customerId : param.getCustomerIds()) {
                 CrmCustomer customer = crmCustomerService.selectCrmCustomerById(customerId);
                 if (customer != null && StringUtils.isNotBlank(customer.getMobile())) {
-                    checkSmsBlacklist(param.getCompanyId(), customer.getMobile());
+                    checkCustomerSmsBlacklist(param.getCompanyId(), customer.getMobile());
                 }
             }
         }
         if (param.getCompanyUserId() != null) {
             CompanyUser companyUser = companyUserService.selectCompanyUserById(param.getCompanyUserId());
             if (companyUser != null && StringUtils.isNotBlank(companyUser.getPhonenumber())) {
-                checkSmsBlacklist(param.getCompanyId(), companyUser.getPhonenumber());
+                checkSalesSmsBlacklist(param.getCompanyId(), companyUser.getPhonenumber());
             }
         }
         try {
@@ -359,17 +359,34 @@ public class CommSmsSendService {
         }
     }
 
-    private void checkSmsBlacklist(Long companyId, String phone) {
+    private void checkCustomerSmsBlacklist(Long companyId, String phone) {
+        checkSmsBlacklistInternal(companyId, phone, false);
+    }
+
+    private void checkSalesSmsBlacklist(Long companyId, String phone) {
+        checkSmsBlacklistInternal(companyId, phone, true);
+    }
+
+    private void checkSmsBlacklistInternal(Long companyId, String phone, boolean salesSide) {
         if (StringUtils.isBlank(phone)) {
             return;
         }
+        String targetValue = PhoneUtil.resolvePhoneForBlacklist(phone);
+        if (StringUtils.isBlank(targetValue)) {
+            throw new ServiceException("手机号无效或解密失败");
+        }
         CompanyVoiceRoboticCallBlacklistCheckParam checkParam = new CompanyVoiceRoboticCallBlacklistCheckParam();
         checkParam.setCompanyId(companyId);
         checkParam.setBusinessType(BusinessTypeEnum.SMS.getCode());
-        checkParam.setTargetValue(PhoneUtil.decryptPhone(phone));
+        checkParam.setTargetType(1);
+        checkParam.setTargetValue(targetValue);
         CompanyVoiceRoboticCallBlacklistCheckVO vo = companyVoiceRoboticCallBlacklistService.checkBlacklist(checkParam);
-        if (!vo.getPass()) {
-            throw new ServiceException("号码命中短信黑名单: " + phone);
+        if (Boolean.TRUE.equals(vo.getPass())) {
+            return;
+        }
+        if (Boolean.TRUE.equals(vo.getHitBlacklist())) {
+            throw new ServiceException(salesSide ? "销售号码黑名单校验未通过" : "客户号码黑名单校验未通过");
         }
+        throw new ServiceException(StringUtils.defaultIfBlank(vo.getReason(), "黑名单校验未通过"));
     }
 }

+ 11 - 2
fs-service/src/main/java/com/fs/common/service/impl/SmsServiceImpl.java

@@ -33,6 +33,7 @@ import com.fs.crm.param.SmsSendParam;
 import com.fs.crm.param.SmsSendUserParam;
 import com.fs.crm.service.ICrmCustomerService;
 import com.fs.his.config.FsSmsConfig;
+import com.fs.his.utils.PhoneUtil;
 import com.fs.his.domain.FsPayConfig;
 import com.fs.his.domain.FsStoreOrder;
 import com.fs.his.mapper.FsPackageOrderMapper;
@@ -781,7 +782,11 @@ public class SmsServiceImpl implements ISmsService
             CompanyVoiceRoboticCallBlacklistCheckParam salesBlacklistParam = new CompanyVoiceRoboticCallBlacklistCheckParam();
             salesBlacklistParam.setCompanyId(param.getCompanyId());
             salesBlacklistParam.setBusinessType(BusinessTypeEnum.SMS.getCode());
-            salesBlacklistParam.setTargetValue(companyUser.getPhonenumber());
+            salesBlacklistParam.setTargetType(1);
+            salesBlacklistParam.setTargetValue(PhoneUtil.resolvePhoneForBlacklist(companyUser.getPhonenumber()));
+            if (StringUtils.isEmpty(salesBlacklistParam.getTargetValue())) {
+                throw new RuntimeException("销售手机号无效或解密失败");
+            }
             CompanyVoiceRoboticCallBlacklistCheckVO salesBlacklistVo = companyVoiceRoboticCallBlacklistService.checkBlacklist(salesBlacklistParam);
             if (!salesBlacklistVo.getPass()){
                 throw new RuntimeException("销售号码黑名单校验未通过");
@@ -796,7 +801,11 @@ public class SmsServiceImpl implements ISmsService
                 CompanyVoiceRoboticCallBlacklistCheckParam customerBlacklistParam = new CompanyVoiceRoboticCallBlacklistCheckParam();
                 customerBlacklistParam.setCompanyId(param.getCompanyId());
                 customerBlacklistParam.setBusinessType(BusinessTypeEnum.SMS.getCode());
-                customerBlacklistParam.setTargetValue(crmCustomer.getMobile());
+                customerBlacklistParam.setTargetType(1);
+                customerBlacklistParam.setTargetValue(PhoneUtil.resolvePhoneForBlacklist(crmCustomer.getMobile()));
+                if (StringUtils.isEmpty(customerBlacklistParam.getTargetValue())) {
+                    throw new RuntimeException("客户手机号无效或解密失败");
+                }
                 CompanyVoiceRoboticCallBlacklistCheckVO customerBlacklistVo = companyVoiceRoboticCallBlacklistService.checkBlacklist(customerBlacklistParam);
                 if (!customerBlacklistVo.getPass()){
                     throw new RuntimeException("客户号码黑名单校验未通过");

+ 44 - 10
fs-service/src/main/java/com/fs/his/utils/PhoneUtil.java

@@ -26,30 +26,31 @@ public class PhoneUtil {
     * 解密
     */
     public static String decryptPhone(String encryptedText) {
-        String text=null;
+        String text = null;
         try {
             SecretKeySpec secretKey = new SecretKeySpec("AESAabCdeREssREA".getBytes(), "AES");
             Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
             cipher.init(Cipher.DECRYPT_MODE, secretKey);
             byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(encryptedText));
             text = new String(decryptedBytes);
-        } catch (Exception e) {
-            e.printStackTrace();
+        } catch (Exception ignored) {
+            // 非 AES 密文时解密失败属正常,由 decryptAutoPhone 兜底
         }
         return text;
     }
+
     /**
-    * 解密加*
-    */
+     * 解密加*
+     */
     public static String decryptPhoneMk(String encryptedText) {
-        String text=null;
+        String text = null;
         try {
             SecretKeySpec secretKey = new SecretKeySpec("AESAabCdeREssREA".getBytes(), "AES");
             Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
             cipher.init(Cipher.DECRYPT_MODE, secretKey);
             byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(encryptedText));
             text = new String(decryptedBytes);
-            text =text.replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2");
+            text = text.replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2");
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -64,10 +65,43 @@ public class PhoneUtil {
             return null;
         }
         String text = encryptedText.trim();
-        if (text.length() > 11) {
-            return decryptPhone(text);
+        if (text.length() <= 11 && text.matches("\\d+")) {
+            return text;
         }
-        return text;
+        if (looksLikePlainPhone(text)) {
+            return text;
+        }
+        String decrypted = decryptPhone(text);
+        if (decrypted != null && !decrypted.isEmpty()) {
+            return decrypted;
+        }
+        return looksLikePlainPhone(text) ? text : null;
+    }
+
+    /**
+     * 黑名单校验用手机号:自动解密并归一化(去 +86、空格等)
+     */
+    public static String resolvePhoneForBlacklist(String phone) {
+        String decrypted = decryptAutoPhone(phone);
+        if (decrypted == null || decrypted.isEmpty()) {
+            return null;
+        }
+        return decrypted.replace(" ", "")
+                .replace("-", "")
+                .replace("+86", "")
+                .replace("(", "")
+                .replace(")", "");
+    }
+
+    private static boolean looksLikePlainPhone(String text) {
+        if (text == null || text.isEmpty()) {
+            return false;
+        }
+        if (!text.matches("^[+\\d\\-\\s()]+$")) {
+            return false;
+        }
+        String digits = text.replaceAll("\\D", "");
+        return digits.length() >= 11 && digits.length() <= 15;
     }
 
     public static String decryptAutoPhoneMk(String encryptedText) {