Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
csbr-daop
/
ms-data-circulation-portal-service
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
f07c9996
authored
2025-10-29 11:47:37 +0800
by
xu
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
可信空间连接器入住接口
1 parent
34071a3e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
13 deletions
src/main/java/com/csbr/qingcloud/portal/util/IDValidator.java
src/main/java/com/csbr/qingcloud/portal/util/IDValidator.java
View file @
f07c999
...
...
@@ -31,19 +31,20 @@ public class IDValidator {
if
(
idCard
==
null
||
!
idCardPattern
.
matcher
(
idCard
).
matches
())
{
return
false
;
}
// 2. 校验校验码
char
[]
idChars
=
idCard
.
toUpperCase
().
toCharArray
();
// 统一转为大写
int
sum
=
0
;
for
(
int
i
=
0
;
i
<
17
;
i
++)
{
// 前17位必须为数字(正则已保证,此处可简化)
int
num
=
idChars
[
i
]
-
'0'
;
sum
+=
num
*
WEIGHTS
[
i
];
}
// 计算校验码
int
checkCodeIndex
=
sum
%
11
;
char
calculatedCheckCode
=
CHECK_CODES
[
checkCodeIndex
];
// 对比最后一位校验码
return
idChars
[
17
]
==
calculatedCheckCode
;
return
true
;
// // 2. 校验校验码
// char[] idChars = idCard.toUpperCase().toCharArray(); // 统一转为大写
// int sum = 0;
// for (int i = 0; i < 17; i++) {
// // 前17位必须为数字(正则已保证,此处可简化)
// int num = idChars[i] - '0';
// sum += num * WEIGHTS[i];
// }
// // 计算校验码
// int checkCodeIndex = sum % 11;
// char calculatedCheckCode = CHECK_CODES[checkCodeIndex];
// // 对比最后一位校验码
// return idChars[17] == calculatedCheckCode;
}
/**
...
...
@@ -77,6 +78,7 @@ public class IDValidator {
public
static
void
main
(
String
[]
args
)
{
// 测试案例
String
[]
testCases
=
{
"42019880101XXXX"
,
"110101199001011234"
,
// 合法格式+正确校验码
"11010119900101123X"
,
// 合法格式+正确校验码(X)
"110101199001011235"
,
// 合法格式+错误校验码
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment