|
|
@@ -2,9 +2,14 @@ package com.ruoyi.wisdomarbitrate.service.impl;
|
|
2
|
2
|
|
|
3
|
3
|
|
|
4
|
4
|
|
|
|
5
|
+import cn.hutool.crypto.SmUtil;
|
|
|
6
|
+import cn.hutool.crypto.asymmetric.SM2;
|
|
|
7
|
+import cn.hutool.crypto.symmetric.SymmetricCrypto;
|
|
5
|
8
|
import com.alibaba.fastjson.JSON;
|
|
6
|
9
|
import com.alibaba.fastjson.JSONObject;
|
|
7
|
10
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
11
|
+import com.ruoyi.common.utils.StringUtils;
|
|
|
12
|
+import com.ruoyi.exceptions.TradeException;
|
|
8
|
13
|
import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication;
|
|
9
|
14
|
import com.ruoyi.wisdomarbitrate.mapper.IdentityAuthenticationMapper;
|
|
10
|
15
|
import com.ruoyi.wisdomarbitrate.service.ICaseApplicationService;
|
|
|
@@ -14,6 +19,8 @@ import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
|
14
|
19
|
import com.tencentcloudapi.common.profile.ClientProfile;
|
|
15
|
20
|
import com.tencentcloudapi.common.profile.HttpProfile;
|
|
16
|
21
|
import com.tencentcloudapi.faceid.v20180301.FaceidClient;
|
|
|
22
|
+import com.tencentcloudapi.faceid.v20180301.models.GetEidResultRequest;
|
|
|
23
|
+import com.tencentcloudapi.faceid.v20180301.models.GetEidResultResponse;
|
|
17
|
24
|
import com.tencentcloudapi.faceid.v20180301.models.GetEidTokenRequest;
|
|
18
|
25
|
import com.tencentcloudapi.faceid.v20180301.models.GetEidTokenResponse;
|
|
19
|
26
|
import org.slf4j.Logger;
|
|
|
@@ -21,11 +28,14 @@ import org.slf4j.LoggerFactory;
|
|
21
|
28
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
22
|
29
|
import org.springframework.beans.factory.annotation.Value;
|
|
23
|
30
|
import org.springframework.stereotype.Service;
|
|
|
31
|
+import org.springframework.transaction.annotation.Transactional;
|
|
24
|
32
|
|
|
25
|
33
|
import java.io.FileInputStream;
|
|
26
|
34
|
import java.io.IOException;
|
|
27
|
35
|
import java.io.InputStream;
|
|
28
|
36
|
import java.util.Base64;
|
|
|
37
|
+import java.util.HashMap;
|
|
|
38
|
+import java.util.Map;
|
|
29
|
39
|
|
|
30
|
40
|
@Service
|
|
31
|
41
|
public class IdentityAuthenticationServiceImpl implements IdentityAuthenticationService {
|
|
|
@@ -36,9 +46,9 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthenticatio
|
|
36
|
46
|
private String credentialSecretKey;
|
|
37
|
47
|
@Value("${identityAuthentication.merchantId}")
|
|
38
|
48
|
private String merchantId;
|
|
|
49
|
+ @Value("${identityAuthentication.privateKeyHexDecodeinfo}")
|
|
|
50
|
+ private String privateKeyHexDecodeinfo;
|
|
39
|
51
|
|
|
40
|
|
-// private static final String SECRET_ID = "AKIDeEf2A8uX1HSainvvnXAc3X9ZlhtyvkMp";
|
|
41
|
|
-// private static final String SECRET_KEY = "QjphKo8zkHZigT8j9PVtFPJyfIvO3d6V";
|
|
42
|
52
|
|
|
43
|
53
|
@Autowired
|
|
44
|
54
|
private IdentityAuthenticationMapper identityAuthenticationMapper;
|
|
|
@@ -64,7 +74,6 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthenticatio
|
|
64
|
74
|
public IdentityAuthentication selectIdentityAuthenticaEIDtoken() {
|
|
65
|
75
|
IdentityAuthentication identityAuthentication = new IdentityAuthentication();
|
|
66
|
76
|
try{
|
|
67
|
|
- // Credential credIdenAuth = new Credential(SECRET_ID, SECRET_KEY);
|
|
68
|
77
|
Credential authenti = new Credential(credentialSecretId, credentialSecretKey);
|
|
69
|
78
|
HttpProfile httpProfileIdenAuth = new HttpProfile();
|
|
70
|
79
|
httpProfileIdenAuth.setEndpoint("faceid.tencentcloudapi.com");
|
|
|
@@ -78,17 +87,91 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthenticatio
|
|
78
|
87
|
GetEidTokenResponse respIdenAuth = clientIdenAuth.GetEidToken(reqest);
|
|
79
|
88
|
String respJSON = GetEidTokenResponse.toJsonString(respIdenAuth);
|
|
80
|
89
|
JSONObject objJSON = JSON.parseObject(respJSON);
|
|
81
|
|
- JSONObject objJSONRes = (JSONObject) objJSON.get("Response");
|
|
82
|
|
- String eidToken = objJSONRes.getString("EidToken");
|
|
83
|
|
- String requestId = objJSONRes.getString("RequestId");
|
|
|
90
|
+ String eidToken = objJSON.getString("EidToken");
|
|
|
91
|
+ String requestId = objJSON.getString("RequestId");
|
|
84
|
92
|
identityAuthentication.setEidToken(eidToken);
|
|
85
|
93
|
}catch (TencentCloudSDKException e) {
|
|
86
|
|
- System.out.println(e.toString());
|
|
|
94
|
+ log.error("获取Eidtoke异常:", e);
|
|
|
95
|
+ throw new RuntimeException("获取Eidtoke异常");
|
|
87
|
96
|
}
|
|
88
|
97
|
|
|
89
|
98
|
return identityAuthentication;
|
|
90
|
99
|
|
|
91
|
100
|
}
|
|
92
|
101
|
|
|
|
102
|
+ @Override
|
|
|
103
|
+ @Transactional
|
|
|
104
|
+ public IdentityAuthentication selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication) {
|
|
|
105
|
+ 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
|
+ GetEidResultResponse respIdenAuth = clientIdenAuth.GetEidResult(reqest);
|
|
|
124
|
+ String respJSON = GetEidResultResponse.toJsonString(respIdenAuth);
|
|
|
125
|
+ JSONObject objJSON = JSON.parseObject(respJSON);
|
|
|
126
|
+ JSONObject objText = JSON.parseObject(objJSON.getString("Text"));
|
|
|
127
|
+ String name = objText.getString("OcrName");
|
|
|
128
|
+// IdentityAuthenticationRespon.setName(name);
|
|
|
129
|
+ String identityNo = objText.getString("OcrIdCard");
|
|
|
130
|
+// IdentityAuthenticationRespon.setIdentityNo(identityNo);
|
|
|
131
|
+ IdentityAuthenticationRespon.setCertificationStatus(1);
|
|
|
132
|
+ IdentityAuthenticationRespon.setUserName(userName);
|
|
|
133
|
+ IdentityAuthenticationRespon.setUserId(userId);
|
|
|
134
|
+
|
|
|
135
|
+ JSONObject objEidInfo = JSON.parseObject(objJSON.getString("EidInfo"));
|
|
|
136
|
+ String desKey = objEidInfo.getString("DesKey");
|
|
|
137
|
+ String uerInfo = objEidInfo.getString("UserInfo");
|
|
|
138
|
+ Map<String,String> mapEidInfo = decodeEidInfo(desKey,uerInfo);
|
|
|
139
|
+ IdentityAuthenticationRespon.setName(mapEidInfo.get("name"));
|
|
|
140
|
+ IdentityAuthenticationRespon.setIdentityNo(mapEidInfo.get("identityNo"));
|
|
|
141
|
+
|
|
|
142
|
+ identityAuthenticationMapper.insertIdentityAuthentication(IdentityAuthenticationRespon);
|
|
|
143
|
+// IdentityAuthenticationResult.setUserName(userName);
|
|
|
144
|
+ IdentityAuthenticationResult.setCertificationStatus(1);
|
|
|
145
|
+ IdentityAuthenticationResult.setCertificationStatusName("认证成功");
|
|
|
146
|
+// IdentityAuthenticationResult.setName(name);
|
|
|
147
|
+// IdentityAuthenticationResult.setIdentityNo(identityNo);
|
|
|
148
|
+ System.out.println(GetEidResultResponse.toJsonString(respIdenAuth));
|
|
|
149
|
+ } catch (TencentCloudSDKException e) {
|
|
|
150
|
+ log.error("认证失败:", e);
|
|
|
151
|
+ throw new RuntimeException("认证失败");
|
|
|
152
|
+ }
|
|
|
153
|
+
|
|
|
154
|
+ }
|
|
|
155
|
+ return IdentityAuthenticationResult;
|
|
|
156
|
+ }
|
|
|
157
|
+
|
|
|
158
|
+ private Map<String, String> decodeEidInfo(String desKey, String uerInfo) {
|
|
|
159
|
+ Map<String, String> mapEidInfo = new HashMap<>();
|
|
|
160
|
+ byte[] deskeybyts = Base64.getDecoder().decode(desKey);
|
|
|
161
|
+ final SM2 sm2crypt = new SM2(privateKeyHexDecodeinfo, null, null);
|
|
|
162
|
+ sm2crypt.usePlainEncoding();
|
|
|
163
|
+ byte[] sm4keybys = sm2crypt.decrypt(deskeybyts);
|
|
|
164
|
+ SymmetricCrypto sm4dcrypt = SmUtil.sm4(sm4keybys);
|
|
|
165
|
+ byte[] uerInfobytes = sm4dcrypt.decrypt(Base64.getDecoder().decode(uerInfo));
|
|
|
166
|
+ JSONObject objuerInfo = JSON.parseObject(new String(uerInfobytes));
|
|
|
167
|
+ String name = objuerInfo.getString("name");
|
|
|
168
|
+ mapEidInfo.put("name",name);
|
|
|
169
|
+ String idtype = objuerInfo.getString("idtype");
|
|
|
170
|
+ mapEidInfo.put("identitytype",idtype);
|
|
|
171
|
+ String idnum = objuerInfo.getString("idnum");
|
|
|
172
|
+ mapEidInfo.put("identityNo",idnum);
|
|
|
173
|
+ return mapEidInfo;
|
|
|
174
|
+ }
|
|
|
175
|
+
|
|
93
|
176
|
|
|
94
|
177
|
}
|