Przeglądaj źródła

Merge branch 'qtz' of SH-Arbitrate/Arbitrate-Backend into dev

qtz 2 lat temu
rodzic
commit
66ac29f692

+ 14
- 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/IdentityAuthenticationController.java Wyświetl plik

@@ -28,6 +28,20 @@ public class IdentityAuthenticationController   extends BaseController {
28 28
         return success(ientityAuthentication);
29 29
     }
30 30
 
31
+    /**
32
+     * 查询身份认证结果
33
+     */
34
+    @PostMapping("/selectIdentityAuthenticaRespon")
35
+    public AjaxResult selectIdentityAuthenticaRespon(@Validated @RequestBody IdentityAuthentication ientityAuthentication)
36
+    {
37
+        String username = this.getUsername();
38
+        Long userId = this.getUserId();
39
+        ientityAuthentication.setUserId(userId);
40
+        ientityAuthentication.setUserName(username);
41
+        IdentityAuthentication ientityAuthenticationRes = identityAuthenticationService.selectIdentityAuthenticaRespon( ientityAuthentication);
42
+        return success(ientityAuthenticationRes);
43
+    }
44
+
31 45
 
32 46
 
33 47
 

+ 4
- 3
ruoyi-admin/src/main/resources/application.yml Wyświetl plik

@@ -158,6 +158,7 @@ elegent:
158 158
       watch: true
159 159
       cycle: 10
160 160
 identityAuthentication:
161
-  credentialSecretId: 123
162
-  credentialSecretKey: 367
163
-  merchantId: 356
161
+  credentialSecretId: AKID3xfHgroY4MQHvLXUXMwIQL1UjmbBX1Tv
162
+  credentialSecretKey: INDrIXcT8YmomZBcsy0oNirnU0LTN4X7
163
+  merchantId: 0NSJ2309281116194321
164
+  privateKeyHexDecodeinfo: MHcCAQEEIEw7MRv3uYlpmU6Fko4GlXSh6Vd38k0cUQZ5zDwvRg+voAoGCCqBHM9VAYItoUQDQgAEUdxIAWhGg4LUXf1GoPdb8XMbGudpexPQCuaaRi9BCnNbpaF1kcwRhhsBKvop9ZmW/nOz4wQ1r/iIEOrc9qCXgQ==

+ 12
- 0
ruoyi-common/pom.xml Wyświetl plik

@@ -145,6 +145,18 @@
145 145
             <version>3.1.871</version>
146 146
         </dependency>
147 147
 
148
+        <dependency>
149
+            <groupId>cn.hutool</groupId>
150
+            <artifactId>hutool-all</artifactId>
151
+            <version>5.7.15</version>
152
+        </dependency>
153
+
154
+        <dependency>
155
+            <groupId>org.bouncycastle</groupId>
156
+            <artifactId>bcprov-jdk15to18</artifactId>
157
+            <version>1.69</version>
158
+        </dependency>
159
+
148 160
         <!-- poi-tl-->
149 161
         <dependency>
150 162
             <groupId>com.deepoove</groupId>

+ 2
- 0
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/IdentityAuthenticationService.java Wyświetl plik

@@ -10,4 +10,6 @@ public interface IdentityAuthenticationService {
10 10
 
11 11
 
12 12
     IdentityAuthentication selectIdentityAuthenticaEIDtoken();
13
+
14
+    IdentityAuthentication selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication);
13 15
 }

+ 90
- 7
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/IdentityAuthenticationServiceImpl.java Wyświetl plik

@@ -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
 }

+ 3
- 3
ruoyi-system/src/main/resources/mapper/wisdomarbitrate/IdentityAuthenticationMapper.xml Wyświetl plik

@@ -19,7 +19,7 @@
19 19
         <if test="userId != null">user_id,</if>
20 20
         <if test="name != null and name != ''">name,</if>
21 21
         <if test="identityNo != null and identityNo != ''">identity_no,</if>
22
-        <if test="certificationTime != null and certificationTime != ''">certification_time,</if>
22
+        certification_time,
23 23
         <if test="certificationStatus != null and certificationStatus != ''">certification_status,</if>
24 24
         <if test="userName != null and userName != ''">user_name,</if>
25 25
         <if test="createBy != null  and createBy != ''">create_by,</if>
@@ -28,8 +28,8 @@
28 28
         <if test="userId != null ">#{userId},</if>
29 29
         <if test="name != null and name != ''">#{name},</if>
30 30
         <if test="identityNo != null and identityNo != ''">#{identityNo},</if>
31
-        <if test="certificationTime != null and certificationTime != ''">#{certificationTime},</if>
32
-        <if test="certificationStatus != null and certificationStatus != ''">#{certificationStatus},</if>
31
+        sysdate(),
32
+        <if test="certificationStatus != null ">#{certificationStatus},</if>
33 33
         <if test="userName != null and userName != ''">#{userName},</if>
34 34
         <if test="createBy != null  and createBy != ''">#{createBy},</if>
35 35
         sysdate()