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
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
...
@@ -4,12 +4,15 @@ package com.xxfc.platform.universal.service;
...
@@ -4,12 +4,15 @@ package com.xxfc.platform.universal.service;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.core.map.MapUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.github.wxiaoqi.security.admin.feign.UserFeign
;
import
com.github.wxiaoqi.security.admin.feign.UserFeign
;
import
com.github.wxiaoqi.security.common.constant.RestCode
;
import
com.github.wxiaoqi.security.common.exception.BaseException
;
import
com.github.wxiaoqi.security.common.exception.BaseException
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.github.wxiaoqi.security.common.util.process.ResultCode
;
import
com.github.wxiaoqi.security.common.util.process.ResultCode
;
import
com.xxfc.platform.universal.biz.UserMessage
;
import
com.xxfc.platform.universal.biz.UserMessage
;
import
com.xxfc.platform.universal.entity.IDCardInformation
;
import
com.xxfc.platform.universal.entity.IdInformation
;
import
com.xxfc.platform.universal.entity.IdInformation
;
import
com.xxfc.platform.universal.mapper.IdInformationMapper
;
import
com.xxfc.platform.universal.mapper.IdInformationMapper
;
import
com.xxfc.platform.universal.service.PictureParsing.UserPictureParsing
;
import
com.xxfc.platform.universal.service.authenticationInterface.UserAuthentication
;
import
com.xxfc.platform.universal.service.authenticationInterface.UserAuthentication
;
import
com.xxfc.platform.universal.utils.CertifHttpUtils
;
import
com.xxfc.platform.universal.utils.CertifHttpUtils
;
import
com.xxfc.platform.universal.utils.Validation
;
import
com.xxfc.platform.universal.utils.Validation
;
...
@@ -36,107 +39,14 @@ import java.util.*;
...
@@ -36,107 +39,14 @@ import java.util.*;
/**
/**
* 认证业务
* 认证业务
*
* @author Administrator
* @author Administrator
*/
*/
@Service
@Service
@Slf4j
@Slf4j
public
class
CertificationService
{
public
class
CertificationService
{
@Autowired
@Autowired
private
UserAuthentication
authentication
;
private
UserAuthentication
authentication
;
/**
* 认证相关的数据
*/
@Value
(
"${certif.cHost}"
)
private
String
cHost
;
@Value
(
"${certif.cPath}"
)
private
String
cPath
;
@Value
(
"${certif.cMethod}"
)
private
String
cMethod
;
@Value
(
"${certif.cAppcode}"
)
private
String
cAppcode
;
//请求:身份证号字段名
@Value
(
"${certif.idCardName}"
)
private
String
idCardName
;
//请求:用户姓名字段名
@Value
(
"${certif.cName}"
)
private
String
cName
;
//响应:认证错误码字段名
@Value
(
"${certif.certifRet}"
)
private
String
certifRet
;
//响应:认证通过码
@Value
(
"${certif.certifResultCode}"
)
private
String
certifResultCode
;
/**
* 图片解析相关的数据
*/
//认证借口host
@Value
(
"${certif.iHost}"
)
private
String
iHost
;
//认证接口path
@Value
(
"${certif.iPath}"
)
private
String
iPath
;
//请求方式
@Value
(
"${certif.iMethod}"
)
private
String
iMethod
;
//认证AppCode(接口商家提供)
@Value
(
"${certif.iAppcode}"
)
private
String
iAppcode
;
//请求:图片url字段名
@Value
(
"${certif.picName}"
)
private
String
picName
;
//请求:方向字段名
@Value
(
"${certif.typeName}"
)
private
String
typeName
;
//请求:反面图片标识
@Value
(
"${certif.frontParameter}"
)
private
String
frontParameter
;
//请求:反面图片标识
@Value
(
"${certif.backParameter}"
)
private
String
backParameter
;
//响应:解析错误码字段名
@Value
(
"${certif.imageRet}"
)
private
String
imageRet
;
//响应:图片解析错误码
@Value
(
"${certif.imageResultCode}"
)
private
String
imageResultCode
;
//响应:响应内容字段名
@Value
(
"${certif.dataNam}"
)
private
String
dataNam
;
//响应:正面身份证号字段名
@Value
(
"${certif.numberName}"
)
private
String
numberName
;
//响应:正面姓名字段名
@Value
(
"${certif.iName}"
)
private
String
iName
;
//响应:背面到期时间字段名
@Value
(
"${certif.expirationDateName}"
)
private
String
expirationDateName
;
@Autowired
@Autowired
private
IdInformationMapper
idInformationMapper
;
private
IdInformationMapper
idInformationMapper
;
...
@@ -148,14 +58,16 @@ public class CertificationService {
...
@@ -148,14 +58,16 @@ public class CertificationService {
@Autowired
@Autowired
private
ApplicationContext
applicationContext
;
private
ApplicationContext
applicationContext
;
@Autowired
private
UserPictureParsing
userPictureParsing
;
// 身份证图片进行实名认证
/**
* 一、身份证图片进行实名认证
public
ObjectRestResponse
<
Integer
>
certificate
(
IdInformation
idInformation
)
{
* @param idInformation
//1.判断
* @return
//携带返回参数的map
*/
HashedMap
hashMap
=
new
HashedMap
();
public
ObjectRestResponse
<
Integer
>
certificate
(
IdInformation
idInformation
)
{
//
认证状态:true是认证过
//
1.认证前数据判断
//判断是否bean是否为null
//判断是否bean是否为null
if
(
idInformation
==
null
)
{
if
(
idInformation
==
null
)
{
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
INCOMPLETE_DATA
,
"无法识别,请重新上传"
);
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
INCOMPLETE_DATA
,
"无法识别,请重新上传"
);
...
@@ -181,170 +93,69 @@ public class CertificationService {
...
@@ -181,170 +93,69 @@ public class CertificationService {
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
INCOMPLETE_DATA
,
"请上传背面照"
);
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
INCOMPLETE_DATA
,
"请上传背面照"
);
}
}
//2.解析
//2.解析
//正面进行解析
IDCardInformation
credentialsData
=
userPictureParsing
.
analysis
(
idInformation
.
getFrontUrl
(),
idInformation
.
getBackUrl
());
String
front
=
imageParse
(
idInformation
.
getFrontUrl
(),
frontParameter
);
//验证证件信息是否和填入的客户信息一致
//解析证件背面
String
name
=
credentialsData
.
getName
();
String
back
=
imageParse
(
idInformation
.
getBackUrl
(),
backParameter
);
String
number
=
credentialsData
.
getCode
();
log
.
info
(
"----解析front========="
+
front
);
log
.
info
(
"----解析back========="
+
back
);
if
(
StringUtils
.
isBlank
(
front
)
||
StringUtils
.
isBlank
(
back
))
{
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
INCOMPLETE_DATA
,
"无法识别,请重新上传"
);
}
Map
frontMap
=
(
Map
)
JSONObject
.
parse
(
front
);
//反面进行解析
Map
backMap
=
(
Map
)
JSONObject
.
parse
(
back
);
//判断是否调用图片解析的接口是否异常,若果两个次认证都没结果
if
(
MapUtil
.
isEmpty
(
frontMap
)
||
!(
frontMap
.
get
(
imageRet
).
equals
(
imageResultCode
))
||
MapUtil
.
isEmpty
(
backMap
)
||
!(
backMap
.
get
(
imageRet
).
equals
(
imageResultCode
))
)
{
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
INCOMPLETE_DATA
,
"无法识别,请重新上传"
);
}
Map
frontData
=
(
Map
)
frontMap
.
get
(
dataNam
);
Map
backData
=
(
Map
)
backMap
.
get
(
dataNam
);
if
(
MapUtil
.
isEmpty
(
backData
)
||
MapUtil
.
isEmpty
(
frontData
))
{
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
INCOMPLETE_DATA
,
"无法识别,请重新上传"
);
}
//解析通过,进行匹配
String
name
=
(
String
)
frontData
.
get
(
iName
);
String
number
=
(
String
)
frontData
.
get
(
numberName
);
if
(
idInformation
.
getName
().
equals
(
name
))
{
if
(
idInformation
.
getName
().
equals
(
name
))
{
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
FAILED_CODE
,
"姓名不一致"
);
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
FAILED_CODE
,
"姓名不一致"
);
}
}
if
(
idInformation
.
getIdNumber
().
equals
(
number
))
{
if
(
idInformation
.
getIdNumber
().
equals
(
number
))
{
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
FAILED_CODE
,
"证件号不一致"
);
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
FAILED_CODE
,
"证件号不一致"
);
}
}
//3.验证
//map携带身份证和姓名进行认证
boolean
result
=
authentication
.
certificate
(
new
UserMessage
()
{{
// Map<String, String> authMap = new HashMap<>();
// authMap.put(idCardName, (String) frontData.get(numberName));
// authMap.put(cName, (String) frontData.get(cName));
// //3.调用接口进行认证
//
// boolean result = certificate(authMap);
boolean
result
=
authentication
.
certificate
(
new
UserMessage
(){{
setIdNumber
(
number
);
setIdNumber
(
number
);
setName
(
name
);
setName
(
name
);
}}
);
}});
log
.
info
(
"----认证结果result========="
+
result
);
log
.
info
(
"----认证结果result========="
+
result
);
//认证返回的参数是否为空
//认证返回的参数是否为空
if
(
result
)
{
if
(
result
)
{
//认证成功后存入保存到数据库
//认证成功后存入保存到数据库
//获得身份证正面记录的身份证号和真实姓名
//获得身份证正面记录的身份证号和真实姓名
//设置姓名
//设置姓名
idInformation
.
setName
(
name
);
idInformation
.
setName
((
String
)
frontData
.
get
(
iName
));
//设置身份证号
//设置身份证号
idInformation
.
setIdNumber
(
number
);
idInformation
.
setIdNumber
((
String
)
frontData
.
get
(
numberName
));
//获得到期时间
//获得到期时间
String
endDate
=
credentialsData
.
getExpiryDate
();
String
endDate
=
(
String
)
backData
.
get
(
expirationDateName
);
log
.
info
(
"----获得到期时间endDate========="
+
endDate
);
log
.
info
(
"----获得到期时间endDate========="
+
endDate
);
if
(
StringUtils
.
isBlank
(
endDate
))
{
if
(
StringUtils
.
isBlank
(
endDate
))
{
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
FAILED_CODE
,
"图片识别失败,请重新上传"
);
return
ObjectRestResponse
.
succ
();
}
Date
expirationDate
=
new
Date
();
if
(!
Validation
.
isDate
(
endDate
))
{
Date
date
=
new
Date
();
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
date
);
c
.
add
(
Calendar
.
YEAR
,
100
);
expirationDate
=
c
.
getTime
();
}
else
{
SimpleDateFormat
formatter
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
formatter
.
setLenient
(
false
);
try
{
expirationDate
=
formatter
.
parse
(
endDate
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
INCOMPLETE_DATA
,
"无法识别,请重新上传"
);
}
}
idInformation
.
setExpirationDate
(
expirationDate
);
CertificationService
cs
=
applicationContext
.
getBean
(
this
.
getClass
());
return
cs
.
addIdInformation
(
idInformation
);
// log.info("----请求admin=========" + objRR);
// if (objRR.getRel()) {
// return ObjectRestResponse.succ(objRR.getData());
// }
}
}
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
INCOMPLETE_DATA
,
"网络异常,请稍后再试"
);
Date
expirationDate
=
new
Date
();
if
(!
Validation
.
isDate
(
endDate
))
{
Date
date
=
new
Date
();
}
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
date
);
c
.
add
(
Calendar
.
YEAR
,
100
);
//认证
expirationDate
=
c
.
getTime
();
//认证
}
else
{
public
boolean
certificate
(
Map
<
String
,
String
>
querys
)
{
SimpleDateFormat
formatter
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
Map
<
String
,
String
>
headers
=
new
HashMap
<
String
,
String
>();
formatter
.
setLenient
(
false
);
headers
.
put
(
"Authorization"
,
"APPCODE "
+
cAppcode
);
try
{
try
{
expirationDate
=
formatter
.
parse
(
endDate
);
log
.
info
(
"----querys========="
+
querys
);
}
catch
(
ParseException
e
)
{
HttpResponse
response
=
CertifHttpUtils
.
doGet
(
cHost
,
cPath
,
cMethod
,
headers
,
querys
);
e
.
printStackTrace
();
StatusLine
statusLine
=
response
.
getStatusLine
();
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
INCOMPLETE_DATA
,
"无法识别,请重新上传"
);
int
statusCode
=
statusLine
.
getStatusCode
();
/**
* 状态码: 200 正常;400 URL无效;401 appCode错误; 403 次数用完; 500 API网管错误
*/
//获取response的body
if
(
statusCode
==
200
)
{
String
result
=
EntityUtils
.
toString
(
response
.
getEntity
());
log
.
info
(
"----认证结果result========="
+
result
);
//认证返回的参数是否为空
if
(!
StringUtils
.
isBlank
(
result
))
{
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
JSONObject
.
parse
(
result
);
log
.
info
(
"----certifRet========="
+
certifRet
);
if
(
MapUtil
.
isNotEmpty
(
map
)
||
certifResultCode
.
equals
(
map
.
get
(
certifRet
)))
{
return
true
;
}
}
}
}
}
return
false
;
idInformation
.
setExpirationDate
(
expirationDate
);
}
catch
(
Exception
e
)
{
CertificationService
cs
=
applicationContext
.
getBean
(
this
.
getClass
());
e
.
printStackTrace
();
return
cs
.
addIdInformation
(
idInformation
);
return
false
;
}
}
}
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
INCOMPLETE_DATA
,
"网络异常,请稍后再试"
);
//身份证照片解析
public
String
imageParse
(
String
imageUrl
,
String
type
)
{
Map
<
String
,
String
>
headers
=
new
HashMap
<
String
,
String
>();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
headers
.
put
(
"Authorization"
,
"APPCODE "
+
iAppcode
);
Map
<
String
,
String
>
querys
=
new
HashMap
<
String
,
String
>();
Map
<
String
,
String
>
bodys
=
new
HashMap
<
String
,
String
>();
bodys
.
put
(
picName
,
imageUrl
);
//默认正面front,背面请传back
bodys
.
put
(
typeName
,
type
);
try
{
HttpResponse
response
=
CertifHttpUtils
.
doPost
(
iHost
,
iPath
,
iMethod
,
headers
,
querys
,
bodys
);
StatusLine
statusLine
=
response
.
getStatusLine
();
int
statusCode
=
statusLine
.
getStatusCode
();
log
.
info
(
"----statusCode========="
+
querys
);
/**
* 状态码: 200 正常;400 URL无效;401 appCode错误; 403 次数用完; 500 API网管错误
*/
//获取response的body
if
(
statusCode
==
200
)
{
return
EntityUtils
.
toString
(
response
.
getEntity
());
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
}
/**
//认证通过保存到数据库当中
* 二、认证通过保存到数据库当中
*
* @param idInformation
* @return
*/
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
ObjectRestResponse
<
Integer
>
addIdInformation
(
IdInformation
idInformation
)
{
public
ObjectRestResponse
<
Integer
>
addIdInformation
(
IdInformation
idInformation
)
{
log
.
info
(
"----idInformation========="
+
idInformation
);
log
.
info
(
"----idInformation========="
+
idInformation
);
...
@@ -353,28 +164,23 @@ public class CertificationService {
...
@@ -353,28 +164,23 @@ public class CertificationService {
try
{
try
{
Example
exa
=
new
Example
(
IdInformation
.
class
);
Example
exa
=
new
Example
(
IdInformation
.
class
);
Example
.
Criteria
criteria
=
exa
.
createCriteria
();
Example
.
Criteria
criteria
=
exa
.
createCriteria
();
criteria
.
andEqualTo
(
"idNumber"
,
idInformation
.
getIdNumber
());
criteria
.
andEqualTo
(
"idNumber"
,
idInformation
.
getIdNumber
());
// criteria.andEqualTo("userLoginId",idInformation.getUserLoginId());
List
<
IdInformation
>
idInformatics
=
idInformationMapper
.
selectByExample
(
exa
);
List
<
IdInformation
>
idInformatics
=
idInformationMapper
.
selectByExample
(
exa
);
if
(
CollectionUtils
.
isEmpty
(
idInformatics
))
{
if
(
CollectionUtils
.
isEmpty
(
idInformatics
))
{
idInformation
.
setCrtTime
(
new
Date
());
idInformation
.
setCrtTime
(
new
Date
());
idInformationMapper
.
insertSelective
(
idInformation
);
idInformationMapper
.
insertSelective
(
idInformation
);
}
else
{
}
else
{
// IdInformation idInformation1 = idInformatics.get(0);
// idInformation.setId(idInformation1.getId());
// idInformation.setUpdTime(new Date());
// idInformationMapper.updateByPrimaryKeySelective(idInformation);
log
.
error
(
"该身份证已存在,不要重复认证"
);
log
.
error
(
"该身份证已存在,不要重复认证"
);
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
FAILED_CODE
,
"该身份证已存在,不要重复认证"
);
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
FAILED_CODE
,
"该身份证已存在,不要重复认证"
);
}
}
log
.
info
(
"----addIdInformation---userid==="
+
idInformation
.
getUserLoginId
()+
"----name===="
+
idInformation
.
getName
()+
"---IdNumber==="
+
idInformation
.
getIdNumber
());
log
.
info
(
"----addIdInformation---userid==="
+
idInformation
.
getUserLoginId
()
+
"----name===="
+
idInformation
.
getName
()
+
"---IdNumber==="
+
idInformation
.
getIdNumber
());
//认证成功后修改用户,用户认证状态
//认证成功后修改用户,用户认证状态
ObjectRestResponse
authentication
=
userFeign
.
authentication
(
idInformation
.
getUserLoginId
(),
idInformation
.
getName
(),
idInformation
.
getIdNumber
(),
1
);
ObjectRestResponse
authentication
=
userFeign
.
authentication
(
idInformation
.
getUserLoginId
(),
idInformation
.
getName
(),
idInformation
.
getIdNumber
(),
1
);
return
ObjectRestResponse
.
succ
(
idInformation
.
getId
());
return
ObjectRestResponse
.
succ
(
idInformation
.
getId
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
TransactionAspectSupport
.
currentTransactionStatus
();
TransactionAspectSupport
.
currentTransactionStatus
();
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
INCOMPLETE_DATA
,
"无法识别,请重新上传"
);
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
INCOMPLETE_DATA
,
"无法识别,请重新上传"
);
}
}
}
}
...
...
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