Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
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
youjj
cloud-platform
Commits
8910eab1
Commit
8910eab1
authored
Nov 04, 2019
by
hanfeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改实名认证
parent
2ef211bf
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
337 additions
and
287 deletions
+337
-287
IDCardInformation.java
...com/xxfc/platform/universal/entity/IDCardInformation.java
+58
-0
CertificationService.java
...xxfc/platform/universal/service/CertificationService.java
+65
-259
UserPictureParsing.java
.../universal/service/PictureParsing/UserPictureParsing.java
+10
-0
XCFQPictureParsingImpl.java
...l/service/PictureParsing/impl/XCFQPictureParsingImpl.java
+155
-0
XCFQAuthentication.java
...vice/authenticationInterface/impl/XCFQAuthentication.java
+49
-28
No files found.
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/entity/IDCardInformation.java
0 → 100644
View file @
8910eab1
package
com
.
xxfc
.
platform
.
universal
.
entity
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
/**
* 解析出的身份证信息
* @author Administrator
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public
class
IDCardInformation
{
/**
* 住址
*/
private
String
address
;
/**
* 出生年月日(yyyyMMdd格式)
*/
private
String
birthday
;
/**
* 姓名
*/
private
String
name
;
/**
* 证件号
*/
private
String
code
;
/**
* 性别
*/
private
String
sex
;
/**
* 民族
*/
private
String
nation
;
/**
* 证件签发机构
*/
private
String
issue
;
/**
* 签发时间
*/
private
String
issueDate
;
/**
*失效时间
*/
private
String
expiryDate
;
}
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/service/CertificationService.java
View file @
8910eab1
This diff is collapsed.
Click to expand it.
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/service/PictureParsing/UserPictureParsing.java
0 → 100644
View file @
8910eab1
package
com
.
xxfc
.
platform
.
universal
.
service
.
PictureParsing
;
import
com.xxfc.platform.universal.entity.IDCardInformation
;
/**
* @author Administrator
*/
public
interface
UserPictureParsing
{
IDCardInformation
analysis
(
String
front
,
String
back
);
}
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/service/PictureParsing/impl/XCFQPictureParsingImpl.java
0 → 100644
View file @
8910eab1
package
com
.
xxfc
.
platform
.
universal
.
service
.
PictureParsing
.
impl
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.map.MapUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.github.wxiaoqi.security.common.exception.BaseException
;
import
com.xxfc.platform.universal.entity.IDCardInformation
;
import
com.xxfc.platform.universal.service.PictureParsing.UserPictureParsing
;
import
com.xxfc.platform.universal.utils.CertifHttpUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.MapUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.StatusLine
;
import
org.apache.http.util.EntityUtils
;
import
org.springframework.stereotype.Service
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 调用四川涪擎图片解析接口
*
* @author Administrator
*/
@Service
@Slf4j
public
class
XCFQPictureParsingImpl
implements
UserPictureParsing
{
private
String
appcode
=
"acea1c8811f748b3a65815f11db357c4"
;
private
String
appcode2
=
"ee7710ce92054cae9f6c040f6864e6a7"
;
/**
* 认证相关的数据
*/
private
String
host
=
"https://ocridcard.market.alicloudapi.com"
;
private
String
path
=
"/idcard"
;
private
String
methd
=
"POST"
;
private
String
imageRet
=
"code"
;
private
String
resultCode
=
"1"
;
private
String
dataNam
=
"result"
;
/**
* 照片解析
*
* @param frontImage 正面照片
* @param backImage 反面照片
* @return
*/
@Override
public
IDCardInformation
analysis
(
String
frontImage
,
String
backImage
)
{
Map
<
String
,
String
>
front
=
judgeAccordingToAnalyticalData
(
frontImage
,
"front"
);
if
(
MapUtils
.
isEmpty
(
front
))
{
log
.
error
(
"正面解析失败,请重新上传"
);
throw
new
BaseException
(
"正面解析失败,请重新上传"
);
}
Map
<
String
,
String
>
back
=
judgeAccordingToAnalyticalData
(
backImage
,
"back"
);
if
(
MapUtils
.
isEmpty
(
back
))
{
log
.
error
(
"反面解析失败,请重新上传"
);
throw
new
BaseException
(
"反面解析失败,请重新上传"
);
}
return
new
IDCardInformation
(
front
.
get
(
"address"
),
front
.
get
(
"birthday"
),
front
.
get
(
"name"
),
front
.
get
(
"code"
),
front
.
get
(
"sex"
),
front
.
get
(
"nation"
),
back
.
get
(
"issue"
),
back
.
get
(
"issueDate"
),
back
.
get
(
"expiryDate"
));
}
private
Map
<
String
,
String
>
judgeAccordingToAnalyticalData
(
String
imageUrl
,
String
type
)
{
String
json
=
imageParse
(
imageUrl
,
type
);
log
.
info
(
"json:"
+
json
);
if
(
StringUtils
.
isBlank
(
json
))
{
return
null
;
}
Map
reuslt
=
(
Map
)
JSONObject
.
parse
(
json
);
//判断是否调用图片解析的接口是否异常,若果两个次认证都没结果
if
(
MapUtil
.
isEmpty
(
reuslt
)
||
!(
reuslt
.
get
(
imageRet
).
equals
(
resultCode
))
)
{
return
null
;
}
Map
<
String
,
String
>
map
=
(
Map
)
reuslt
.
get
(
dataNam
);
log
.
info
(
"map:"
+
map
);
if
(
MapUtils
.
isNotEmpty
(
map
))
{
return
map
;
}
return
null
;
}
//身份证照片解析
private
String
imageParse
(
String
imageUrl
,
String
type
)
{
Map
<
String
,
String
>
headers
=
new
HashMap
<
String
,
String
>();
headers
.
put
(
"Authorization"
,
"APPCODE "
+
appcode2
);
Map
<
String
,
String
>
querys
=
new
HashMap
<
String
,
String
>();
Map
<
String
,
String
>
bodys
=
new
HashMap
<
String
,
String
>();
bodys
.
put
(
"image"
,
imageUrl
);
//默认正面front,背面请传back
bodys
.
put
(
"idCardSide"
,
type
);
try
{
return
callExternalRequest
(
headers
,
querys
,
bodys
,
1
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
private
String
callExternalRequest
(
Map
<
String
,
String
>
headers
,
Map
<
String
,
String
>
querys
,
Map
<
String
,
String
>
bodys
,
int
type
)
throws
Exception
{
HttpResponse
response
=
CertifHttpUtils
.
doPost
(
host
,
path
,
methd
,
headers
,
querys
,
bodys
);
log
.
info
(
"response:"
+
response
);
StatusLine
statusLine
=
response
.
getStatusLine
();
int
statusCode
=
statusLine
.
getStatusCode
();
/**
* 状态码: 200 正常;400 URL无效;401 appCode错误; 403 次数用完; 500 API网管错误
*/
log
.
info
(
"外部接口响应状态码:"
+
statusCode
);
//获取response的body
if
(
statusCode
==
200
)
{
return
EntityUtils
.
toString
(
response
.
getEntity
());
}
if
(
403
==
statusCode
){
if
(
type
==
2
){
log
.
error
(
"验证次数已用完"
);
return
null
;
}
Map
<
String
,
String
>
headers2
=
new
HashMap
<
String
,
String
>();
headers
.
put
(
"Authorization"
,
"APPCODE "
+
appcode
);
return
callExternalRequest
(
headers2
,
querys
,
bodys
,
2
);
}
return
null
;
}
}
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/service/authenticationInterface/impl/XCFQAuthentication.java
View file @
8910eab1
...
@@ -28,16 +28,18 @@ import java.util.Map;
...
@@ -28,16 +28,18 @@ import java.util.Map;
@Primary
@Primary
public
class
XCFQAuthentication
implements
UserAuthentication
{
public
class
XCFQAuthentication
implements
UserAuthentication
{
private
String
cAppcode
=
"acea1c8811f748b3a65815f11db357c4"
;
private
String
appcode
=
"acea1c8811f748b3a65815f11db357c4"
;
private
String
appcode2
=
"ee7710ce92054cae9f6c040f6864e6a7"
;
/**
/**
* 认证相关的数据
* 认证相关的数据
*/
*/
private
String
cHos
t
=
"https://idcert.market.alicloudapi.com"
;
private
String
hso
t
=
"https://idcert.market.alicloudapi.com"
;
private
String
cP
ath
=
"/idcard"
;
private
String
p
ath
=
"/idcard"
;
private
String
cMetho
d
=
"GET"
;
private
String
meth
d
=
"GET"
;
//响应:认证错误码字段名
//响应:认证错误码字段名
private
String
certifRet
=
"status"
;
private
String
certifRet
=
"status"
;
...
@@ -53,37 +55,56 @@ public class XCFQAuthentication implements UserAuthentication {
...
@@ -53,37 +55,56 @@ public class XCFQAuthentication implements UserAuthentication {
@Override
@Override
public
boolean
certificate
(
UserMessage
message
)
{
public
boolean
certificate
(
UserMessage
message
)
{
Map
<
String
,
String
>
headers
=
new
HashMap
<
String
,
String
>();
headers
.
put
(
"Authorization"
,
"APPCODE "
+
appcode2
);
try
{
callExternalRequest
(
message
,
headers
,
1
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
false
;
}
private
boolean
callExternalRequest
(
UserMessage
message
,
Map
<
String
,
String
>
headers
,
int
type
)
throws
Exception
{
//map携带身份证和姓名进行认证
//map携带身份证和姓名进行认证
Map
<
String
,
String
>
querys
=
new
HashMap
<>();
Map
<
String
,
String
>
querys
=
new
HashMap
<>();
querys
.
put
(
idCardName
,
message
.
getIdNumber
());
querys
.
put
(
idCardName
,
message
.
getIdNumber
());
querys
.
put
(
cName
,
message
.
getName
());
querys
.
put
(
cName
,
message
.
getName
());
Map
<
String
,
String
>
headers
=
new
HashMap
<
String
,
String
>();
log
.
info
(
"----querys========="
+
querys
);
headers
.
put
(
"Authorization"
,
"APPCODE "
+
cAppcode
);
HttpResponse
response
=
HttpUtils
.
doGet
(
hsot
,
path
,
methd
,
headers
,
querys
);
try
{
StatusLine
statusLine
=
response
.
getStatusLine
();
log
.
info
(
"----querys========="
+
querys
);
int
statusCode
=
statusLine
.
getStatusCode
();
HttpResponse
response
=
HttpUtils
.
doGet
(
cHost
,
cPath
,
cMethod
,
headers
,
querys
);
/**
StatusLine
statusLine
=
response
.
getStatusLine
();
* 状态码: 200 正常;400 URL无效;401 appCode错误; 403 次数用完; 500 API网管错误
int
statusCode
=
statusLine
.
getStatusCode
();
*/
/**
log
.
info
(
"外部接口响应状态码:"
+
statusCode
);
* 状态码: 200 正常;400 URL无效;401 appCode错误; 403 次数用完; 500 API网管错误
//获取response的body
*/
log
.
info
(
"外部接口响应状态码:"
+
statusCode
);
if
(
statusCode
==
200
)
{
//获取response的body
String
result
=
EntityUtils
.
toString
(
response
.
getEntity
());
if
(
statusCode
==
200
)
{
log
.
info
(
"----认证结果result========="
+
result
);
String
result
=
EntityUtils
.
toString
(
response
.
getEntity
());
//认证返回的参数是否为空
log
.
info
(
"----认证结果result========="
+
result
);
if
(!
StringUtils
.
isBlank
(
result
))
{
//认证返回的参数是否为空
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
JSONObject
.
parse
(
result
);
if
(!
StringUtils
.
isBlank
(
result
))
{
log
.
info
(
"----响应数据========="
+
map
);
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
JSONObject
.
parse
(
result
);
if
(
MapUtil
.
isNotEmpty
(
map
)
||
certifResultCode
.
equals
(
map
.
get
(
certifRet
)))
{
log
.
info
(
"----certifRet========="
+
certifRet
);
return
true
;
if
(
MapUtil
.
isNotEmpty
(
map
)
||
certifResultCode
.
equals
(
map
.
get
(
certifRet
)))
{
return
true
;
}
}
}
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
if
(
403
==
statusCode
){
if
(
type
==
2
){
log
.
error
(
"验证次数已用完"
);
return
false
;
}
Map
<
String
,
String
>
headers2
=
new
HashMap
<
String
,
String
>();
headers
.
put
(
"Authorization"
,
"APPCODE "
+
appcode
);
return
callExternalRequest
(
message
,
headers2
,
2
);
}
return
false
;
return
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