|
|
@@ -1,10 +1,15 @@
|
|
1
|
1
|
package com.ruoyi.wisdomarbitrate.service.impl;
|
|
2
|
2
|
|
|
3
|
3
|
|
|
|
4
|
+import cn.hutool.core.codec.Base64;
|
|
|
5
|
+import cn.hutool.crypto.SmUtil;
|
|
|
6
|
+import cn.hutool.crypto.asymmetric.SM2;
|
|
|
7
|
+import cn.hutool.crypto.symmetric.SymmetricCrypto;
|
|
4
|
8
|
import com.alibaba.fastjson.JSON;
|
|
5
|
9
|
import com.alibaba.fastjson.JSONObject;
|
|
6
|
10
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
7
|
|
-import com.ruoyi.common.utils.StringUtils;
|
|
|
11
|
+import com.ruoyi.common.core.domain.model.LoginUser;
|
|
|
12
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
8
|
13
|
import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication;
|
|
9
|
14
|
import com.ruoyi.wisdomarbitrate.mapper.IdentityAuthenticationMapper;
|
|
10
|
15
|
import com.ruoyi.wisdomarbitrate.service.IdentityAuthenticationService;
|
|
|
@@ -24,6 +29,8 @@ import org.springframework.beans.factory.annotation.Value;
|
|
24
|
29
|
import org.springframework.stereotype.Service;
|
|
25
|
30
|
import org.springframework.transaction.annotation.Transactional;
|
|
26
|
31
|
|
|
|
32
|
+import java.util.Date;
|
|
|
33
|
+
|
|
27
|
34
|
@Service
|
|
28
|
35
|
public class IdentityAuthenticationServiceImpl implements IdentityAuthenticationService {
|
|
29
|
36
|
|
|
|
@@ -58,6 +65,27 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthentication
|
|
58
|
65
|
|
|
59
|
66
|
}
|
|
60
|
67
|
|
|
|
68
|
+ /**
|
|
|
69
|
+ * 检查是否已经认证的用户
|
|
|
70
|
+ *
|
|
|
71
|
+ * @param identityAuthentication
|
|
|
72
|
+ * @return
|
|
|
73
|
+ */
|
|
|
74
|
+ @Override
|
|
|
75
|
+ public String checkIsAuthentication(IdentityAuthentication identityAuthentication) {
|
|
|
76
|
+ IdentityAuthentication identityAuthenticationselect = identityAuthenticationMapper.selectIdentityAuthentication(identityAuthentication);
|
|
|
77
|
+ if (identityAuthenticationselect != null) {
|
|
|
78
|
+ return "1";
|
|
|
79
|
+ } else {
|
|
|
80
|
+ return "0";
|
|
|
81
|
+ }
|
|
|
82
|
+ }
|
|
|
83
|
+
|
|
|
84
|
+ /**
|
|
|
85
|
+ * 获取EIDtoken
|
|
|
86
|
+ *
|
|
|
87
|
+ * @return
|
|
|
88
|
+ */
|
|
61
|
89
|
@Override
|
|
62
|
90
|
public JSONObject selectIdentityAuthenticaEIDtoken() {
|
|
63
|
91
|
JSONObject objJSON = new JSONObject();
|
|
|
@@ -74,10 +102,10 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthentication
|
|
74
|
102
|
FaceidClient client = new FaceidClient(cred, "", clientProfile);
|
|
75
|
103
|
// 实例化一个请求对象,每个接口都会对应一个request对象
|
|
76
|
104
|
GetEidTokenRequest req = new GetEidTokenRequest();
|
|
|
105
|
+ req.setMerchantId(merchantId);
|
|
77
|
106
|
// 返回的resp是一个GetEidTokenResponse的实例,与请求对象对应
|
|
78
|
107
|
GetEidTokenResponse resp = client.GetEidToken(req);
|
|
79
|
108
|
// 输出json格式的字符串回包
|
|
80
|
|
- System.out.println(GetEidTokenResponse.toJsonString(resp));
|
|
81
|
109
|
String respJSON = GetEidTokenResponse.toJsonString(resp);
|
|
82
|
110
|
objJSON = JSON.parseObject(respJSON);
|
|
83
|
111
|
} catch (TencentCloudSDKException e) {
|
|
|
@@ -87,9 +115,37 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthentication
|
|
87
|
115
|
return objJSON;
|
|
88
|
116
|
}
|
|
89
|
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;
|
|
|
138
|
+ }
|
|
|
139
|
+
|
|
|
140
|
+ /**
|
|
|
141
|
+ * 小程序人脸核身后查询身份认证结果
|
|
|
142
|
+ *
|
|
|
143
|
+ * @param ientityAuthentication
|
|
|
144
|
+ * @return
|
|
|
145
|
+ */
|
|
90
|
146
|
@Override
|
|
91
|
147
|
@Transactional
|
|
92
|
|
- public JSONObject selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication) {
|
|
|
148
|
+ public AjaxResult selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication) {
|
|
93
|
149
|
String eidToken = ientityAuthentication.getEidToken();
|
|
94
|
150
|
|
|
95
|
151
|
try {
|
|
|
@@ -108,10 +164,53 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthentication
|
|
108
|
164
|
// 返回的resp是一个GetEidResultResponse的实例,与请求对象对应
|
|
109
|
165
|
GetEidResultResponse resp = client.GetEidResult(req);
|
|
110
|
166
|
// 输出json格式的字符串回包
|
|
111
|
|
- System.out.println(GetEidResultResponse.toJsonString(resp));
|
|
112
|
167
|
String s = GetEidResultResponse.toJsonString(resp);
|
|
113
|
|
- JSONObject object = JSON.parseObject(s);
|
|
114
|
|
- return object;
|
|
|
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();
|
|
115
|
214
|
} catch (TencentCloudSDKException e) {
|
|
116
|
215
|
System.out.println(e.toString());
|
|
117
|
216
|
}
|