From 9aa2ff00eb1697e943d1d0cadc812d4a23a60627 Mon Sep 17 00:00:00 2001 From: gy b Date: Wed, 11 Oct 2023 12:21:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=85=BE=E8=AE=AF?= =?UTF-8?q?=E4=BA=BA=E8=84=B8=E6=A0=B8=E8=BA=AB=E7=9B=B8=E5=85=B3=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IdentityAuthenticationController.java | 21 +-- ruoyi-common/pom.xml | 4 +- .../IdentityAuthenticationService.java | 20 ++- .../IdentityAuthenticationServiceImpl.java | 147 +++++++----------- 4 files changed, 85 insertions(+), 107 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/IdentityAuthenticationController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/IdentityAuthenticationController.java index f097a64..66fedb3 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/IdentityAuthenticationController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/IdentityAuthenticationController.java @@ -1,5 +1,6 @@ package com.ruoyi.web.controller.wisdomarbitrate; +import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.wisdomarbitrate.domain.CaseApplication; @@ -19,27 +20,27 @@ public class IdentityAuthenticationController extends BaseController { private IdentityAuthenticationService identityAuthenticationService; /** - * 查询身份认证EIDtoken + * 获取EIDtoken */ @PostMapping("/selectIdentityAuthenticaEIDtoken") public AjaxResult selectIdentityAuthenticaEIDtoken() { - IdentityAuthentication ientityAuthentication = identityAuthenticationService.selectIdentityAuthenticaEIDtoken(); - return success(ientityAuthentication); + JSONObject tokenResult = identityAuthenticationService.selectIdentityAuthenticaEIDtoken(); + return success(tokenResult); } /** - * 查询身份认证结果 + * 小程序人脸核身后查询身份认证结果 */ @PostMapping("/selectIdentityAuthenticaRespon") public AjaxResult selectIdentityAuthenticaRespon(@Validated @RequestBody IdentityAuthentication ientityAuthentication) { - String username = this.getUsername(); - Long userId = this.getUserId(); - ientityAuthentication.setUserId(userId); - ientityAuthentication.setUserName(username); - IdentityAuthentication ientityAuthenticationRes = identityAuthenticationService.selectIdentityAuthenticaRespon( ientityAuthentication); - return success(ientityAuthenticationRes); +// String username = this.getUsername(); +// Long userId = this.getUserId(); +// ientityAuthentication.setUserId(userId); +// ientityAuthentication.setUserName(username); + JSONObject checkResult = identityAuthenticationService.selectIdentityAuthenticaRespon( ientityAuthentication); + return success(checkResult); } diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml index 77e53b1..206e38a 100644 --- a/ruoyi-common/pom.xml +++ b/ruoyi-common/pom.xml @@ -136,13 +136,13 @@ com.tencentcloudapi tencentcloud-sdk-java - 3.1.270 + 3.1.876 com.tencentcloudapi tencentcloud-sdk-java-faceid - 3.1.871 + 3.1.875 diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/IdentityAuthenticationService.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/IdentityAuthenticationService.java index 3748942..b98d66b 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/IdentityAuthenticationService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/IdentityAuthenticationService.java @@ -1,15 +1,25 @@ package com.ruoyi.wisdomarbitrate.service; +import com.alibaba.fastjson.JSONObject; import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication; -import com.tencentcloudapi.common.exception.TencentCloudSDKException; public interface IdentityAuthenticationService { - IdentityAuthentication selectIdentityAuthentication(IdentityAuthentication identityAuthentication); + IdentityAuthentication selectIdentityAuthentication(IdentityAuthentication identityAuthentication); + /** + * 获取Eidtoken + * + * @return + */ + JSONObject selectIdentityAuthenticaEIDtoken(); - IdentityAuthentication selectIdentityAuthenticaEIDtoken(); - - IdentityAuthentication selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication); + /** + * 小程序人脸核身后查询身份认证结果 + * + * @param ientityAuthentication + * @return + */ + JSONObject selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/IdentityAuthenticationServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/IdentityAuthenticationServiceImpl.java index 5d56387..f8686ed 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/IdentityAuthenticationServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/IdentityAuthenticationServiceImpl.java @@ -1,27 +1,22 @@ package com.ruoyi.wisdomarbitrate.service.impl; - -import cn.hutool.crypto.SmUtil; -import cn.hutool.crypto.asymmetric.SM2; -import cn.hutool.crypto.symmetric.SymmetricCrypto; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.exceptions.TradeException; import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication; import com.ruoyi.wisdomarbitrate.mapper.IdentityAuthenticationMapper; -import com.ruoyi.wisdomarbitrate.service.ICaseApplicationService; import com.ruoyi.wisdomarbitrate.service.IdentityAuthenticationService; - import com.tencentcloudapi.common.Credential; +import com.tencentcloudapi.common.exception.TencentCloudSDKException; import com.tencentcloudapi.common.profile.ClientProfile; import com.tencentcloudapi.common.profile.HttpProfile; -import com.tencentcloudapi.common.exception.TencentCloudSDKException; import com.tencentcloudapi.faceid.v20180301.FaceidClient; -import com.tencentcloudapi.faceid.v20180301.models.*; - +import com.tencentcloudapi.faceid.v20180301.models.GetEidResultRequest; +import com.tencentcloudapi.faceid.v20180301.models.GetEidResultResponse; +import com.tencentcloudapi.faceid.v20180301.models.GetEidTokenRequest; +import com.tencentcloudapi.faceid.v20180301.models.GetEidTokenResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -29,15 +24,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Base64; -import java.util.HashMap; -import java.util.Map; - @Service -public class IdentityAuthenticationServiceImpl implements IdentityAuthenticationService { +public class IdentityAuthenticationServiceImpl implements IdentityAuthenticationService { @Value("${identityAuthentication.credentialSecretId}") private String credentialSecretId; @@ -58,9 +46,9 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthenticatio @Override public IdentityAuthentication selectIdentityAuthentication(IdentityAuthentication identityAuthentication) { IdentityAuthentication identityAuthenticationselect = identityAuthenticationMapper.selectIdentityAuthentication(identityAuthentication); - if(identityAuthenticationselect!=null){ + if (identityAuthenticationselect != null) { identityAuthenticationselect.setCertificationStatusName("已身份认证"); - }else { + } else { IdentityAuthentication identityAuthenticationselectnew = new IdentityAuthentication(); identityAuthenticationselectnew.setCertificationStatusName("未身份认证"); identityAuthenticationselectnew.setCertificationStatus(0); @@ -71,85 +59,64 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthenticatio } @Override - public IdentityAuthentication selectIdentityAuthenticaEIDtoken() { - IdentityAuthentication identityAuthentication = new IdentityAuthentication(); - try{ - Credential authenti = new Credential(credentialSecretId, credentialSecretKey); - HttpProfile httpProfileIdenAuth = new HttpProfile(); - httpProfileIdenAuth.setEndpoint("faceid.tencentcloudapi.com"); - ClientProfile clientInv= new ClientProfile(); - clientInv.setHttpProfile(httpProfileIdenAuth); - FaceidClient clientIdenAuth = new FaceidClient(authenti, "", clientInv); - // 实例化一个请求对象 - GetEidTokenRequest reqest = new GetEidTokenRequest(); - //设置请求参数 - reqest.setMerchantId(merchantId); - GetEidTokenResponse respIdenAuth = clientIdenAuth.GetEidToken(reqest); - String respJSON = GetEidTokenResponse.toJsonString(respIdenAuth); - JSONObject objJSON = JSON.parseObject(respJSON); - String eidToken = objJSON.getString("EidToken"); - String requestId = objJSON.getString("RequestId"); - identityAuthentication.setEidToken(eidToken); - }catch (TencentCloudSDKException e) { - log.error("获取Eidtoke异常:", e); - throw new RuntimeException("获取Eidtoke异常"); + public JSONObject selectIdentityAuthenticaEIDtoken() { + JSONObject objJSON = new JSONObject(); + objJSON.put("EidToken", ""); + try { + Credential cred = new Credential(credentialSecretId, credentialSecretKey); + // 实例化一个http选项,可选的,没有特殊需求可以跳过 + HttpProfile httpProfile = new HttpProfile(); + httpProfile.setEndpoint("faceid.tencentcloudapi.com"); + // 实例化一个client选项,可选的,没有特殊需求可以跳过 + ClientProfile clientProfile = new ClientProfile(); + clientProfile.setHttpProfile(httpProfile); + // 实例化要请求产品的client对象,clientProfile是可选的 + FaceidClient client = new FaceidClient(cred, "", clientProfile); + // 实例化一个请求对象,每个接口都会对应一个request对象 + GetEidTokenRequest req = new GetEidTokenRequest(); + // 返回的resp是一个GetEidTokenResponse的实例,与请求对象对应 + GetEidTokenResponse resp = client.GetEidToken(req); + // 输出json格式的字符串回包 + System.out.println(GetEidTokenResponse.toJsonString(resp)); + String respJSON = GetEidTokenResponse.toJsonString(resp); + objJSON = JSON.parseObject(respJSON); + } catch (TencentCloudSDKException e) { + System.out.println(e.toString()); + System.out.println("获取Eidtoken失败"); } - - return identityAuthentication; - + return objJSON; } @Override @Transactional - public IdentityAuthentication selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication) { + public JSONObject selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication) { String eidToken = ientityAuthentication.getEidToken(); - Long userId = ientityAuthentication.getUserId(); - String userName = ientityAuthentication.getUserName(); - IdentityAuthentication IdentityAuthenticationRespon = new IdentityAuthentication(); - IdentityAuthentication IdentityAuthenticationResult = new IdentityAuthentication(); - if(StringUtils.isNotEmpty(eidToken)){ - try{ - Credential authenti = new Credential(credentialSecretId, credentialSecretKey); - HttpProfile httpProfileIdenAuth = new HttpProfile(); - httpProfileIdenAuth.setEndpoint("faceid.tencentcloudapi.com"); - ClientProfile clientInv= new ClientProfile(); - clientInv.setHttpProfile(httpProfileIdenAuth); - FaceidClient clientIdenAuth = new FaceidClient(authenti, "", clientInv); - // 实例化一个请求对象 - GetEidResultRequest reqest = new GetEidResultRequest(); - //设置请求参数 - reqest.setEidToken(eidToken); - -// reqest.setInfoType("1"); -// reqest.setInfoType("13"); -// reqest.setInfoType("2"); - - //获得身份认证结果 - GetEidResultResponse respIdenAuth = clientIdenAuth.GetEidResult(reqest); - String respJSON = GetEidResultResponse.toJsonString(respIdenAuth); - JSONObject objJSON = JSON.parseObject(respJSON); - IdentityAuthenticationRespon.setCertificationStatus(1); - IdentityAuthenticationRespon.setUserName(userName); - IdentityAuthenticationRespon.setUserId(userId); - - JSONObject objEidInfo = JSON.parseObject(objJSON.getString("EidInfo")); -// identityAuthenticationMapper.insertIdentityAuthentication(IdentityAuthenticationRespon); - IdentityAuthenticationResult.setCertificationStatus(1); - IdentityAuthenticationResult.setCertificationStatusName("认证成功"); - } catch (TencentCloudSDKException e) { - log.error("认证失败:", e); - throw new RuntimeException("认证失败"); - } + try { + Credential cred = new Credential(credentialSecretId, credentialSecretKey); + // 实例化一个http选项,可选的,没有特殊需求可以跳过 + HttpProfile httpProfile = new HttpProfile(); + httpProfile.setEndpoint("faceid.tencentcloudapi.com"); + // 实例化一个client选项,可选的,没有特殊需求可以跳过 + ClientProfile clientProfile = new ClientProfile(); + clientProfile.setHttpProfile(httpProfile); + // 实例化要请求产品的client对象,clientProfile是可选的 + FaceidClient client = new FaceidClient(cred, "", clientProfile); + // 实例化一个请求对象,每个接口都会对应一个request对象 + GetEidResultRequest req = new GetEidResultRequest(); + req.setEidToken(eidToken); + // 返回的resp是一个GetEidResultResponse的实例,与请求对象对应 + GetEidResultResponse resp = client.GetEidResult(req); + // 输出json格式的字符串回包 + System.out.println(GetEidResultResponse.toJsonString(resp)); + String s = GetEidResultResponse.toJsonString(resp); + JSONObject object = JSON.parseObject(s); + return object; + } catch (TencentCloudSDKException e) { + System.out.println(e.toString()); } - return IdentityAuthenticationResult; + return null; } - - - - - - } From d40fbccf2442f3dd46219b1e6d98ffef2291ffb3 Mon Sep 17 00:00:00 2001 From: gy b Date: Wed, 11 Oct 2023 18:11:32 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BA=BA=E8=84=B8?= =?UTF-8?q?=E6=A0=B8=E8=BA=AB=E8=A7=A3=E5=AF=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/SysLoginController.java | 34 +++--- .../IdentityAuthenticationController.java | 24 +--- .../src/main/resources/application.yml | 2 +- ruoyi-common/pom.xml | 16 +-- .../IdentityAuthenticationService.java | 11 +- .../IdentityAuthenticationServiceImpl.java | 111 +++++++++++++++++- 6 files changed, 143 insertions(+), 55 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java index deef3b5..60633c7 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java @@ -22,12 +22,11 @@ import com.ruoyi.system.service.ISysMenuService; /** * 登录验证 - * + * * @author ruoyi */ @RestController -public class SysLoginController -{ +public class SysLoginController { @Autowired private SysLoginService loginService; @@ -37,40 +36,36 @@ public class SysLoginController @Autowired private SysPermissionService permissionService; @Autowired - private IdentityAuthenticationService identityAuthenticationService; + IdentityAuthenticationService identityAuthenticationService; /** * 登录方法 - * + * * @param loginBody 登录信息 * @return 结果 */ @PostMapping("/login") - public AjaxResult login(@RequestBody LoginBody loginBody) - { + public AjaxResult login(@RequestBody LoginBody loginBody) { AjaxResult ajax = AjaxResult.success(); // 生成令牌 String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), loginBody.getUuid()); ajax.put(Constants.TOKEN, token); - -// IdentityAuthentication identityAuthentication = new IdentityAuthentication(); -// identityAuthentication.setUserName(loginBody.getUsername()); -// IdentityAuthentication identityAuthenticationselect = identityAuthenticationService.selectIdentityAuthentication(identityAuthentication); -// ajax.put("certificationStatusName", identityAuthenticationselect.getCertificationStatusName()); -// ajax.put("certificationStatus", identityAuthenticationselect.getCertificationStatus()); - + //判断该用户是否已经实名认证(certificationStatus1已认证0未认证) + IdentityAuthentication identityAuthentication=new IdentityAuthentication(); + identityAuthentication.setUserName(loginBody.getUsername()); + String status = identityAuthenticationService.checkIsAuthentication(identityAuthentication); + ajax.put("certificationStatus", status); return ajax; } /** * 获取用户信息 - * + * * @return 用户信息 */ @GetMapping("getInfo") - public AjaxResult getInfo() - { + public AjaxResult getInfo() { SysUser user = SecurityUtils.getLoginUser().getUser(); // 角色集合 Set roles = permissionService.getRolePermission(user); @@ -85,12 +80,11 @@ public class SysLoginController /** * 获取路由信息 - * + * * @return 路由信息 */ @GetMapping("getRouters") - public AjaxResult getRouters() - { + public AjaxResult getRouters() { Long userId = SecurityUtils.getUserId(); List menus = menuService.selectMenuTreeByUserId(userId); return AjaxResult.success(menuService.buildMenus(menus)); diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/IdentityAuthenticationController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/IdentityAuthenticationController.java index 66fedb3..7260847 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/IdentityAuthenticationController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/IdentityAuthenticationController.java @@ -3,7 +3,6 @@ package com.ruoyi.web.controller.wisdomarbitrate; import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.wisdomarbitrate.domain.CaseApplication; import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication; import com.ruoyi.wisdomarbitrate.service.IdentityAuthenticationService; import org.springframework.beans.factory.annotation.Autowired; @@ -15,7 +14,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/identityAuthentication") -public class IdentityAuthenticationController extends BaseController { +public class IdentityAuthenticationController extends BaseController { @Autowired private IdentityAuthenticationService identityAuthenticationService; @@ -23,8 +22,7 @@ public class IdentityAuthenticationController extends BaseController { * 获取EIDtoken */ @PostMapping("/selectIdentityAuthenticaEIDtoken") - public AjaxResult selectIdentityAuthenticaEIDtoken() - { + public AjaxResult selectIdentityAuthenticaEIDtoken() { JSONObject tokenResult = identityAuthenticationService.selectIdentityAuthenticaEIDtoken(); return success(tokenResult); } @@ -33,22 +31,10 @@ public class IdentityAuthenticationController extends BaseController { * 小程序人脸核身后查询身份认证结果 */ @PostMapping("/selectIdentityAuthenticaRespon") - public AjaxResult selectIdentityAuthenticaRespon(@Validated @RequestBody IdentityAuthentication ientityAuthentication) - { -// String username = this.getUsername(); -// Long userId = this.getUserId(); -// ientityAuthentication.setUserId(userId); -// ientityAuthentication.setUserName(username); - JSONObject checkResult = identityAuthenticationService.selectIdentityAuthenticaRespon( ientityAuthentication); - return success(checkResult); + public AjaxResult selectIdentityAuthenticaRespon(@Validated @RequestBody IdentityAuthentication ientityAuthentication) { + AjaxResult checkResult = identityAuthenticationService.selectIdentityAuthenticaRespon(ientityAuthentication); + return checkResult; } - - - - - - - } diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 9e15e95..3e9f5c0 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -166,4 +166,4 @@ identityAuthentication: credentialSecretId: AKID3xfHgroY4MQHvLXUXMwIQL1UjmbBX1Tv credentialSecretKey: INDrIXcT8YmomZBcsy0oNirnU0LTN4X7 merchantId: 0NSJ2309281116194321 - privateKeyHexDecodeinfo: MHcCAQEEIEw7MRv3uYlpmU6Fko4GlXSh6Vd38k0cUQZ5zDwvRg+voAoGCCqBHM9VAYItoUQDQgAEUdxIAWhGg4LUXf1GoPdb8XMbGudpexPQCuaaRi9BCnNbpaF1kcwRhhsBKvop9ZmW/nOz4wQ1r/iIEOrc9qCXgQ== \ No newline at end of file + privateKeyHexDecodeinfo: 4c3b311bf7b98969994e85928e069574a1e95777f24d1c510679cc3c2f460faf \ No newline at end of file diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml index 206e38a..b0c399b 100644 --- a/ruoyi-common/pom.xml +++ b/ruoyi-common/pom.xml @@ -52,19 +52,19 @@ org.apache.commons commons-lang3 - + com.fasterxml.jackson.core jackson-databind - + - - com.baomidou - dynamic-datasource-spring-boot-starter - 3.5.2 - + + com.baomidou + dynamic-datasource-spring-boot-starter + 3.5.2 + @@ -144,7 +144,7 @@ tencentcloud-sdk-java-faceid 3.1.875 - + cn.hutool hutool-all diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/IdentityAuthenticationService.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/IdentityAuthenticationService.java index b98d66b..1ae0f29 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/IdentityAuthenticationService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/IdentityAuthenticationService.java @@ -1,6 +1,7 @@ package com.ruoyi.wisdomarbitrate.service; import com.alibaba.fastjson.JSONObject; +import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication; public interface IdentityAuthenticationService { @@ -8,6 +9,14 @@ public interface IdentityAuthenticationService { IdentityAuthentication selectIdentityAuthentication(IdentityAuthentication identityAuthentication); + /** + * 检查是否已经认证的用户 + * + * @param identityAuthentication + * @return + */ + String checkIsAuthentication(IdentityAuthentication identityAuthentication); + /** * 获取Eidtoken * @@ -21,5 +30,5 @@ public interface IdentityAuthenticationService { * @param ientityAuthentication * @return */ - JSONObject selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication); + AjaxResult selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/IdentityAuthenticationServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/IdentityAuthenticationServiceImpl.java index f8686ed..b842f92 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/IdentityAuthenticationServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/IdentityAuthenticationServiceImpl.java @@ -1,10 +1,15 @@ package com.ruoyi.wisdomarbitrate.service.impl; +import cn.hutool.core.codec.Base64; +import cn.hutool.crypto.SmUtil; +import cn.hutool.crypto.asymmetric.SM2; +import cn.hutool.crypto.symmetric.SymmetricCrypto; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.core.domain.model.LoginUser; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication; import com.ruoyi.wisdomarbitrate.mapper.IdentityAuthenticationMapper; import com.ruoyi.wisdomarbitrate.service.IdentityAuthenticationService; @@ -24,6 +29,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Date; + @Service public class IdentityAuthenticationServiceImpl implements IdentityAuthenticationService { @@ -58,6 +65,27 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthentication } + /** + * 检查是否已经认证的用户 + * + * @param identityAuthentication + * @return + */ + @Override + public String checkIsAuthentication(IdentityAuthentication identityAuthentication) { + IdentityAuthentication identityAuthenticationselect = identityAuthenticationMapper.selectIdentityAuthentication(identityAuthentication); + if (identityAuthenticationselect != null) { + return "1"; + } else { + return "0"; + } + } + + /** + * 获取EIDtoken + * + * @return + */ @Override public JSONObject selectIdentityAuthenticaEIDtoken() { JSONObject objJSON = new JSONObject(); @@ -74,10 +102,10 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthentication FaceidClient client = new FaceidClient(cred, "", clientProfile); // 实例化一个请求对象,每个接口都会对应一个request对象 GetEidTokenRequest req = new GetEidTokenRequest(); + req.setMerchantId(merchantId); // 返回的resp是一个GetEidTokenResponse的实例,与请求对象对应 GetEidTokenResponse resp = client.GetEidToken(req); // 输出json格式的字符串回包 - System.out.println(GetEidTokenResponse.toJsonString(resp)); String respJSON = GetEidTokenResponse.toJsonString(resp); objJSON = JSON.parseObject(respJSON); } catch (TencentCloudSDKException e) { @@ -87,9 +115,37 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthentication return objJSON; } + /** + * 解密用户信息 + */ + public JSONObject DecodeUserInfo(String deskey, String userInfo) { + JSONObject parse = null; + try { + byte[] desKeyBytes = Base64.decode(deskey); + final SM2 sm2 = new SM2(privateKeyHexDecodeinfo, null, null); + sm2.usePlainEncoding(); + byte[] sm4KeyBytes = sm2.decrypt(desKeyBytes); + SymmetricCrypto sm4 = SmUtil.sm4(sm4KeyBytes); + byte[] plaintext = sm4.decrypt(Base64.decode(userInfo)); + if (plaintext != null && plaintext.length > 0) { + String s = new String(plaintext); + parse = JSON.parseObject(s); + } + } catch (Exception e) { + System.out.println(e.toString()); + } + return parse; + } + + /** + * 小程序人脸核身后查询身份认证结果 + * + * @param ientityAuthentication + * @return + */ @Override @Transactional - public JSONObject selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication) { + public AjaxResult selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication) { String eidToken = ientityAuthentication.getEidToken(); try { @@ -108,10 +164,53 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthentication // 返回的resp是一个GetEidResultResponse的实例,与请求对象对应 GetEidResultResponse resp = client.GetEidResult(req); // 输出json格式的字符串回包 - System.out.println(GetEidResultResponse.toJsonString(resp)); String s = GetEidResultResponse.toJsonString(resp); - JSONObject object = JSON.parseObject(s); - return object; + JSONObject objJSON = JSON.parseObject(s); + //查看是否核验成功 + JSONObject text = objJSON.getJSONObject("Text"); + if (text != null) { + Integer comparestatus = text.getInteger("Comparestatus"); + if (comparestatus != null && comparestatus == 0) { + JSONObject eidInfo = objJSON.getJSONObject("EidInfo"); + if (eidInfo != null) { + String desKey = eidInfo.getString("DesKey"); + String userInfo = eidInfo.getString("UserInfo"); + //1.解密用户的信息 + JSONObject info = DecodeUserInfo(desKey, userInfo); + if (info != null) { + String idcardno = info.getString("idnum"); + String name = info.getString("name"); + //2.在用户认证表中插入用户认证记录 + LoginUser loginUser = SecurityUtils.getLoginUser(); + IdentityAuthentication authentication = new IdentityAuthentication(); + /** + * 用户名 + * 用户名id + * 姓名 + * 身份证号 + * 认证时间 + * 认证状态0表示成功 + * 请求id + */ + authentication.setUserName(loginUser.getUsername()); + authentication.setUserId(loginUser.getUserId()); + authentication.setName(name); + authentication.setIdentityNo(idcardno); + authentication.setCertificationTime(new Date()); + authentication.setCertificationStatus(0); + authentication.setRequestId(objJSON.getString("RequestId")); + try { + identityAuthenticationMapper.insertIdentityAuthentication(authentication); + } catch (Exception e) { + System.out.println("认证记录新增失败"); + } + + } + + } + } + } + return AjaxResult.success(); } catch (TencentCloudSDKException e) { System.out.println(e.toString()); }