|
|
@@ -1,27 +1,27 @@
|
|
1
|
1
|
package com.ruoyi.wisdomarbitrate.service.impl;
|
|
2
|
2
|
|
|
3
|
3
|
|
|
4
|
|
-
|
|
|
4
|
+import cn.hutool.core.codec.Base64;
|
|
5
|
5
|
import cn.hutool.crypto.SmUtil;
|
|
6
|
6
|
import cn.hutool.crypto.asymmetric.SM2;
|
|
7
|
7
|
import cn.hutool.crypto.symmetric.SymmetricCrypto;
|
|
8
|
8
|
import com.alibaba.fastjson.JSON;
|
|
9
|
9
|
import com.alibaba.fastjson.JSONObject;
|
|
10
|
10
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
11
|
|
-import com.ruoyi.common.utils.StringUtils;
|
|
12
|
|
-import com.ruoyi.exceptions.TradeException;
|
|
|
11
|
+import com.ruoyi.common.core.domain.model.LoginUser;
|
|
|
12
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
13
|
13
|
import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication;
|
|
14
|
14
|
import com.ruoyi.wisdomarbitrate.mapper.IdentityAuthenticationMapper;
|
|
15
|
|
-import com.ruoyi.wisdomarbitrate.service.ICaseApplicationService;
|
|
16
|
15
|
import com.ruoyi.wisdomarbitrate.service.IdentityAuthenticationService;
|
|
17
|
|
-
|
|
18
|
16
|
import com.tencentcloudapi.common.Credential;
|
|
|
17
|
+import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
|
19
|
18
|
import com.tencentcloudapi.common.profile.ClientProfile;
|
|
20
|
19
|
import com.tencentcloudapi.common.profile.HttpProfile;
|
|
21
|
|
-import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
|
22
|
20
|
import com.tencentcloudapi.faceid.v20180301.FaceidClient;
|
|
23
|
|
-import com.tencentcloudapi.faceid.v20180301.models.*;
|
|
24
|
|
-
|
|
|
21
|
+import com.tencentcloudapi.faceid.v20180301.models.GetEidResultRequest;
|
|
|
22
|
+import com.tencentcloudapi.faceid.v20180301.models.GetEidResultResponse;
|
|
|
23
|
+import com.tencentcloudapi.faceid.v20180301.models.GetEidTokenRequest;
|
|
|
24
|
+import com.tencentcloudapi.faceid.v20180301.models.GetEidTokenResponse;
|
|
25
|
25
|
import org.slf4j.Logger;
|
|
26
|
26
|
import org.slf4j.LoggerFactory;
|
|
27
|
27
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -29,15 +29,10 @@ import org.springframework.beans.factory.annotation.Value;
|
|
29
|
29
|
import org.springframework.stereotype.Service;
|
|
30
|
30
|
import org.springframework.transaction.annotation.Transactional;
|
|
31
|
31
|
|
|
32
|
|
-import java.io.FileInputStream;
|
|
33
|
|
-import java.io.IOException;
|
|
34
|
|
-import java.io.InputStream;
|
|
35
|
|
-import java.util.Base64;
|
|
36
|
|
-import java.util.HashMap;
|
|
37
|
|
-import java.util.Map;
|
|
|
32
|
+import java.util.Date;
|
|
38
|
33
|
|
|
39
|
34
|
@Service
|
|
40
|
|
-public class IdentityAuthenticationServiceImpl implements IdentityAuthenticationService {
|
|
|
35
|
+public class IdentityAuthenticationServiceImpl implements IdentityAuthenticationService {
|
|
41
|
36
|
|
|
42
|
37
|
@Value("${identityAuthentication.credentialSecretId}")
|
|
43
|
38
|
private String credentialSecretId;
|
|
|
@@ -58,9 +53,9 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthenticatio
|
|
58
|
53
|
@Override
|
|
59
|
54
|
public IdentityAuthentication selectIdentityAuthentication(IdentityAuthentication identityAuthentication) {
|
|
60
|
55
|
IdentityAuthentication identityAuthenticationselect = identityAuthenticationMapper.selectIdentityAuthentication(identityAuthentication);
|
|
61
|
|
- if(identityAuthenticationselect!=null){
|
|
|
56
|
+ if (identityAuthenticationselect != null) {
|
|
62
|
57
|
identityAuthenticationselect.setCertificationStatusName("已身份认证");
|
|
63
|
|
- }else {
|
|
|
58
|
+ } else {
|
|
64
|
59
|
IdentityAuthentication identityAuthenticationselectnew = new IdentityAuthentication();
|
|
65
|
60
|
identityAuthenticationselectnew.setCertificationStatusName("未身份认证");
|
|
66
|
61
|
identityAuthenticationselectnew.setCertificationStatus(0);
|
|
|
@@ -70,86 +65,157 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthenticatio
|
|
70
|
65
|
|
|
71
|
66
|
}
|
|
72
|
67
|
|
|
|
68
|
+ /**
|
|
|
69
|
+ * 检查是否已经认证的用户
|
|
|
70
|
+ *
|
|
|
71
|
+ * @param identityAuthentication
|
|
|
72
|
+ * @return
|
|
|
73
|
+ */
|
|
73
|
74
|
@Override
|
|
74
|
|
- public IdentityAuthentication selectIdentityAuthenticaEIDtoken() {
|
|
75
|
|
- IdentityAuthentication identityAuthentication = new IdentityAuthentication();
|
|
76
|
|
- try{
|
|
77
|
|
- Credential authenti = new Credential(credentialSecretId, credentialSecretKey);
|
|
78
|
|
- HttpProfile httpProfileIdenAuth = new HttpProfile();
|
|
79
|
|
- httpProfileIdenAuth.setEndpoint("faceid.tencentcloudapi.com");
|
|
80
|
|
- ClientProfile clientInv= new ClientProfile();
|
|
81
|
|
- clientInv.setHttpProfile(httpProfileIdenAuth);
|
|
82
|
|
- FaceidClient clientIdenAuth = new FaceidClient(authenti, "", clientInv);
|
|
83
|
|
- // 实例化一个请求对象
|
|
84
|
|
- GetEidTokenRequest reqest = new GetEidTokenRequest();
|
|
85
|
|
- //设置请求参数
|
|
86
|
|
- reqest.setMerchantId(merchantId);
|
|
87
|
|
- GetEidTokenResponse respIdenAuth = clientIdenAuth.GetEidToken(reqest);
|
|
88
|
|
- String respJSON = GetEidTokenResponse.toJsonString(respIdenAuth);
|
|
89
|
|
- JSONObject objJSON = JSON.parseObject(respJSON);
|
|
90
|
|
- String eidToken = objJSON.getString("EidToken");
|
|
91
|
|
- String requestId = objJSON.getString("RequestId");
|
|
92
|
|
- identityAuthentication.setEidToken(eidToken);
|
|
93
|
|
- }catch (TencentCloudSDKException e) {
|
|
94
|
|
- log.error("获取Eidtoke异常:", e);
|
|
95
|
|
- throw new RuntimeException("获取Eidtoke异常");
|
|
|
75
|
+ public String checkIsAuthentication(IdentityAuthentication identityAuthentication) {
|
|
|
76
|
+ IdentityAuthentication identityAuthenticationselect = identityAuthenticationMapper.selectIdentityAuthentication(identityAuthentication);
|
|
|
77
|
+ if (identityAuthenticationselect != null) {
|
|
|
78
|
+ return "1";
|
|
|
79
|
+ } else {
|
|
|
80
|
+ return "0";
|
|
96
|
81
|
}
|
|
|
82
|
+ }
|
|
97
|
83
|
|
|
98
|
|
- return identityAuthentication;
|
|
|
84
|
+ /**
|
|
|
85
|
+ * 获取EIDtoken
|
|
|
86
|
+ *
|
|
|
87
|
+ * @return
|
|
|
88
|
+ */
|
|
|
89
|
+ @Override
|
|
|
90
|
+ public JSONObject selectIdentityAuthenticaEIDtoken() {
|
|
|
91
|
+ JSONObject objJSON = new JSONObject();
|
|
|
92
|
+ objJSON.put("EidToken", "");
|
|
|
93
|
+ try {
|
|
|
94
|
+ Credential cred = new Credential(credentialSecretId, credentialSecretKey);
|
|
|
95
|
+ // 实例化一个http选项,可选的,没有特殊需求可以跳过
|
|
|
96
|
+ HttpProfile httpProfile = new HttpProfile();
|
|
|
97
|
+ httpProfile.setEndpoint("faceid.tencentcloudapi.com");
|
|
|
98
|
+ // 实例化一个client选项,可选的,没有特殊需求可以跳过
|
|
|
99
|
+ ClientProfile clientProfile = new ClientProfile();
|
|
|
100
|
+ clientProfile.setHttpProfile(httpProfile);
|
|
|
101
|
+ // 实例化要请求产品的client对象,clientProfile是可选的
|
|
|
102
|
+ FaceidClient client = new FaceidClient(cred, "", clientProfile);
|
|
|
103
|
+ // 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
104
|
+ GetEidTokenRequest req = new GetEidTokenRequest();
|
|
|
105
|
+ req.setMerchantId(merchantId);
|
|
|
106
|
+ // 返回的resp是一个GetEidTokenResponse的实例,与请求对象对应
|
|
|
107
|
+ GetEidTokenResponse resp = client.GetEidToken(req);
|
|
|
108
|
+ // 输出json格式的字符串回包
|
|
|
109
|
+ String respJSON = GetEidTokenResponse.toJsonString(resp);
|
|
|
110
|
+ objJSON = JSON.parseObject(respJSON);
|
|
|
111
|
+ } catch (TencentCloudSDKException e) {
|
|
|
112
|
+ System.out.println(e.toString());
|
|
|
113
|
+ System.out.println("获取Eidtoken失败");
|
|
|
114
|
+ }
|
|
|
115
|
+ return objJSON;
|
|
|
116
|
+ }
|
|
99
|
117
|
|
|
|
118
|
+ /**
|
|
|
119
|
+ * 解密用户信息
|
|
|
120
|
+ */
|
|
|
121
|
+ public JSONObject DecodeUserInfo(String deskey, String userInfo) {
|
|
|
122
|
+ JSONObject parse = null;
|
|
|
123
|
+ try {
|
|
|
124
|
+ byte[] desKeyBytes = Base64.decode(deskey);
|
|
|
125
|
+ final SM2 sm2 = new SM2(privateKeyHexDecodeinfo, null, null);
|
|
|
126
|
+ sm2.usePlainEncoding();
|
|
|
127
|
+ byte[] sm4KeyBytes = sm2.decrypt(desKeyBytes);
|
|
|
128
|
+ SymmetricCrypto sm4 = SmUtil.sm4(sm4KeyBytes);
|
|
|
129
|
+ byte[] plaintext = sm4.decrypt(Base64.decode(userInfo));
|
|
|
130
|
+ if (plaintext != null && plaintext.length > 0) {
|
|
|
131
|
+ String s = new String(plaintext);
|
|
|
132
|
+ parse = JSON.parseObject(s);
|
|
|
133
|
+ }
|
|
|
134
|
+ } catch (Exception e) {
|
|
|
135
|
+ System.out.println(e.toString());
|
|
|
136
|
+ }
|
|
|
137
|
+ return parse;
|
|
100
|
138
|
}
|
|
101
|
139
|
|
|
|
140
|
+ /**
|
|
|
141
|
+ * 小程序人脸核身后查询身份认证结果
|
|
|
142
|
+ *
|
|
|
143
|
+ * @param ientityAuthentication
|
|
|
144
|
+ * @return
|
|
|
145
|
+ */
|
|
102
|
146
|
@Override
|
|
103
|
147
|
@Transactional
|
|
104
|
|
- public IdentityAuthentication selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication) {
|
|
|
148
|
+ public AjaxResult selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication) {
|
|
105
|
149
|
String eidToken = ientityAuthentication.getEidToken();
|
|
106
|
|
- Long userId = ientityAuthentication.getUserId();
|
|
107
|
|
- String userName = ientityAuthentication.getUserName();
|
|
108
|
|
- IdentityAuthentication IdentityAuthenticationRespon = new IdentityAuthentication();
|
|
109
|
|
- IdentityAuthentication IdentityAuthenticationResult = new IdentityAuthentication();
|
|
110
|
|
- if(StringUtils.isNotEmpty(eidToken)){
|
|
111
|
|
- try{
|
|
112
|
|
- Credential authenti = new Credential(credentialSecretId, credentialSecretKey);
|
|
113
|
|
- HttpProfile httpProfileIdenAuth = new HttpProfile();
|
|
114
|
|
- httpProfileIdenAuth.setEndpoint("faceid.tencentcloudapi.com");
|
|
115
|
|
- ClientProfile clientInv= new ClientProfile();
|
|
116
|
|
- clientInv.setHttpProfile(httpProfileIdenAuth);
|
|
117
|
|
- FaceidClient clientIdenAuth = new FaceidClient(authenti, "", clientInv);
|
|
118
|
|
- // 实例化一个请求对象
|
|
119
|
|
- GetEidResultRequest reqest = new GetEidResultRequest();
|
|
120
|
|
- //设置请求参数
|
|
121
|
|
- reqest.setEidToken(eidToken);
|
|
122
|
|
-
|
|
123
|
|
-// reqest.setInfoType("1");
|
|
124
|
|
-// reqest.setInfoType("13");
|
|
125
|
|
-// reqest.setInfoType("2");
|
|
126
|
|
-
|
|
127
|
|
- //获得身份认证结果
|
|
128
|
|
- GetEidResultResponse respIdenAuth = clientIdenAuth.GetEidResult(reqest);
|
|
129
|
|
- String respJSON = GetEidResultResponse.toJsonString(respIdenAuth);
|
|
130
|
|
- JSONObject objJSON = JSON.parseObject(respJSON);
|
|
131
|
|
- IdentityAuthenticationRespon.setCertificationStatus(1);
|
|
132
|
|
- IdentityAuthenticationRespon.setUserName(userName);
|
|
133
|
|
- IdentityAuthenticationRespon.setUserId(userId);
|
|
134
|
|
-
|
|
135
|
|
- JSONObject objEidInfo = JSON.parseObject(objJSON.getString("EidInfo"));
|
|
136
|
|
-// identityAuthenticationMapper.insertIdentityAuthentication(IdentityAuthenticationRespon);
|
|
137
|
|
- IdentityAuthenticationResult.setCertificationStatus(1);
|
|
138
|
|
- IdentityAuthenticationResult.setCertificationStatusName("认证成功");
|
|
139
|
|
- } catch (TencentCloudSDKException e) {
|
|
140
|
|
- log.error("认证失败:", e);
|
|
141
|
|
- throw new RuntimeException("认证失败");
|
|
142
|
|
- }
|
|
143
|
150
|
|
|
|
151
|
+ try {
|
|
|
152
|
+ Credential cred = new Credential(credentialSecretId, credentialSecretKey);
|
|
|
153
|
+ // 实例化一个http选项,可选的,没有特殊需求可以跳过
|
|
|
154
|
+ HttpProfile httpProfile = new HttpProfile();
|
|
|
155
|
+ httpProfile.setEndpoint("faceid.tencentcloudapi.com");
|
|
|
156
|
+ // 实例化一个client选项,可选的,没有特殊需求可以跳过
|
|
|
157
|
+ ClientProfile clientProfile = new ClientProfile();
|
|
|
158
|
+ clientProfile.setHttpProfile(httpProfile);
|
|
|
159
|
+ // 实例化要请求产品的client对象,clientProfile是可选的
|
|
|
160
|
+ FaceidClient client = new FaceidClient(cred, "", clientProfile);
|
|
|
161
|
+ // 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
162
|
+ GetEidResultRequest req = new GetEidResultRequest();
|
|
|
163
|
+ req.setEidToken(eidToken);
|
|
|
164
|
+ // 返回的resp是一个GetEidResultResponse的实例,与请求对象对应
|
|
|
165
|
+ GetEidResultResponse resp = client.GetEidResult(req);
|
|
|
166
|
+ // 输出json格式的字符串回包
|
|
|
167
|
+ String s = GetEidResultResponse.toJsonString(resp);
|
|
|
168
|
+ JSONObject objJSON = JSON.parseObject(s);
|
|
|
169
|
+ //查看是否核验成功
|
|
|
170
|
+ JSONObject text = objJSON.getJSONObject("Text");
|
|
|
171
|
+ if (text != null) {
|
|
|
172
|
+ Integer comparestatus = text.getInteger("Comparestatus");
|
|
|
173
|
+ if (comparestatus != null && comparestatus == 0) {
|
|
|
174
|
+ JSONObject eidInfo = objJSON.getJSONObject("EidInfo");
|
|
|
175
|
+ if (eidInfo != null) {
|
|
|
176
|
+ String desKey = eidInfo.getString("DesKey");
|
|
|
177
|
+ String userInfo = eidInfo.getString("UserInfo");
|
|
|
178
|
+ //1.解密用户的信息
|
|
|
179
|
+ JSONObject info = DecodeUserInfo(desKey, userInfo);
|
|
|
180
|
+ if (info != null) {
|
|
|
181
|
+ String idcardno = info.getString("idnum");
|
|
|
182
|
+ String name = info.getString("name");
|
|
|
183
|
+ //2.在用户认证表中插入用户认证记录
|
|
|
184
|
+ LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
185
|
+ IdentityAuthentication authentication = new IdentityAuthentication();
|
|
|
186
|
+ /**
|
|
|
187
|
+ * 用户名
|
|
|
188
|
+ * 用户名id
|
|
|
189
|
+ * 姓名
|
|
|
190
|
+ * 身份证号
|
|
|
191
|
+ * 认证时间
|
|
|
192
|
+ * 认证状态0表示成功
|
|
|
193
|
+ * 请求id
|
|
|
194
|
+ */
|
|
|
195
|
+ authentication.setUserName(loginUser.getUsername());
|
|
|
196
|
+ authentication.setUserId(loginUser.getUserId());
|
|
|
197
|
+ authentication.setName(name);
|
|
|
198
|
+ authentication.setIdentityNo(idcardno);
|
|
|
199
|
+ authentication.setCertificationTime(new Date());
|
|
|
200
|
+ authentication.setCertificationStatus(0);
|
|
|
201
|
+ authentication.setRequestId(objJSON.getString("RequestId"));
|
|
|
202
|
+ try {
|
|
|
203
|
+ identityAuthenticationMapper.insertIdentityAuthentication(authentication);
|
|
|
204
|
+ } catch (Exception e) {
|
|
|
205
|
+ System.out.println("认证记录新增失败");
|
|
|
206
|
+ }
|
|
|
207
|
+
|
|
|
208
|
+ }
|
|
|
209
|
+
|
|
|
210
|
+ }
|
|
|
211
|
+ }
|
|
|
212
|
+ }
|
|
|
213
|
+ return AjaxResult.success();
|
|
|
214
|
+ } catch (TencentCloudSDKException e) {
|
|
|
215
|
+ System.out.println(e.toString());
|
|
144
|
216
|
}
|
|
145
|
|
- return IdentityAuthenticationResult;
|
|
|
217
|
+ return null;
|
|
146
|
218
|
}
|
|
147
|
219
|
|
|
148
|
220
|
|
|
149
|
|
-
|
|
150
|
|
-
|
|
151
|
|
-
|
|
152
|
|
-
|
|
153
|
|
-
|
|
154
|
|
-
|
|
155
|
221
|
}
|