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
029d33d3
Commit
029d33d3
authored
Apr 30, 2020
by
zhaoxiqing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gsb
parent
8c3b0aa3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
51 deletions
+74
-51
bpo-web/app/base/api/impl/econtractApi.js
+0
-1
bpo-web/app/base/api/impl/testApi.js
+0
-12
bpo-web/app/base/utils/idcardClient.js
+74
-38
No files found.
bpo-web/app/base/api/impl/econtractApi.js
View file @
029d33d3
...
@@ -907,7 +907,6 @@ class EcontractApi {
...
@@ -907,7 +907,6 @@ class EcontractApi {
if
(
!
param
.
idNo
)
{
if
(
!
param
.
idNo
)
{
return
this
.
returnjson
(
-
1
,
"请提供该用户身份证号"
)
return
this
.
returnjson
(
-
1
,
"请提供该用户身份证号"
)
}
}
console
.
log
(
await
this
.
idcardClient
.
validateIdCard
(
param
.
idNo
));
if
(
!
await
this
.
idcardClient
.
checkIDCard
(
param
.
idNo
))
{
if
(
!
await
this
.
idcardClient
.
checkIDCard
(
param
.
idNo
))
{
return
this
.
returnjson
(
-
1
,
"身份证格式不正确"
);
return
this
.
returnjson
(
-
1
,
"身份证格式不正确"
);
}
}
...
...
bpo-web/app/base/api/impl/testApi.js
View file @
029d33d3
...
@@ -88,18 +88,6 @@ class TestApi {
...
@@ -88,18 +88,6 @@ class TestApi {
}
}
}
}
async
sssss
(
obj
){
if
(
obj
.
ss
in
{
"12"
:
""
,
"13"
:
""
})
{
console
.
log
(
"ok"
)
}
else
{
console
.
log
(
"no"
)
}
}
}
}
module
.
exports
=
TestApi
;
module
.
exports
=
TestApi
;
bpo-web/app/base/utils/idcardClient.js
View file @
029d33d3
...
@@ -9,46 +9,82 @@ class IdcardClient {
...
@@ -9,46 +9,82 @@ class IdcardClient {
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;
// }
// idcard = idcard.toUpperCase();
// var code = idcard.toString().toUpperCase();
// var last = idcard[17];//最后一个
//
// var seventeen = code.substring(0, 17);
//
// // ISO 7064:1983.MOD 11-2
// // 判断最后一位校验码是否正确
// var arr = seventeen.split("");
// var len = arr.length;
// var num = 0;
// for (var i = 0; i < len; i++) {
// num = num + arr[i] * this.weight_factor[i];
// }
//
// // 获取余数
// var resisue = num % 11;
// var last_no = this.check_code[resisue];
//
// // 格式的正则
// // 正则思路
// /*
// 第一位不可能是0
// 第二位到第六位可以是0-9
// 第七位到第十位是年份,所以七八位为19或者20
// 十一位和十二位是月份,这两位是01-12之间的数值
// 十三位和十四位是日期,是从01-31之间的数值
// 十五,十六,十七都是数字0-9
// 十八位可能是数字0-9,也可能是X
// */
// var idcard_patter = /^[1-9][0-9]{5}([1][9][0-9]{2}|[2][0][0|1][0-9])([0][1-9]|[1][0|1|2])([0][1-9]|[1|2][0-9]|[3][0|1])[0-9]{3}([0-9]|[X])$/;
//
// // 判断格式是否正确
// var format = idcard_patter.test(idcard);
//
// // 返回验证结果,校验码和格式同时正确才算是合法的身份证号码
// return last === last_no && format ? true : false;
// }
async
checkIDCard
(
idCard
)
{
//15位和18位身份证号码的正则表达式
var
regIdCard
=
/^
(
^
[
1-9
]\d{7}((
0
\d)
|
(
1
[
0-2
]))(([
0|1|2
]\d)
|3
[
0-1
])\d{3}
$
)
|
(
^
[
1-9
]\d{5}[
1-9
]\d{3}((
0
\d)
|
(
1
[
0-2
]))(([
0|1|2
]\d)
|3
[
0-1
])((\d{4})
|
\d{3}[
Xx
])
$
)
$/
;
//如果通过该验证,说明身份证格式正确,但准确性还需计算
if
(
regIdCard
.
test
(
idCard
))
{
if
(
idCard
.
length
==
18
)
{
var
idCardWi
=
new
Array
(
7
,
9
,
10
,
5
,
8
,
4
,
2
,
1
,
6
,
3
,
7
,
9
,
10
,
5
,
8
,
4
,
2
);
//将前17位加权因子保存在数组里
var
idCardY
=
new
Array
(
1
,
0
,
10
,
9
,
8
,
7
,
6
,
5
,
4
,
3
,
2
);
//这是除以11后,可能产生的11位余数、验证码,也保存成数组
var
idCardWiSum
=
0
;
//用来保存前17位各自乖以加权因子后的总和
for
(
var
i
=
0
;
i
<
17
;
i
++
)
{
idCardWiSum
+=
idCard
.
substring
(
i
,
i
+
1
)
*
idCardWi
[
i
];
}
var
idCardMod
=
idCardWiSum
%
11
;
//计算出校验码所在数组的位置
var
idCardLast
=
idCard
.
substring
(
17
);
//得到最后一位身份证号码
//如果等于2,则说明校验码是10,身份证号码最后一位应该是X
if
(
idCardMod
==
2
)
{
if
(
idCardLast
==
"X"
||
idCardLast
==
"x"
)
{
return
true
;
}
else
{
return
false
;
}
}
else
{
//用计算出的验证码与最后一位身份证号码匹配,如果一致,说明通过,否则是无效的身份证号码
if
(
idCardLast
==
idCardY
[
idCardMod
])
{
return
true
;
}
else
{
return
false
;
}
}
}
}
else
{
return
false
;
return
false
;
}
}
var
code
=
idcard
.
toString
().
toUpperCase
();
var
last
=
idcard
[
17
];
//最后一个
var
seventeen
=
code
.
substring
(
0
,
17
);
// ISO 7064:1983.MOD 11-2
// 判断最后一位校验码是否正确
var
arr
=
seventeen
.
split
(
""
);
var
len
=
arr
.
length
;
var
num
=
0
;
for
(
var
i
=
0
;
i
<
len
;
i
++
)
{
num
=
num
+
arr
[
i
]
*
this
.
weight_factor
[
i
];
}
// 获取余数
var
resisue
=
num
%
11
;
var
last_no
=
this
.
check_code
[
resisue
];
// 格式的正则
// 正则思路
/*
第一位不可能是0
第二位到第六位可以是0-9
第七位到第十位是年份,所以七八位为19或者20
十一位和十二位是月份,这两位是01-12之间的数值
十三位和十四位是日期,是从01-31之间的数值
十五,十六,十七都是数字0-9
十八位可能是数字0-9,也可能是X
*/
var
idcard_patter
=
/^
[
1-9
][
0-9
]{5}([
1
][
9
][
0-9
]{2}
|
[
2
][
0
][
0|1
][
0-9
])([
0
][
1-9
]
|
[
1
][
0|1|2
])([
0
][
1-9
]
|
[
1|2
][
0-9
]
|
[
3
][
0|1
])[
0-9
]{3}([
0-9
]
|
[
X
])
$/
;
// 判断格式是否正确
var
format
=
idcard_patter
.
test
(
idcard
);
// 返回验证结果,校验码和格式同时正确才算是合法的身份证号码
return
last
===
last_no
&&
format
?
true
:
false
;
}
}
/**
/**
...
...
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