f07c9996 by xu

可信空间连接器入住接口

1 parent 34071a3e
...@@ -31,19 +31,20 @@ public class IDValidator { ...@@ -31,19 +31,20 @@ public class IDValidator {
31 if (idCard == null || !idCardPattern.matcher(idCard).matches()) { 31 if (idCard == null || !idCardPattern.matcher(idCard).matches()) {
32 return false; 32 return false;
33 } 33 }
34 // 2. 校验校验码 34 return true;
35 char[] idChars = idCard.toUpperCase().toCharArray(); // 统一转为大写 35 // // 2. 校验校验码
36 int sum = 0; 36 // char[] idChars = idCard.toUpperCase().toCharArray(); // 统一转为大写
37 for (int i = 0; i < 17; i++) { 37 // int sum = 0;
38 // 前17位必须为数字(正则已保证,此处可简化) 38 // for (int i = 0; i < 17; i++) {
39 int num = idChars[i] - '0'; 39 // // 前17位必须为数字(正则已保证,此处可简化)
40 sum += num * WEIGHTS[i]; 40 // int num = idChars[i] - '0';
41 } 41 // sum += num * WEIGHTS[i];
42 // 计算校验码 42 // }
43 int checkCodeIndex = sum % 11; 43 // // 计算校验码
44 char calculatedCheckCode = CHECK_CODES[checkCodeIndex]; 44 // int checkCodeIndex = sum % 11;
45 // 对比最后一位校验码 45 // char calculatedCheckCode = CHECK_CODES[checkCodeIndex];
46 return idChars[17] == calculatedCheckCode; 46 // // 对比最后一位校验码
47 // return idChars[17] == calculatedCheckCode;
47 } 48 }
48 49
49 /** 50 /**
...@@ -77,6 +78,7 @@ public class IDValidator { ...@@ -77,6 +78,7 @@ public class IDValidator {
77 public static void main(String[] args) { 78 public static void main(String[] args) {
78 // 测试案例 79 // 测试案例
79 String[] testCases = { 80 String[] testCases = {
81 "42019880101XXXX",
80 "110101199001011234", // 合法格式+正确校验码 82 "110101199001011234", // 合法格式+正确校验码
81 "11010119900101123X", // 合法格式+正确校验码(X) 83 "11010119900101123X", // 合法格式+正确校验码(X)
82 "110101199001011235", // 合法格式+错误校验码 84 "110101199001011235", // 合法格式+错误校验码
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!