实现身份认证功能
This commit is contained in:
+14
@@ -28,6 +28,20 @@ public class IdentityAuthenticationController extends BaseController {
|
|||||||
return success(ientityAuthentication);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ elegent:
|
|||||||
watch: true
|
watch: true
|
||||||
cycle: 10
|
cycle: 10
|
||||||
identityAuthentication:
|
identityAuthentication:
|
||||||
credentialSecretId: 123
|
credentialSecretId: AKID3xfHgroY4MQHvLXUXMwIQL1UjmbBX1Tv
|
||||||
credentialSecretKey: 367
|
credentialSecretKey: INDrIXcT8YmomZBcsy0oNirnU0LTN4X7
|
||||||
merchantId: 356
|
merchantId: 0NSJ2309281116194321
|
||||||
|
privateKeyHexDecodeinfo: MHcCAQEEIEw7MRv3uYlpmU6Fko4GlXSh6Vd38k0cUQZ5zDwvRg+voAoGCCqBHM9VAYItoUQDQgAEUdxIAWhGg4LUXf1GoPdb8XMbGudpexPQCuaaRi9BCnNbpaF1kcwRhhsBKvop9ZmW/nOz4wQ1r/iIEOrc9qCXgQ==
|
||||||
@@ -145,6 +145,18 @@
|
|||||||
<version>3.1.871</version>
|
<version>3.1.871</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
<version>5.7.15</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bouncycastle</groupId>
|
||||||
|
<artifactId>bcprov-jdk15to18</artifactId>
|
||||||
|
<version>1.69</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- poi-tl-->
|
<!-- poi-tl-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.deepoove</groupId>
|
<groupId>com.deepoove</groupId>
|
||||||
|
|||||||
+2
@@ -10,4 +10,6 @@ public interface IdentityAuthenticationService {
|
|||||||
|
|
||||||
|
|
||||||
IdentityAuthentication selectIdentityAuthenticaEIDtoken();
|
IdentityAuthentication selectIdentityAuthenticaEIDtoken();
|
||||||
|
|
||||||
|
IdentityAuthentication selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication);
|
||||||
}
|
}
|
||||||
|
|||||||
+90
-7
@@ -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.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
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.domain.IdentityAuthentication;
|
||||||
import com.ruoyi.wisdomarbitrate.mapper.IdentityAuthenticationMapper;
|
import com.ruoyi.wisdomarbitrate.mapper.IdentityAuthenticationMapper;
|
||||||
import com.ruoyi.wisdomarbitrate.service.ICaseApplicationService;
|
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.ClientProfile;
|
||||||
import com.tencentcloudapi.common.profile.HttpProfile;
|
import com.tencentcloudapi.common.profile.HttpProfile;
|
||||||
import com.tencentcloudapi.faceid.v20180301.FaceidClient;
|
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.GetEidTokenRequest;
|
||||||
import com.tencentcloudapi.faceid.v20180301.models.GetEidTokenResponse;
|
import com.tencentcloudapi.faceid.v20180301.models.GetEidTokenResponse;
|
||||||
import org.slf4j.Logger;
|
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.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class IdentityAuthenticationServiceImpl implements IdentityAuthenticationService {
|
public class IdentityAuthenticationServiceImpl implements IdentityAuthenticationService {
|
||||||
@@ -36,9 +46,9 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthenticatio
|
|||||||
private String credentialSecretKey;
|
private String credentialSecretKey;
|
||||||
@Value("${identityAuthentication.merchantId}")
|
@Value("${identityAuthentication.merchantId}")
|
||||||
private String 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
|
@Autowired
|
||||||
private IdentityAuthenticationMapper identityAuthenticationMapper;
|
private IdentityAuthenticationMapper identityAuthenticationMapper;
|
||||||
@@ -64,7 +74,6 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthenticatio
|
|||||||
public IdentityAuthentication selectIdentityAuthenticaEIDtoken() {
|
public IdentityAuthentication selectIdentityAuthenticaEIDtoken() {
|
||||||
IdentityAuthentication identityAuthentication = new IdentityAuthentication();
|
IdentityAuthentication identityAuthentication = new IdentityAuthentication();
|
||||||
try{
|
try{
|
||||||
// Credential credIdenAuth = new Credential(SECRET_ID, SECRET_KEY);
|
|
||||||
Credential authenti = new Credential(credentialSecretId, credentialSecretKey);
|
Credential authenti = new Credential(credentialSecretId, credentialSecretKey);
|
||||||
HttpProfile httpProfileIdenAuth = new HttpProfile();
|
HttpProfile httpProfileIdenAuth = new HttpProfile();
|
||||||
httpProfileIdenAuth.setEndpoint("faceid.tencentcloudapi.com");
|
httpProfileIdenAuth.setEndpoint("faceid.tencentcloudapi.com");
|
||||||
@@ -78,17 +87,91 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthenticatio
|
|||||||
GetEidTokenResponse respIdenAuth = clientIdenAuth.GetEidToken(reqest);
|
GetEidTokenResponse respIdenAuth = clientIdenAuth.GetEidToken(reqest);
|
||||||
String respJSON = GetEidTokenResponse.toJsonString(respIdenAuth);
|
String respJSON = GetEidTokenResponse.toJsonString(respIdenAuth);
|
||||||
JSONObject objJSON = JSON.parseObject(respJSON);
|
JSONObject objJSON = JSON.parseObject(respJSON);
|
||||||
JSONObject objJSONRes = (JSONObject) objJSON.get("Response");
|
String eidToken = objJSON.getString("EidToken");
|
||||||
String eidToken = objJSONRes.getString("EidToken");
|
String requestId = objJSON.getString("RequestId");
|
||||||
String requestId = objJSONRes.getString("RequestId");
|
|
||||||
identityAuthentication.setEidToken(eidToken);
|
identityAuthentication.setEidToken(eidToken);
|
||||||
}catch (TencentCloudSDKException e) {
|
}catch (TencentCloudSDKException e) {
|
||||||
System.out.println(e.toString());
|
log.error("获取Eidtoke异常:", e);
|
||||||
|
throw new RuntimeException("获取Eidtoke异常");
|
||||||
}
|
}
|
||||||
|
|
||||||
return identityAuthentication;
|
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<String,String> 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<String, String> decodeEidInfo(String desKey, String uerInfo) {
|
||||||
|
Map<String, String> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -19,7 +19,7 @@
|
|||||||
<if test="userId != null">user_id,</if>
|
<if test="userId != null">user_id,</if>
|
||||||
<if test="name != null and name != ''">name,</if>
|
<if test="name != null and name != ''">name,</if>
|
||||||
<if test="identityNo != null and identityNo != ''">identity_no,</if>
|
<if test="identityNo != null and identityNo != ''">identity_no,</if>
|
||||||
<if test="certificationTime != null and certificationTime != ''">certification_time,</if>
|
certification_time,
|
||||||
<if test="certificationStatus != null and certificationStatus != ''">certification_status,</if>
|
<if test="certificationStatus != null and certificationStatus != ''">certification_status,</if>
|
||||||
<if test="userName != null and userName != ''">user_name,</if>
|
<if test="userName != null and userName != ''">user_name,</if>
|
||||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||||
@@ -28,8 +28,8 @@
|
|||||||
<if test="userId != null ">#{userId},</if>
|
<if test="userId != null ">#{userId},</if>
|
||||||
<if test="name != null and name != ''">#{name},</if>
|
<if test="name != null and name != ''">#{name},</if>
|
||||||
<if test="identityNo != null and identityNo != ''">#{identityNo},</if>
|
<if test="identityNo != null and identityNo != ''">#{identityNo},</if>
|
||||||
<if test="certificationTime != null and certificationTime != ''">#{certificationTime},</if>
|
sysdate(),
|
||||||
<if test="certificationStatus != null and certificationStatus != ''">#{certificationStatus},</if>
|
<if test="certificationStatus != null ">#{certificationStatus},</if>
|
||||||
<if test="userName != null and userName != ''">#{userName},</if>
|
<if test="userName != null and userName != ''">#{userName},</if>
|
||||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||||
sysdate()
|
sysdate()
|
||||||
|
|||||||
Reference in New Issue
Block a user