Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
1386ff55
Commit
1386ff55
authored
Dec 25, 2019
by
王昆
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gsb
parent
83805b92
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
8 deletions
+40
-8
bpo-web/app/base/utils/idcardClient.js
+40
-8
No files found.
bpo-web/app/base/utils/idcardClient.js
View file @
1386ff55
const
system
=
require
(
"../system"
);
const
system
=
require
(
"../system"
);
const
uuidv4
=
require
(
'uuid/v4'
);
const
uuidv4
=
require
(
'uuid/v4'
);
class
IdcardClient
{
class
IdcardClient
{
constructor
()
{
constructor
()
{
// 加权因子
// 加权因子
this
.
weight_factor
=
[
7
,
9
,
10
,
5
,
8
,
4
,
2
,
1
,
6
,
3
,
7
,
9
,
10
,
5
,
8
,
4
,
2
];
this
.
weight_factor
=
[
7
,
9
,
10
,
5
,
8
,
4
,
2
,
1
,
6
,
3
,
7
,
9
,
10
,
5
,
8
,
4
,
2
];
// 校验码
// 校验码
this
.
check_code
=
[
'1'
,
'0'
,
'X'
,
'9'
,
'8'
,
'7'
,
'6'
,
'5'
,
'4'
,
'3'
,
'2'
];
this
.
check_code
=
[
'1'
,
'0'
,
'X'
,
'9'
,
'8'
,
'7'
,
'6'
,
'5'
,
'4'
,
'3'
,
'2'
];
}
}
async
checkIDCard
(
idcard
)
{
async
checkIDCard
(
idcard
)
{
if
(
!
idcard
)
{
if
(
!
idcard
)
{
return
false
;
return
false
;
}
}
var
code
=
idcard
.
toString
().
toUpperCase
();
var
code
=
idcard
.
toString
().
toUpperCase
();
var
last
=
idcard
[
17
];
//最后一个
var
last
=
idcard
[
17
];
//最后一个
var
seventeen
=
code
.
substring
(
0
,
17
);
var
seventeen
=
code
.
substring
(
0
,
17
);
// ISO 7064:1983.MOD 11-2
// ISO 7064:1983.MOD 11-2
// 判断最后一位校验码是否正确
// 判断最后一位校验码是否正确
var
arr
=
seventeen
.
split
(
""
);
var
arr
=
seventeen
.
split
(
""
);
var
len
=
arr
.
length
;
var
len
=
arr
.
length
;
var
num
=
0
;
var
num
=
0
;
for
(
var
i
=
0
;
i
<
len
;
i
++
)
{
for
(
var
i
=
0
;
i
<
len
;
i
++
)
{
num
=
num
+
arr
[
i
]
*
this
.
weight_factor
[
i
];
num
=
num
+
arr
[
i
]
*
this
.
weight_factor
[
i
];
}
}
// 获取余数
// 获取余数
var
resisue
=
num
%
11
;
var
resisue
=
num
%
11
;
var
last_no
=
this
.
check_code
[
resisue
];
var
last_no
=
this
.
check_code
[
resisue
];
// 格式的正则
// 格式的正则
...
@@ -51,13 +51,44 @@ class IdcardClient {
...
@@ -51,13 +51,44 @@ class IdcardClient {
return
last
===
last_no
&&
format
?
true
:
false
;
return
last
===
last_no
&&
format
?
true
:
false
;
}
}
/**
*
* @param card
* @returns {
* birth 生日
* sex 性别
*
* }
*/
async
cardInfo
(
card
)
{
let
info
=
{};
//获取出生日期
info
.
birth
=
card
.
substring
(
6
,
10
)
+
"-"
+
card
.
substring
(
10
,
12
)
+
"-"
+
card
.
substring
(
12
,
14
);
//获取性别
if
(
parseInt
(
card
.
substr
(
16
,
1
))
%
2
==
1
)
{
info
.
sex
=
"male"
;
}
else
{
info
.
sex
=
"female"
;
}
//获取年龄
let
myDate
=
new
Date
();
let
month
=
myDate
.
getMonth
()
+
1
;
let
day
=
myDate
.
getDate
();
let
age
=
Number
(
myDate
.
getFullYear
())
-
Number
(
card
.
substring
(
6
,
10
))
-
1
;
if
(
card
.
substring
(
10
,
12
)
<
month
||
card
.
substring
(
10
,
12
)
==
month
&&
card
.
substring
(
12
,
14
)
<=
day
)
{
age
++
;
}
info
.
age
=
Number
(
age
);
return
info
;
}
}
}
module
.
exports
=
IdcardClient
;
module
.
exports
=
IdcardClient
;
// 函数参数必须是字符串,因为二代身份证号码是十八位,而在javascript中,十八位的数值会超出计算范围,造成不精确的结果,导致最后两位和计算的值不一致,从而该函数出现错误。
// 函数参数必须是字符串,因为二代身份证号码是十八位,而在javascript中,十八位的数值会超出计算范围,造成不精确的结果,导致最后两位和计算的值不一致,从而该函数出现错误。
// 详情查看javascript的数值范围
// 详情查看javascript的数值范围
function
checkIDCard
(
idcode
){
function
checkIDCard
(
idcode
)
{
}
}
\ No newline at end of file
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