zjh
昨天 ad4326adc4ccad14f090fba5acb435deab8260db
ltkj-admin/src/test/java/zjhTest.java
@@ -1,7 +1,6 @@
import cn.hutool.core.io.FileUtil;
import com.ltkj.LtkjApplication;
import com.ltkj.framework.config.MatchUtils;
import com.ltkj.LtkjApplication;import com.ltkj.framework.config.MatchUtils;
import com.ltkj.hosp.domain.TjJcycxm;
import com.ltkj.hosp.idutil.IdUtils;
import jodd.util.StringUtil;
@@ -33,6 +32,9 @@
import java.io.File;
import java.io.IOException;
/**
 * @Author: 西安路泰科技有限公司/赵佳豪
 * @Date: 2022/12/12 9:05
@@ -69,14 +71,42 @@
    }
    private static final String[] CHECK_INDEX = {"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"};
        public static void main(String[] args) throws Exception {
            String s = "620821201106110016";
            System.out.println(String.valueOf(MatchUtils.getSexByIdCard(s)));
            String s = "62272219650528411X";
            System.out.println(isValidIdCard(s) ? "合法" : "非法");
        }
    public static boolean isValidIdCard(String idCardNumber) {
        // 正则表达式,匹配身份证号码的格式
        String regex = "(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(idCardNumber);
        // 判断是否匹配身份证号码的格式
        if (!matcher.matches()) {
            return false;
        }
        // 验证身份证号码中的校验位
        if (idCardNumber.length() == 18) {
            int[] weights = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
            char[] chars = idCardNumber.toCharArray();
            int sum = 0;
            for (int i = 0; i < weights.length; i++) {
                sum += (chars[i] - '0') * weights[i];
            }
            char[] checkCodes = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
            char checkCode = checkCodes[sum % 11];
            return chars[17] == checkCode || (chars[17] == 'x' && checkCode == 'X');
        }
        return true;
    }
    /**
     * 执行生成