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
0da8cce6
Commit
0da8cce6
authored
Sep 27, 2019
by
hanfeng
Committed by
libin
Sep 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改实名认证
parent
690984e9
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
551 additions
and
49 deletions
+551
-49
pom.xml
xx-universal/xx-universal-api/pom.xml
+6
-0
BaseAuthentication.java
...a/com/xxfc/platform/universal/api/BaseAuthentication.java
+0
-14
FQAuthentication.java
...om/xxfc/platform/universal/api/impl/FQAuthentication.java
+0
-13
Authentication.java
.../com/xxfc/platform/universal/api/pojo/Authentication.java
+0
-4
HttpUtils.java
...ain/java/com/xxfc/platform/universal/utils/HttpUtils.java
+312
-0
UserMessage.java
...ain/java/com/xxfc/platform/universal/biz/UserMessage.java
+13
-0
CertificationService.java
...xxfc/platform/universal/service/CertificationService.java
+38
-18
UserAuthentication.java
...l/service/authenticationInterface/UserAuthentication.java
+18
-0
BJCYAuthentication.java
...vice/authenticationInterface/impl/BJCYAuthentication.java
+73
-0
XCFQAuthentication.java
...vice/authenticationInterface/impl/XCFQAuthentication.java
+91
-0
No files found.
xx-universal/xx-universal-api/pom.xml
View file @
0da8cce6
...
...
@@ -83,6 +83,12 @@
<artifactId>
jiguang-common
</artifactId>
<version>
1.1.1
</version>
</dependency>
<dependency>
<groupId>
commons-lang
</groupId>
<artifactId>
commons-lang
</artifactId>
<version>
2.6
</version>
<scope>
compile
</scope>
</dependency>
</dependencies>
...
...
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/api/BaseAuthentication.java
deleted
100644 → 0
View file @
690984e9
package
com
.
xxfc
.
platform
.
universal
.
api
;
import
com.xxfc.platform.universal.api.pojo.Authentication
;
import
com.xxfc.platform.universal.entity.IdInformation
;
/**
* 调用外部接口实现类。调用不同的外部接口,需要编写不同了类实现该类
*/
public
interface
BaseAuthentication
{
Authentication
getAuthentication
(
IdInformation
idInformation
);
}
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/api/impl/FQAuthentication.java
deleted
100644 → 0
View file @
690984e9
package
com
.
xxfc
.
platform
.
universal
.
api
.
impl
;
import
com.xxfc.platform.universal.api.BaseAuthentication
;
import
com.xxfc.platform.universal.api.pojo.Authentication
;
import
com.xxfc.platform.universal.entity.IdInformation
;
public
class
FQAuthentication
implements
BaseAuthentication
{
@Override
public
Authentication
getAuthentication
(
IdInformation
idInformation
)
{
return
null
;
}
}
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/api/pojo/Authentication.java
deleted
100644 → 0
View file @
690984e9
package
com
.
xxfc
.
platform
.
universal
.
api
.
pojo
;
public
class
Authentication
{
}
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/utils/HttpUtils.java
0 → 100644
View file @
0da8cce6
package
com
.
xxfc
.
platform
.
universal
.
utils
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.security.KeyManagementException
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.cert.X509Certificate
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
javax.net.ssl.SSLContext
;
import
javax.net.ssl.TrustManager
;
import
javax.net.ssl.X509TrustManager
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.NameValuePair
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.entity.UrlEncodedFormEntity
;
import
org.apache.http.client.methods.HttpDelete
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.client.methods.HttpPut
;
import
org.apache.http.conn.ClientConnectionManager
;
import
org.apache.http.conn.scheme.Scheme
;
import
org.apache.http.conn.scheme.SchemeRegistry
;
import
org.apache.http.conn.ssl.SSLSocketFactory
;
import
org.apache.http.entity.ByteArrayEntity
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.DefaultHttpClient
;
import
org.apache.http.message.BasicNameValuePair
;
public
class
HttpUtils
{
/**
* get
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @return
* @throws Exception
*/
public
static
HttpResponse
doGet
(
String
host
,
String
path
,
String
method
,
Map
<
String
,
String
>
headers
,
Map
<
String
,
String
>
querys
)
throws
Exception
{
HttpClient
httpClient
=
wrapClient
(
host
);
HttpGet
request
=
new
HttpGet
(
buildUrl
(
host
,
path
,
querys
));
for
(
Map
.
Entry
<
String
,
String
>
e
:
headers
.
entrySet
())
{
request
.
addHeader
(
e
.
getKey
(),
e
.
getValue
());
}
return
httpClient
.
execute
(
request
);
}
/**
* post form
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param bodys
* @return
* @throws Exception
*/
public
static
HttpResponse
doPost
(
String
host
,
String
path
,
String
method
,
Map
<
String
,
String
>
headers
,
Map
<
String
,
String
>
querys
,
Map
<
String
,
String
>
bodys
)
throws
Exception
{
HttpClient
httpClient
=
wrapClient
(
host
);
HttpPost
request
=
new
HttpPost
(
buildUrl
(
host
,
path
,
querys
));
for
(
Map
.
Entry
<
String
,
String
>
e
:
headers
.
entrySet
())
{
request
.
addHeader
(
e
.
getKey
(),
e
.
getValue
());
}
if
(
bodys
!=
null
)
{
List
<
NameValuePair
>
nameValuePairList
=
new
ArrayList
<
NameValuePair
>();
for
(
String
key
:
bodys
.
keySet
())
{
nameValuePairList
.
add
(
new
BasicNameValuePair
(
key
,
bodys
.
get
(
key
)));
}
UrlEncodedFormEntity
formEntity
=
new
UrlEncodedFormEntity
(
nameValuePairList
,
"utf-8"
);
formEntity
.
setContentType
(
"application/x-www-form-urlencoded; charset=UTF-8"
);
request
.
setEntity
(
formEntity
);
}
return
httpClient
.
execute
(
request
);
}
/**
* Post String
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public
static
HttpResponse
doPost
(
String
host
,
String
path
,
String
method
,
Map
<
String
,
String
>
headers
,
Map
<
String
,
String
>
querys
,
String
body
)
throws
Exception
{
HttpClient
httpClient
=
wrapClient
(
host
);
HttpPost
request
=
new
HttpPost
(
buildUrl
(
host
,
path
,
querys
));
for
(
Map
.
Entry
<
String
,
String
>
e
:
headers
.
entrySet
())
{
request
.
addHeader
(
e
.
getKey
(),
e
.
getValue
());
}
if
(
StringUtils
.
isNotBlank
(
body
))
{
request
.
setEntity
(
new
StringEntity
(
body
,
"utf-8"
));
}
return
httpClient
.
execute
(
request
);
}
/**
* Post stream
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public
static
HttpResponse
doPost
(
String
host
,
String
path
,
String
method
,
Map
<
String
,
String
>
headers
,
Map
<
String
,
String
>
querys
,
byte
[]
body
)
throws
Exception
{
HttpClient
httpClient
=
wrapClient
(
host
);
HttpPost
request
=
new
HttpPost
(
buildUrl
(
host
,
path
,
querys
));
for
(
Map
.
Entry
<
String
,
String
>
e
:
headers
.
entrySet
())
{
request
.
addHeader
(
e
.
getKey
(),
e
.
getValue
());
}
if
(
body
!=
null
)
{
request
.
setEntity
(
new
ByteArrayEntity
(
body
));
}
return
httpClient
.
execute
(
request
);
}
/**
* Put String
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public
static
HttpResponse
doPut
(
String
host
,
String
path
,
String
method
,
Map
<
String
,
String
>
headers
,
Map
<
String
,
String
>
querys
,
String
body
)
throws
Exception
{
HttpClient
httpClient
=
wrapClient
(
host
);
HttpPut
request
=
new
HttpPut
(
buildUrl
(
host
,
path
,
querys
));
for
(
Map
.
Entry
<
String
,
String
>
e
:
headers
.
entrySet
())
{
request
.
addHeader
(
e
.
getKey
(),
e
.
getValue
());
}
if
(
StringUtils
.
isNotBlank
(
body
))
{
request
.
setEntity
(
new
StringEntity
(
body
,
"utf-8"
));
}
return
httpClient
.
execute
(
request
);
}
/**
* Put stream
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public
static
HttpResponse
doPut
(
String
host
,
String
path
,
String
method
,
Map
<
String
,
String
>
headers
,
Map
<
String
,
String
>
querys
,
byte
[]
body
)
throws
Exception
{
HttpClient
httpClient
=
wrapClient
(
host
);
HttpPut
request
=
new
HttpPut
(
buildUrl
(
host
,
path
,
querys
));
for
(
Map
.
Entry
<
String
,
String
>
e
:
headers
.
entrySet
())
{
request
.
addHeader
(
e
.
getKey
(),
e
.
getValue
());
}
if
(
body
!=
null
)
{
request
.
setEntity
(
new
ByteArrayEntity
(
body
));
}
return
httpClient
.
execute
(
request
);
}
/**
* Delete
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @return
* @throws Exception
*/
public
static
HttpResponse
doDelete
(
String
host
,
String
path
,
String
method
,
Map
<
String
,
String
>
headers
,
Map
<
String
,
String
>
querys
)
throws
Exception
{
HttpClient
httpClient
=
wrapClient
(
host
);
HttpDelete
request
=
new
HttpDelete
(
buildUrl
(
host
,
path
,
querys
));
for
(
Map
.
Entry
<
String
,
String
>
e
:
headers
.
entrySet
())
{
request
.
addHeader
(
e
.
getKey
(),
e
.
getValue
());
}
return
httpClient
.
execute
(
request
);
}
private
static
String
buildUrl
(
String
host
,
String
path
,
Map
<
String
,
String
>
querys
)
throws
UnsupportedEncodingException
{
StringBuilder
sbUrl
=
new
StringBuilder
();
sbUrl
.
append
(
host
);
if
(!
StringUtils
.
isBlank
(
path
))
{
sbUrl
.
append
(
path
);
}
if
(
null
!=
querys
)
{
StringBuilder
sbQuery
=
new
StringBuilder
();
for
(
Map
.
Entry
<
String
,
String
>
query
:
querys
.
entrySet
())
{
if
(
0
<
sbQuery
.
length
())
{
sbQuery
.
append
(
"&"
);
}
if
(
StringUtils
.
isBlank
(
query
.
getKey
())
&&
!
StringUtils
.
isBlank
(
query
.
getValue
()))
{
sbQuery
.
append
(
query
.
getValue
());
}
if
(!
StringUtils
.
isBlank
(
query
.
getKey
()))
{
sbQuery
.
append
(
query
.
getKey
());
if
(!
StringUtils
.
isBlank
(
query
.
getValue
()))
{
sbQuery
.
append
(
"="
);
sbQuery
.
append
(
URLEncoder
.
encode
(
query
.
getValue
(),
"utf-8"
));
}
}
}
if
(
0
<
sbQuery
.
length
())
{
sbUrl
.
append
(
"?"
).
append
(
sbQuery
);
}
}
return
sbUrl
.
toString
();
}
private
static
HttpClient
wrapClient
(
String
host
)
{
HttpClient
httpClient
=
new
DefaultHttpClient
();
if
(
host
.
startsWith
(
"https://"
))
{
sslClient
(
httpClient
);
}
return
httpClient
;
}
private
static
void
sslClient
(
HttpClient
httpClient
)
{
try
{
SSLContext
ctx
=
SSLContext
.
getInstance
(
"TLS"
);
X509TrustManager
tm
=
new
X509TrustManager
()
{
public
X509Certificate
[]
getAcceptedIssuers
()
{
return
null
;
}
public
void
checkClientTrusted
(
X509Certificate
[]
xcs
,
String
str
)
{
}
public
void
checkServerTrusted
(
X509Certificate
[]
xcs
,
String
str
)
{
}
};
ctx
.
init
(
null
,
new
TrustManager
[]
{
tm
},
null
);
SSLSocketFactory
ssf
=
new
SSLSocketFactory
(
ctx
);
ssf
.
setHostnameVerifier
(
SSLSocketFactory
.
ALLOW_ALL_HOSTNAME_VERIFIER
);
ClientConnectionManager
ccm
=
httpClient
.
getConnectionManager
();
SchemeRegistry
registry
=
ccm
.
getSchemeRegistry
();
registry
.
register
(
new
Scheme
(
"https"
,
443
,
ssf
));
}
catch
(
KeyManagementException
ex
)
{
throw
new
RuntimeException
(
ex
);
}
catch
(
NoSuchAlgorithmException
ex
)
{
throw
new
RuntimeException
(
ex
);
}
}
}
\ No newline at end of file
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/biz/UserMessage.java
0 → 100644
View file @
0da8cce6
package
com
.
xxfc
.
platform
.
universal
.
biz
;
import
lombok.Data
;
/**
* 用户信息类
* @author Administrator
*/
@Data
public
class
UserMessage
{
private
String
name
;
private
String
idNumber
;
}
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/service/CertificationService.java
View file @
0da8cce6
...
...
@@ -7,8 +7,10 @@ import com.github.wxiaoqi.security.admin.feign.UserFeign;
import
com.github.wxiaoqi.security.common.exception.BaseException
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.github.wxiaoqi.security.common.util.process.ResultCode
;
import
com.xxfc.platform.universal.biz.UserMessage
;
import
com.xxfc.platform.universal.entity.IdInformation
;
import
com.xxfc.platform.universal.mapper.IdInformationMapper
;
import
com.xxfc.platform.universal.service.authenticationInterface.UserAuthentication
;
import
com.xxfc.platform.universal.utils.CertifHttpUtils
;
import
com.xxfc.platform.universal.utils.Validation
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -21,6 +23,7 @@ import org.apache.http.util.EntityUtils;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.interceptor.TransactionAspectSupport
;
...
...
@@ -31,9 +34,16 @@ import java.text.SimpleDateFormat;
import
java.util.*
;
/**
* 认证业务
* @author Administrator
*/
@Service
@Slf4j
public
class
CertificationService
{
@Autowired
private
UserAuthentication
authentication
;
/**
* 认证相关的数据
*/
...
...
@@ -209,17 +219,20 @@ public class CertificationService {
}
//map携带身份证和姓名进行认证
Map
<
String
,
String
>
authMap
=
new
HashMap
<>();
authMap
.
put
(
idCardName
,
(
String
)
frontData
.
get
(
numberName
));
authMap
.
put
(
cName
,
(
String
)
frontData
.
get
(
cName
));
//3.调用接口进行认证
String
result
=
certificate
(
authMap
);
// 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
);
setName
(
name
);
}}
);
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
)))
{
if
(
result
)
{
//认证成功后存入保存到数据库
//获得身份证正面记录的身份证号和真实姓名
//设置姓名
...
...
@@ -257,9 +270,6 @@ public class CertificationService {
// return ObjectRestResponse.succ(objRR.getData());
// }
}
}
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
INCOMPLETE_DATA
,
"网络异常,请稍后再试"
);
...
...
@@ -267,7 +277,8 @@ public class CertificationService {
//认证
public
String
certificate
(
Map
<
String
,
String
>
querys
)
{
//认证
public
boolean
certificate
(
Map
<
String
,
String
>
querys
)
{
Map
<
String
,
String
>
headers
=
new
HashMap
<
String
,
String
>();
headers
.
put
(
"Authorization"
,
"APPCODE "
+
cAppcode
);
try
{
...
...
@@ -280,15 +291,27 @@ public class CertificationService {
*/
//获取response的body
if
(
statusCode
==
200
)
{
return
EntityUtils
.
toString
(
response
.
getEntity
());
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
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
return
null
;
}
//身份证照片解析
public
String
imageParse
(
String
imageUrl
,
String
type
)
{
Map
<
String
,
String
>
headers
=
new
HashMap
<
String
,
String
>();
...
...
@@ -317,10 +340,7 @@ public class CertificationService {
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
...
...
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/service/authenticationInterface/UserAuthentication.java
0 → 100644
View file @
0da8cce6
package
com
.
xxfc
.
platform
.
universal
.
service
.
authenticationInterface
;
import
com.xxfc.platform.universal.biz.UserMessage
;
import
java.util.Map
;
/**
* 用户认证类
* @author Administrator
*/
public
interface
UserAuthentication
{
/**
* 用户认证方法
* @param message
* @return
*/
boolean
certificate
(
UserMessage
message
)
;
}
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/service/authenticationInterface/impl/BJCYAuthentication.java
0 → 100644
View file @
0da8cce6
package
com
.
xxfc
.
platform
.
universal
.
service
.
authenticationInterface
.
impl
;
import
cn.hutool.core.map.MapUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.xxfc.platform.universal.biz.UserMessage
;
import
com.xxfc.platform.universal.service.authenticationInterface.UserAuthentication
;
import
com.xxfc.platform.universal.utils.CertifHttpUtils
;
import
com.xxfc.platform.universal.utils.HttpUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.StatusLine
;
import
org.apache.http.util.EntityUtils
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.stereotype.Service
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 调用北京畅游互联科技有限公司接口
*
* @author Administrator
*/
@Service
@Slf4j
@Primary
public
class
BJCYAuthentication
implements
UserAuthentication
{
private
final
String
host
=
"http://aliyunverifyidcard.haoservice.com"
;
private
final
String
path
=
"/idcard/VerifyIdcardv2"
;
private
final
String
method
=
"GET"
;
private
final
String
appcode
=
"ee7710ce92054cae9f6c040f6864e6a7"
;
private
final
String
tokenHead
=
"Authorization"
;
private
final
String
token
=
"APPCODE "
+
appcode
;
private
final
String
cardNo
=
"cardNo"
;
private
final
String
realName
=
"realName"
;
private
final
Integer
resultCode
=
0
;
private
final
String
ret
=
"error_code"
;
@Override
public
boolean
certificate
(
UserMessage
message
)
{
Map
<
String
,
String
>
headers
=
new
HashMap
<
String
,
String
>();
headers
.
put
(
tokenHead
,
token
);
Map
<
String
,
String
>
querys
=
new
HashMap
<
String
,
String
>();
querys
.
put
(
cardNo
,
message
.
getIdNumber
());
querys
.
put
(
realName
,
message
.
getName
());
try
{
HttpResponse
response
=
HttpUtils
.
doGet
(
host
,
path
,
method
,
headers
,
querys
);
StatusLine
statusLine
=
response
.
getStatusLine
();
log
.
error
(
response
.
toString
());
int
statusCode
=
statusLine
.
getStatusCode
();
log
.
error
(
statusCode
+
""
);
//获取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========="
+
map
);
if
(
MapUtil
.
isNotEmpty
(
map
)
||
resultCode
.
equals
(
map
.
get
(
ret
)))
{
return
true
;
}
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
false
;
}
}
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/service/authenticationInterface/impl/XCFQAuthentication.java
0 → 100644
View file @
0da8cce6
package
com
.
xxfc
.
platform
.
universal
.
service
.
authenticationInterface
.
impl
;
import
cn.hutool.core.map.MapUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.xxfc.platform.universal.biz.UserMessage
;
import
com.xxfc.platform.universal.service.authenticationInterface.UserAuthentication
;
import
com.xxfc.platform.universal.utils.CertifHttpUtils
;
import
com.xxfc.platform.universal.utils.HttpUtils
;
import
lombok.extern.slf4j.Slf4j
;
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
XCFQAuthentication
implements
UserAuthentication
{
private
String
cAppcode
=
"acea1c8811f748b3a65815f11db357c4"
;
/**
* 认证相关的数据
*/
private
String
cHost
=
"https://idcert.market.alicloudapi.com"
;
private
String
cPath
=
"/idcard"
;
private
String
cMethod
=
"GET"
;
//响应:认证错误码字段名
private
String
certifRet
=
"status"
;
//响应:认证通过码
private
String
certifResultCode
=
"01"
;
//请求:身份证号字段名
private
String
idCardName
=
"idCard"
;
//请求:用户姓名字段名
private
String
cName
=
"name"
;
@Override
public
boolean
certificate
(
UserMessage
message
)
{
//map携带身份证和姓名进行认证
Map
<
String
,
String
>
querys
=
new
HashMap
<>();
querys
.
put
(
idCardName
,
message
.
getIdNumber
());
querys
.
put
(
cName
,
message
.
getName
());
Map
<
String
,
String
>
headers
=
new
HashMap
<
String
,
String
>();
headers
.
put
(
"Authorization"
,
"APPCODE "
+
cAppcode
);
try
{
log
.
info
(
"----querys========="
+
querys
);
HttpResponse
response
=
HttpUtils
.
doGet
(
cHost
,
cPath
,
cMethod
,
headers
,
querys
);
StatusLine
statusLine
=
response
.
getStatusLine
();
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
;
}
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
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