Преглед изворни кода

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

bgy пре 2 година
родитељ
комит
b89a6ea218

+ 14
- 20
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java Прегледај датотеку

22
 
22
 
23
 /**
23
 /**
24
  * 登录验证
24
  * 登录验证
25
- * 
25
+ *
26
  * @author ruoyi
26
  * @author ruoyi
27
  */
27
  */
28
 @RestController
28
 @RestController
29
-public class SysLoginController
30
-{
29
+public class SysLoginController {
31
     @Autowired
30
     @Autowired
32
     private SysLoginService loginService;
31
     private SysLoginService loginService;
33
 
32
 
37
     @Autowired
36
     @Autowired
38
     private SysPermissionService permissionService;
37
     private SysPermissionService permissionService;
39
     @Autowired
38
     @Autowired
40
-    private IdentityAuthenticationService identityAuthenticationService;
39
+    IdentityAuthenticationService identityAuthenticationService;
41
 
40
 
42
     /**
41
     /**
43
      * 登录方法
42
      * 登录方法
44
-     * 
43
+     *
45
      * @param loginBody 登录信息
44
      * @param loginBody 登录信息
46
      * @return 结果
45
      * @return 结果
47
      */
46
      */
48
     @PostMapping("/login")
47
     @PostMapping("/login")
49
-    public AjaxResult login(@RequestBody LoginBody loginBody)
50
-    {
48
+    public AjaxResult login(@RequestBody LoginBody loginBody) {
51
         AjaxResult ajax = AjaxResult.success();
49
         AjaxResult ajax = AjaxResult.success();
52
         // 生成令牌
50
         // 生成令牌
53
         String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
51
         String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
54
                 loginBody.getUuid());
52
                 loginBody.getUuid());
55
         ajax.put(Constants.TOKEN, token);
53
         ajax.put(Constants.TOKEN, token);
56
-
57
-//        IdentityAuthentication identityAuthentication = new IdentityAuthentication();
58
-//        identityAuthentication.setUserName(loginBody.getUsername());
59
-//        IdentityAuthentication identityAuthenticationselect = identityAuthenticationService.selectIdentityAuthentication(identityAuthentication);
60
-//        ajax.put("certificationStatusName", identityAuthenticationselect.getCertificationStatusName());
61
-//        ajax.put("certificationStatus", identityAuthenticationselect.getCertificationStatus());
62
-
54
+        //判断该用户是否已经实名认证(certificationStatus1已认证0未认证)
55
+        IdentityAuthentication identityAuthentication=new IdentityAuthentication();
56
+        identityAuthentication.setUserName(loginBody.getUsername());
57
+        String status = identityAuthenticationService.checkIsAuthentication(identityAuthentication);
58
+        ajax.put("certificationStatus", status);
63
         return ajax;
59
         return ajax;
64
     }
60
     }
65
 
61
 
66
     /**
62
     /**
67
      * 获取用户信息
63
      * 获取用户信息
68
-     * 
64
+     *
69
      * @return 用户信息
65
      * @return 用户信息
70
      */
66
      */
71
     @GetMapping("getInfo")
67
     @GetMapping("getInfo")
72
-    public AjaxResult getInfo()
73
-    {
68
+    public AjaxResult getInfo() {
74
         SysUser user = SecurityUtils.getLoginUser().getUser();
69
         SysUser user = SecurityUtils.getLoginUser().getUser();
75
         // 角色集合
70
         // 角色集合
76
         Set<String> roles = permissionService.getRolePermission(user);
71
         Set<String> roles = permissionService.getRolePermission(user);
85
 
80
 
86
     /**
81
     /**
87
      * 获取路由信息
82
      * 获取路由信息
88
-     * 
83
+     *
89
      * @return 路由信息
84
      * @return 路由信息
90
      */
85
      */
91
     @GetMapping("getRouters")
86
     @GetMapping("getRouters")
92
-    public AjaxResult getRouters()
93
-    {
87
+    public AjaxResult getRouters() {
94
         Long userId = SecurityUtils.getUserId();
88
         Long userId = SecurityUtils.getUserId();
95
         List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId);
89
         List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId);
96
         return AjaxResult.success(menuService.buildMenus(menus));
90
         return AjaxResult.success(menuService.buildMenus(menus));

+ 10
- 23
ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/IdentityAuthenticationController.java Прегледај датотеку

1
 package com.ruoyi.web.controller.wisdomarbitrate;
1
 package com.ruoyi.web.controller.wisdomarbitrate;
2
 
2
 
3
+import com.alibaba.fastjson.JSONObject;
3
 import com.ruoyi.common.core.controller.BaseController;
4
 import com.ruoyi.common.core.controller.BaseController;
4
 import com.ruoyi.common.core.domain.AjaxResult;
5
 import com.ruoyi.common.core.domain.AjaxResult;
5
-import com.ruoyi.wisdomarbitrate.domain.CaseApplication;
6
 import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication;
6
 import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication;
7
 import com.ruoyi.wisdomarbitrate.service.IdentityAuthenticationService;
7
 import com.ruoyi.wisdomarbitrate.service.IdentityAuthenticationService;
8
 import org.springframework.beans.factory.annotation.Autowired;
8
 import org.springframework.beans.factory.annotation.Autowired;
14
 
14
 
15
 @RestController
15
 @RestController
16
 @RequestMapping("/identityAuthentication")
16
 @RequestMapping("/identityAuthentication")
17
-public class IdentityAuthenticationController   extends BaseController {
17
+public class IdentityAuthenticationController extends BaseController {
18
     @Autowired
18
     @Autowired
19
     private IdentityAuthenticationService identityAuthenticationService;
19
     private IdentityAuthenticationService identityAuthenticationService;
20
 
20
 
21
     /**
21
     /**
22
-     * 查询身份认证EIDtoken
22
+     * 获取EIDtoken
23
      */
23
      */
24
     @PostMapping("/selectIdentityAuthenticaEIDtoken")
24
     @PostMapping("/selectIdentityAuthenticaEIDtoken")
25
-    public AjaxResult selectIdentityAuthenticaEIDtoken()
26
-    {
27
-        IdentityAuthentication ientityAuthentication = identityAuthenticationService.selectIdentityAuthenticaEIDtoken();
28
-        return success(ientityAuthentication);
25
+    public AjaxResult selectIdentityAuthenticaEIDtoken() {
26
+        JSONObject tokenResult = identityAuthenticationService.selectIdentityAuthenticaEIDtoken();
27
+        return success(tokenResult);
29
     }
28
     }
30
 
29
 
31
     /**
30
     /**
32
-     * 查询身份认证结果
31
+     * 小程序人脸核身后查询身份认证结果
33
      */
32
      */
34
     @PostMapping("/selectIdentityAuthenticaRespon")
33
     @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);
34
+    public AjaxResult selectIdentityAuthenticaRespon(@Validated @RequestBody IdentityAuthentication ientityAuthentication) {
35
+        AjaxResult checkResult = identityAuthenticationService.selectIdentityAuthenticaRespon(ientityAuthentication);
36
+        return checkResult;
43
     }
37
     }
44
 
38
 
45
 
39
 
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
 }
40
 }

+ 1
- 1
ruoyi-admin/src/main/resources/application.yml Прегледај датотеку

166
   credentialSecretId: AKID3xfHgroY4MQHvLXUXMwIQL1UjmbBX1Tv
166
   credentialSecretId: AKID3xfHgroY4MQHvLXUXMwIQL1UjmbBX1Tv
167
   credentialSecretKey: INDrIXcT8YmomZBcsy0oNirnU0LTN4X7
167
   credentialSecretKey: INDrIXcT8YmomZBcsy0oNirnU0LTN4X7
168
   merchantId: 0NSJ2309281116194321
168
   merchantId: 0NSJ2309281116194321
169
-  privateKeyHexDecodeinfo: MHcCAQEEIEw7MRv3uYlpmU6Fko4GlXSh6Vd38k0cUQZ5zDwvRg+voAoGCCqBHM9VAYItoUQDQgAEUdxIAWhGg4LUXf1GoPdb8XMbGudpexPQCuaaRi9BCnNbpaF1kcwRhhsBKvop9ZmW/nOz4wQ1r/iIEOrc9qCXgQ==
169
+  privateKeyHexDecodeinfo: 4c3b311bf7b98969994e85928e069574a1e95777f24d1c510679cc3c2f460faf

+ 10
- 10
ruoyi-common/pom.xml Прегледај датотеку

52
             <groupId>org.apache.commons</groupId>
52
             <groupId>org.apache.commons</groupId>
53
             <artifactId>commons-lang3</artifactId>
53
             <artifactId>commons-lang3</artifactId>
54
         </dependency>
54
         </dependency>
55
-  
55
+
56
         <!-- JSON工具类 -->
56
         <!-- JSON工具类 -->
57
         <dependency>
57
         <dependency>
58
             <groupId>com.fasterxml.jackson.core</groupId>
58
             <groupId>com.fasterxml.jackson.core</groupId>
59
             <artifactId>jackson-databind</artifactId>
59
             <artifactId>jackson-databind</artifactId>
60
         </dependency>
60
         </dependency>
61
-        
61
+
62
         <!-- 动态数据源 -->
62
         <!-- 动态数据源 -->
63
-		<dependency>
64
-			<groupId>com.baomidou</groupId>
65
-			<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
66
-			<version>3.5.2</version>
67
-		</dependency>
63
+        <dependency>
64
+            <groupId>com.baomidou</groupId>
65
+            <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
66
+            <version>3.5.2</version>
67
+        </dependency>
68
 
68
 
69
         <!-- 阿里JSON解析器 -->
69
         <!-- 阿里JSON解析器 -->
70
         <dependency>
70
         <dependency>
136
         <dependency>
136
         <dependency>
137
             <groupId>com.tencentcloudapi</groupId>
137
             <groupId>com.tencentcloudapi</groupId>
138
             <artifactId>tencentcloud-sdk-java</artifactId>
138
             <artifactId>tencentcloud-sdk-java</artifactId>
139
-            <version>3.1.270</version>
139
+            <version>3.1.876</version>
140
         </dependency>
140
         </dependency>
141
 
141
 
142
         <dependency>
142
         <dependency>
143
             <groupId>com.tencentcloudapi</groupId>
143
             <groupId>com.tencentcloudapi</groupId>
144
             <artifactId>tencentcloud-sdk-java-faceid</artifactId>
144
             <artifactId>tencentcloud-sdk-java-faceid</artifactId>
145
-            <version>3.1.871</version>
145
+            <version>3.1.875</version>
146
         </dependency>
146
         </dependency>
147
-
147
+        <!--用户信息解密-->
148
         <dependency>
148
         <dependency>
149
             <groupId>cn.hutool</groupId>
149
             <groupId>cn.hutool</groupId>
150
             <artifactId>hutool-all</artifactId>
150
             <artifactId>hutool-all</artifactId>

+ 23
- 4
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/IdentityAuthenticationService.java Прегледај датотеку

1
 package com.ruoyi.wisdomarbitrate.service;
1
 package com.ruoyi.wisdomarbitrate.service;
2
 
2
 
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.ruoyi.common.core.domain.AjaxResult;
3
 import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication;
5
 import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication;
4
-import com.tencentcloudapi.common.exception.TencentCloudSDKException;
5
 
6
 
6
 public interface IdentityAuthenticationService {
7
 public interface IdentityAuthenticationService {
7
 
8
 
8
 
9
 
9
-    IdentityAuthentication  selectIdentityAuthentication(IdentityAuthentication identityAuthentication);
10
+    IdentityAuthentication selectIdentityAuthentication(IdentityAuthentication identityAuthentication);
10
 
11
 
12
+    /**
13
+     * 检查是否已经认证的用户
14
+     *
15
+     * @param identityAuthentication
16
+     * @return
17
+     */
18
+    String checkIsAuthentication(IdentityAuthentication identityAuthentication);
11
 
19
 
12
-    IdentityAuthentication selectIdentityAuthenticaEIDtoken();
20
+    /**
21
+     * 获取Eidtoken
22
+     *
23
+     * @return
24
+     */
25
+    JSONObject selectIdentityAuthenticaEIDtoken();
13
 
26
 
14
-    IdentityAuthentication selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication);
27
+    /**
28
+     * 小程序人脸核身后查询身份认证结果
29
+     *
30
+     * @param ientityAuthentication
31
+     * @return
32
+     */
33
+    AjaxResult selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication);
15
 }
34
 }

+ 151
- 85
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/IdentityAuthenticationServiceImpl.java Прегледај датотеку

1
 package com.ruoyi.wisdomarbitrate.service.impl;
1
 package com.ruoyi.wisdomarbitrate.service.impl;
2
 
2
 
3
 
3
 
4
-
4
+import cn.hutool.core.codec.Base64;
5
 import cn.hutool.crypto.SmUtil;
5
 import cn.hutool.crypto.SmUtil;
6
 import cn.hutool.crypto.asymmetric.SM2;
6
 import cn.hutool.crypto.asymmetric.SM2;
7
 import cn.hutool.crypto.symmetric.SymmetricCrypto;
7
 import cn.hutool.crypto.symmetric.SymmetricCrypto;
8
 import com.alibaba.fastjson.JSON;
8
 import com.alibaba.fastjson.JSON;
9
 import com.alibaba.fastjson.JSONObject;
9
 import com.alibaba.fastjson.JSONObject;
10
 import com.ruoyi.common.core.domain.AjaxResult;
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
 import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication;
13
 import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication;
14
 import com.ruoyi.wisdomarbitrate.mapper.IdentityAuthenticationMapper;
14
 import com.ruoyi.wisdomarbitrate.mapper.IdentityAuthenticationMapper;
15
-import com.ruoyi.wisdomarbitrate.service.ICaseApplicationService;
16
 import com.ruoyi.wisdomarbitrate.service.IdentityAuthenticationService;
15
 import com.ruoyi.wisdomarbitrate.service.IdentityAuthenticationService;
17
-
18
 import com.tencentcloudapi.common.Credential;
16
 import com.tencentcloudapi.common.Credential;
17
+import com.tencentcloudapi.common.exception.TencentCloudSDKException;
19
 import com.tencentcloudapi.common.profile.ClientProfile;
18
 import com.tencentcloudapi.common.profile.ClientProfile;
20
 import com.tencentcloudapi.common.profile.HttpProfile;
19
 import com.tencentcloudapi.common.profile.HttpProfile;
21
-import com.tencentcloudapi.common.exception.TencentCloudSDKException;
22
 import com.tencentcloudapi.faceid.v20180301.FaceidClient;
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
 import org.slf4j.Logger;
25
 import org.slf4j.Logger;
26
 import org.slf4j.LoggerFactory;
26
 import org.slf4j.LoggerFactory;
27
 import org.springframework.beans.factory.annotation.Autowired;
27
 import org.springframework.beans.factory.annotation.Autowired;
29
 import org.springframework.stereotype.Service;
29
 import org.springframework.stereotype.Service;
30
 import org.springframework.transaction.annotation.Transactional;
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
 @Service
34
 @Service
40
-public class IdentityAuthenticationServiceImpl  implements IdentityAuthenticationService {
35
+public class IdentityAuthenticationServiceImpl implements IdentityAuthenticationService {
41
 
36
 
42
     @Value("${identityAuthentication.credentialSecretId}")
37
     @Value("${identityAuthentication.credentialSecretId}")
43
     private String credentialSecretId;
38
     private String credentialSecretId;
58
     @Override
53
     @Override
59
     public IdentityAuthentication selectIdentityAuthentication(IdentityAuthentication identityAuthentication) {
54
     public IdentityAuthentication selectIdentityAuthentication(IdentityAuthentication identityAuthentication) {
60
         IdentityAuthentication identityAuthenticationselect = identityAuthenticationMapper.selectIdentityAuthentication(identityAuthentication);
55
         IdentityAuthentication identityAuthenticationselect = identityAuthenticationMapper.selectIdentityAuthentication(identityAuthentication);
61
-        if(identityAuthenticationselect!=null){
56
+        if (identityAuthenticationselect != null) {
62
             identityAuthenticationselect.setCertificationStatusName("已身份认证");
57
             identityAuthenticationselect.setCertificationStatusName("已身份认证");
63
-        }else {
58
+        } else {
64
             IdentityAuthentication identityAuthenticationselectnew = new IdentityAuthentication();
59
             IdentityAuthentication identityAuthenticationselectnew = new IdentityAuthentication();
65
             identityAuthenticationselectnew.setCertificationStatusName("未身份认证");
60
             identityAuthenticationselectnew.setCertificationStatusName("未身份认证");
66
             identityAuthenticationselectnew.setCertificationStatus(0);
61
             identityAuthenticationselectnew.setCertificationStatus(0);
70
 
65
 
71
     }
66
     }
72
 
67
 
68
+    /**
69
+     * 检查是否已经认证的用户
70
+     *
71
+     * @param identityAuthentication
72
+     * @return
73
+     */
73
     @Override
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
     @Override
146
     @Override
103
     @Transactional
147
     @Transactional
104
-    public IdentityAuthentication selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication) {
148
+    public AjaxResult selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication) {
105
         String eidToken = ientityAuthentication.getEidToken();
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
 }