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 1824d89..f097a64 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 @@ -28,6 +28,20 @@ public class IdentityAuthenticationController extends BaseController { return success(ientityAuthentication); } + /** + * 查询身份认证结果 + */ + @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); + } + diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 56c9e74..822641d 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -158,6 +158,7 @@ elegent: watch: true cycle: 10 identityAuthentication: - credentialSecretId: 123 - credentialSecretKey: 367 - merchantId: 356 \ No newline at end of file + credentialSecretId: AKID3xfHgroY4MQHvLXUXMwIQL1UjmbBX1Tv + credentialSecretKey: INDrIXcT8YmomZBcsy0oNirnU0LTN4X7 + merchantId: 0NSJ2309281116194321 + privateKeyHexDecodeinfo: MHcCAQEEIEw7MRv3uYlpmU6Fko4GlXSh6Vd38k0cUQZ5zDwvRg+voAoGCCqBHM9VAYItoUQDQgAEUdxIAWhGg4LUXf1GoPdb8XMbGudpexPQCuaaRi9BCnNbpaF1kcwRhhsBKvop9ZmW/nOz4wQ1r/iIEOrc9qCXgQ== \ No newline at end of file diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml index c327de4..3b55c2b 100644 --- a/ruoyi-common/pom.xml +++ b/ruoyi-common/pom.xml @@ -145,6 +145,18 @@ 3.1.871 + + cn.hutool + hutool-all + 5.7.15 + + + + org.bouncycastle + bcprov-jdk15to18 + 1.69 + + com.deepoove 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 9b362a2..3748942 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 @@ -10,4 +10,6 @@ public interface IdentityAuthenticationService { IdentityAuthentication selectIdentityAuthenticaEIDtoken(); + + IdentityAuthentication 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 08ca024..b76fcda 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 @@ -2,9 +2,14 @@ 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; @@ -14,6 +19,8 @@ import com.tencentcloudapi.common.exception.TencentCloudSDKException; import com.tencentcloudapi.common.profile.ClientProfile; import com.tencentcloudapi.common.profile.HttpProfile; import com.tencentcloudapi.faceid.v20180301.FaceidClient; +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; @@ -21,11 +28,14 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; 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 { @@ -36,9 +46,9 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthenticatio private String credentialSecretKey; @Value("${identityAuthentication.merchantId}") private String merchantId; + @Value("${identityAuthentication.privateKeyHexDecodeinfo}") + private String privateKeyHexDecodeinfo; -// private static final String SECRET_ID = "AKIDeEf2A8uX1HSainvvnXAc3X9ZlhtyvkMp"; -// private static final String SECRET_KEY = "QjphKo8zkHZigT8j9PVtFPJyfIvO3d6V"; @Autowired private IdentityAuthenticationMapper identityAuthenticationMapper; @@ -64,7 +74,6 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthenticatio public IdentityAuthentication selectIdentityAuthenticaEIDtoken() { IdentityAuthentication identityAuthentication = new IdentityAuthentication(); try{ - // Credential credIdenAuth = new Credential(SECRET_ID, SECRET_KEY); Credential authenti = new Credential(credentialSecretId, credentialSecretKey); HttpProfile httpProfileIdenAuth = new HttpProfile(); httpProfileIdenAuth.setEndpoint("faceid.tencentcloudapi.com"); @@ -78,17 +87,91 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthenticatio GetEidTokenResponse respIdenAuth = clientIdenAuth.GetEidToken(reqest); String respJSON = GetEidTokenResponse.toJsonString(respIdenAuth); JSONObject objJSON = JSON.parseObject(respJSON); - JSONObject objJSONRes = (JSONObject) objJSON.get("Response"); - String eidToken = objJSONRes.getString("EidToken"); - String requestId = objJSONRes.getString("RequestId"); + String eidToken = objJSON.getString("EidToken"); + String requestId = objJSON.getString("RequestId"); identityAuthentication.setEidToken(eidToken); }catch (TencentCloudSDKException e) { - System.out.println(e.toString()); + log.error("获取Eidtoke异常:", e); + throw new RuntimeException("获取Eidtoke异常"); } return identityAuthentication; } + @Override + @Transactional + public IdentityAuthentication 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); + //获得身份认证结果 + GetEidResultResponse respIdenAuth = clientIdenAuth.GetEidResult(reqest); + String respJSON = GetEidResultResponse.toJsonString(respIdenAuth); + JSONObject objJSON = JSON.parseObject(respJSON); + JSONObject objText = JSON.parseObject(objJSON.getString("Text")); + String name = objText.getString("OcrName"); +// IdentityAuthenticationRespon.setName(name); + String identityNo = objText.getString("OcrIdCard"); +// IdentityAuthenticationRespon.setIdentityNo(identityNo); + IdentityAuthenticationRespon.setCertificationStatus(1); + IdentityAuthenticationRespon.setUserName(userName); + IdentityAuthenticationRespon.setUserId(userId); + + JSONObject objEidInfo = JSON.parseObject(objJSON.getString("EidInfo")); + String desKey = objEidInfo.getString("DesKey"); + String uerInfo = objEidInfo.getString("UserInfo"); + Map mapEidInfo = decodeEidInfo(desKey,uerInfo); + IdentityAuthenticationRespon.setName(mapEidInfo.get("name")); + IdentityAuthenticationRespon.setIdentityNo(mapEidInfo.get("identityNo")); + + identityAuthenticationMapper.insertIdentityAuthentication(IdentityAuthenticationRespon); +// IdentityAuthenticationResult.setUserName(userName); + IdentityAuthenticationResult.setCertificationStatus(1); + IdentityAuthenticationResult.setCertificationStatusName("认证成功"); +// IdentityAuthenticationResult.setName(name); +// IdentityAuthenticationResult.setIdentityNo(identityNo); + System.out.println(GetEidResultResponse.toJsonString(respIdenAuth)); + } catch (TencentCloudSDKException e) { + log.error("认证失败:", e); + throw new RuntimeException("认证失败"); + } + + } + return IdentityAuthenticationResult; + } + + private Map decodeEidInfo(String desKey, String uerInfo) { + Map mapEidInfo = new HashMap<>(); + byte[] deskeybyts = Base64.getDecoder().decode(desKey); + final SM2 sm2crypt = new SM2(privateKeyHexDecodeinfo, null, null); + sm2crypt.usePlainEncoding(); + byte[] sm4keybys = sm2crypt.decrypt(deskeybyts); + SymmetricCrypto sm4dcrypt = SmUtil.sm4(sm4keybys); + byte[] uerInfobytes = sm4dcrypt.decrypt(Base64.getDecoder().decode(uerInfo)); + JSONObject objuerInfo = JSON.parseObject(new String(uerInfobytes)); + String name = objuerInfo.getString("name"); + mapEidInfo.put("name",name); + String idtype = objuerInfo.getString("idtype"); + mapEidInfo.put("identitytype",idtype); + String idnum = objuerInfo.getString("idnum"); + mapEidInfo.put("identityNo",idnum); + return mapEidInfo; + } + } diff --git a/ruoyi-system/src/main/resources/mapper/wisdomarbitrate/IdentityAuthenticationMapper.xml b/ruoyi-system/src/main/resources/mapper/wisdomarbitrate/IdentityAuthenticationMapper.xml index 55cb676..946acea 100644 --- a/ruoyi-system/src/main/resources/mapper/wisdomarbitrate/IdentityAuthenticationMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/wisdomarbitrate/IdentityAuthenticationMapper.xml @@ -19,7 +19,7 @@ user_id, name, identity_no, - certification_time, + certification_time, certification_status, user_name, create_by, @@ -28,8 +28,8 @@ #{userId}, #{name}, #{identityNo}, - #{certificationTime}, - #{certificationStatus}, + sysdate(), + #{certificationStatus}, #{userName}, #{createBy}, sysdate()