|
|
@ -2,8 +2,10 @@ package com.epmet.commons.tools.processor; |
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.epmet.commons.tools.annotation.MaskResponse; |
|
|
|
import com.epmet.commons.tools.enums.IdCardTypeEnum; |
|
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.utils.IdCardRegexUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
@ -13,6 +15,7 @@ import java.lang.reflect.Field; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
/** |
|
|
|
* desc:脱敏处理器 |
|
|
@ -136,21 +139,29 @@ public class MaskProcessor { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 唯一整件号打码,可能是身份证号或者是护照号 |
|
|
|
* 将明文字符串打码变为掩码。保留前6,后面打码 |
|
|
|
* @param originString |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private String maskIdCard(String originString) { |
|
|
|
int clearTextLength = 12; |
|
|
|
// 仅将6位之后的全都打码
|
|
|
|
int length = originString.length(); |
|
|
|
if (length <= clearTextLength) { |
|
|
|
|
|
|
|
IdCardRegexUtils regexUtil = IdCardRegexUtils.parse(originString); |
|
|
|
if (regexUtil.getTypeEnum() == IdCardTypeEnum.SFZH) { |
|
|
|
// 身份证号
|
|
|
|
// 仅将6位之后的全都打码
|
|
|
|
int maskedTextLength = 12; |
|
|
|
int length = originString.length(); |
|
|
|
String maskStr = StrUtil.repeatByLength("*", length - maskedTextLength); |
|
|
|
return originString.replaceAll("^(\\d{10})\\d+([a-zA-Z0-9]{2})$", new StringBuilder("$1").append(maskStr).append("$2").toString()); |
|
|
|
} else if (regexUtil.getTypeEnum() == IdCardTypeEnum.PASSPORT) { |
|
|
|
// 护照,前两位,后两位为明文,其他*
|
|
|
|
String maskStr = StrUtil.repeatByLength("*", originString.length() - 4); |
|
|
|
return originString.replaceAll("^([a-zA-Z0-9]{2})\\d+(\\d{2})$", new StringBuilder("$1").append(maskStr).append("$2").toString()); |
|
|
|
} else { |
|
|
|
// 其他情况,不码
|
|
|
|
return originString; |
|
|
|
} |
|
|
|
|
|
|
|
String maskStr = StrUtil.repeatByLength("*", length - clearTextLength); |
|
|
|
|
|
|
|
return originString.replaceAll("^(\\d{10})\\d+([a-zA-Z0-9]{2})$", new StringBuilder("$1").append(maskStr).append("$2").toString()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|