Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
86d49974
Commit
86d49974
authored
Jan 23, 2024
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
身份证识别
parent
e6c23a21
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
3 deletions
+38
-3
SfzhUtil.java
...e/src/main/java/com/yanzuoguang/util/helper/SfzhUtil.java
+6
-2
TestSfzUtil.java
yzg-util-base/src/test/java/helper/TestSfzUtil.java
+32
-1
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/SfzhUtil.java
View file @
86d49974
...
@@ -15,7 +15,7 @@ import static com.yanzuoguang.util.sfz.SfzHandleUtil.*;
...
@@ -15,7 +15,7 @@ import static com.yanzuoguang.util.sfz.SfzHandleUtil.*;
*/
*/
public
class
SfzhUtil
{
public
class
SfzhUtil
{
public
static
final
SfzService
SERVICE
=
new
SfzService
(
SFZ_HANDLE_18
,
SFZ_HANDLE_EN2017
,
SFZ_HANDLE_EN2023
);
public
static
final
SfzService
SERVICE
=
new
SfzService
(
SFZ_HANDLE_18
);
/**
/**
* 将15位身份证号码转换为18位
* 将15位身份证号码转换为18位
...
@@ -175,7 +175,11 @@ public class SfzhUtil {
...
@@ -175,7 +175,11 @@ public class SfzhUtil {
private
static
Short
getBirthdayShortByIdCard
(
String
idCard
,
int
beginIndex
,
int
endIndex
)
{
private
static
Short
getBirthdayShortByIdCard
(
String
idCard
,
int
beginIndex
,
int
endIndex
)
{
SfzInfo
info
=
SERVICE
.
getInfo
(
idCard
);
SfzInfo
info
=
SERVICE
.
getInfo
(
idCard
);
return
Short
.
parseShort
(
SERVICE
.
getBirthday
(
info
).
substring
(
beginIndex
,
endIndex
));
String
birthday
=
SERVICE
.
getBirthday
(
info
);
if
(
StringHelper
.
isEmpty
(
birthday
)
||
birthday
.
length
()
<
endIndex
)
{
return
0
;
}
return
Short
.
parseShort
(
birthday
.
substring
(
beginIndex
,
endIndex
));
}
}
/**
/**
...
...
yzg-util-base/src/test/java/helper/TestSfzUtil.java
View file @
86d49974
...
@@ -11,6 +11,9 @@ import org.junit.Test;
...
@@ -11,6 +11,9 @@ import org.junit.Test;
import
java.io.File
;
import
java.io.File
;
import
java.util.List
;
import
java.util.List
;
import
static
com
.
yanzuoguang
.
util
.
sfz
.
SfzHandleUtil
.
SFZ_HANDLE_15
;
import
static
com
.
yanzuoguang
.
util
.
sfz
.
SfzHandleUtil
.
SFZ_HANDLE_18
;
public
class
TestSfzUtil
{
public
class
TestSfzUtil
{
public
ResponseDataMainResult
<
List
<
DemoVo
>,
DemoVo
>
getReturnType
()
{
public
ResponseDataMainResult
<
List
<
DemoVo
>,
DemoVo
>
getReturnType
()
{
...
@@ -53,17 +56,45 @@ public class TestSfzUtil {
...
@@ -53,17 +56,45 @@ public class TestSfzUtil {
validateIdCard18
(
"44142419920313185X"
);
validateIdCard18
(
"44142419920313185X"
);
}
}
@Test
@Test
public
void
testId
()
throws
NoSuchMethodException
{
public
void
testId18
()
throws
NoSuchMethodException
{
// 获取泛型的返回值类型
String
file
=
getFile
(
"合法身份证.csv"
);
String
s
=
FileHelper
.
readFile
(
new
File
(
file
),
"utf-8"
);
SfzhUtil
.
SERVICE
.
getHandleList
().
remove
(
SFZ_HANDLE_15
);
String
[]
lines
=
s
.
split
(
"\\n"
);
for
(
String
line
:
lines
)
{
if
(!
SfzhUtil
.
validateCard
(
line
))
{
System
.
err
.
println
(
line
);
}
}
}
@Test
public
void
testId18AND15
()
throws
NoSuchMethodException
{
// 获取泛型的返回值类型
// 获取泛型的返回值类型
String
file
=
getFile
(
"合法身份证.csv"
);
String
file
=
getFile
(
"合法身份证.csv"
);
String
s
=
FileHelper
.
readFile
(
new
File
(
file
),
"utf-8"
);
String
s
=
FileHelper
.
readFile
(
new
File
(
file
),
"utf-8"
);
String
[]
lines
=
s
.
split
(
"\\n"
);
String
[]
lines
=
s
.
split
(
"\\n"
);
// 在程序启动时,将15位当成合法身份证
SfzhUtil
.
SERVICE
.
getHandleList
().
add
(
SFZ_HANDLE_15
);
for
(
String
line
:
lines
)
{
for
(
String
line
:
lines
)
{
if
(!
SfzhUtil
.
validateCard
(
line
))
{
if
(!
SfzhUtil
.
validateCard
(
line
))
{
System
.
err
.
println
(
line
);
System
.
err
.
println
(
line
);
}
}
}
}
}
}
@Test
public
void
testId18AND15GetAge
()
throws
NoSuchMethodException
{
// 获取泛型的返回值类型
String
file
=
getFile
(
"合法身份证.csv"
);
String
s
=
FileHelper
.
readFile
(
new
File
(
file
),
"utf-8"
);
String
[]
lines
=
s
.
split
(
"\\n"
);
// 在程序启动时,将15位当成合法身份证
SfzhUtil
.
SERVICE
.
getHandleList
().
add
(
SFZ_HANDLE_15
);
for
(
String
line
:
lines
)
{
int
ageByIdCard
=
SfzhUtil
.
getAgeByIdCard
(
line
);
System
.
err
.
println
(
ageByIdCard
);
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment