优化腾讯人脸核身相关接口
This commit is contained in:
+11
-10
@@ -1,5 +1,6 @@
|
|||||||
package com.ruoyi.web.controller.wisdomarbitrate;
|
package com.ruoyi.web.controller.wisdomarbitrate;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
import com.ruoyi.wisdomarbitrate.domain.CaseApplication;
|
import com.ruoyi.wisdomarbitrate.domain.CaseApplication;
|
||||||
@@ -19,27 +20,27 @@ public class IdentityAuthenticationController extends BaseController {
|
|||||||
private IdentityAuthenticationService identityAuthenticationService;
|
private IdentityAuthenticationService identityAuthenticationService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询身份认证EIDtoken
|
* 获取EIDtoken
|
||||||
*/
|
*/
|
||||||
@PostMapping("/selectIdentityAuthenticaEIDtoken")
|
@PostMapping("/selectIdentityAuthenticaEIDtoken")
|
||||||
public AjaxResult selectIdentityAuthenticaEIDtoken()
|
public AjaxResult selectIdentityAuthenticaEIDtoken()
|
||||||
{
|
{
|
||||||
IdentityAuthentication ientityAuthentication = identityAuthenticationService.selectIdentityAuthenticaEIDtoken();
|
JSONObject tokenResult = identityAuthenticationService.selectIdentityAuthenticaEIDtoken();
|
||||||
return success(ientityAuthentication);
|
return success(tokenResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询身份认证结果
|
* 小程序人脸核身后查询身份认证结果
|
||||||
*/
|
*/
|
||||||
@PostMapping("/selectIdentityAuthenticaRespon")
|
@PostMapping("/selectIdentityAuthenticaRespon")
|
||||||
public AjaxResult selectIdentityAuthenticaRespon(@Validated @RequestBody IdentityAuthentication ientityAuthentication)
|
public AjaxResult selectIdentityAuthenticaRespon(@Validated @RequestBody IdentityAuthentication ientityAuthentication)
|
||||||
{
|
{
|
||||||
String username = this.getUsername();
|
// String username = this.getUsername();
|
||||||
Long userId = this.getUserId();
|
// Long userId = this.getUserId();
|
||||||
ientityAuthentication.setUserId(userId);
|
// ientityAuthentication.setUserId(userId);
|
||||||
ientityAuthentication.setUserName(username);
|
// ientityAuthentication.setUserName(username);
|
||||||
IdentityAuthentication ientityAuthenticationRes = identityAuthenticationService.selectIdentityAuthenticaRespon( ientityAuthentication);
|
JSONObject checkResult = identityAuthenticationService.selectIdentityAuthenticaRespon( ientityAuthentication);
|
||||||
return success(ientityAuthenticationRes);
|
return success(checkResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -136,13 +136,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tencentcloudapi</groupId>
|
<groupId>com.tencentcloudapi</groupId>
|
||||||
<artifactId>tencentcloud-sdk-java</artifactId>
|
<artifactId>tencentcloud-sdk-java</artifactId>
|
||||||
<version>3.1.270</version>
|
<version>3.1.876</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tencentcloudapi</groupId>
|
<groupId>com.tencentcloudapi</groupId>
|
||||||
<artifactId>tencentcloud-sdk-java-faceid</artifactId>
|
<artifactId>tencentcloud-sdk-java-faceid</artifactId>
|
||||||
<version>3.1.871</version>
|
<version>3.1.875</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
+15
-5
@@ -1,15 +1,25 @@
|
|||||||
package com.ruoyi.wisdomarbitrate.service;
|
package com.ruoyi.wisdomarbitrate.service;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication;
|
import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication;
|
||||||
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
|
||||||
|
|
||||||
public interface IdentityAuthenticationService {
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
+57
-90
@@ -1,27 +1,22 @@
|
|||||||
package com.ruoyi.wisdomarbitrate.service.impl;
|
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.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.IdentityAuthenticationService;
|
import com.ruoyi.wisdomarbitrate.service.IdentityAuthenticationService;
|
||||||
|
|
||||||
import com.tencentcloudapi.common.Credential;
|
import com.tencentcloudapi.common.Credential;
|
||||||
|
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.common.exception.TencentCloudSDKException;
|
|
||||||
import com.tencentcloudapi.faceid.v20180301.FaceidClient;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
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
|
@Service
|
||||||
public class IdentityAuthenticationServiceImpl implements IdentityAuthenticationService {
|
public class IdentityAuthenticationServiceImpl implements IdentityAuthenticationService {
|
||||||
|
|
||||||
@Value("${identityAuthentication.credentialSecretId}")
|
@Value("${identityAuthentication.credentialSecretId}")
|
||||||
private String credentialSecretId;
|
private String credentialSecretId;
|
||||||
@@ -58,9 +46,9 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthenticatio
|
|||||||
@Override
|
@Override
|
||||||
public IdentityAuthentication selectIdentityAuthentication(IdentityAuthentication identityAuthentication) {
|
public IdentityAuthentication selectIdentityAuthentication(IdentityAuthentication identityAuthentication) {
|
||||||
IdentityAuthentication identityAuthenticationselect = identityAuthenticationMapper.selectIdentityAuthentication(identityAuthentication);
|
IdentityAuthentication identityAuthenticationselect = identityAuthenticationMapper.selectIdentityAuthentication(identityAuthentication);
|
||||||
if(identityAuthenticationselect!=null){
|
if (identityAuthenticationselect != null) {
|
||||||
identityAuthenticationselect.setCertificationStatusName("已身份认证");
|
identityAuthenticationselect.setCertificationStatusName("已身份认证");
|
||||||
}else {
|
} else {
|
||||||
IdentityAuthentication identityAuthenticationselectnew = new IdentityAuthentication();
|
IdentityAuthentication identityAuthenticationselectnew = new IdentityAuthentication();
|
||||||
identityAuthenticationselectnew.setCertificationStatusName("未身份认证");
|
identityAuthenticationselectnew.setCertificationStatusName("未身份认证");
|
||||||
identityAuthenticationselectnew.setCertificationStatus(0);
|
identityAuthenticationselectnew.setCertificationStatus(0);
|
||||||
@@ -71,85 +59,64 @@ public class IdentityAuthenticationServiceImpl implements IdentityAuthenticatio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IdentityAuthentication selectIdentityAuthenticaEIDtoken() {
|
public JSONObject selectIdentityAuthenticaEIDtoken() {
|
||||||
IdentityAuthentication identityAuthentication = new IdentityAuthentication();
|
JSONObject objJSON = new JSONObject();
|
||||||
try{
|
objJSON.put("EidToken", "");
|
||||||
Credential authenti = new Credential(credentialSecretId, credentialSecretKey);
|
try {
|
||||||
HttpProfile httpProfileIdenAuth = new HttpProfile();
|
Credential cred = new Credential(credentialSecretId, credentialSecretKey);
|
||||||
httpProfileIdenAuth.setEndpoint("faceid.tencentcloudapi.com");
|
// 实例化一个http选项,可选的,没有特殊需求可以跳过
|
||||||
ClientProfile clientInv= new ClientProfile();
|
HttpProfile httpProfile = new HttpProfile();
|
||||||
clientInv.setHttpProfile(httpProfileIdenAuth);
|
httpProfile.setEndpoint("faceid.tencentcloudapi.com");
|
||||||
FaceidClient clientIdenAuth = new FaceidClient(authenti, "", clientInv);
|
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
||||||
// 实例化一个请求对象
|
ClientProfile clientProfile = new ClientProfile();
|
||||||
GetEidTokenRequest reqest = new GetEidTokenRequest();
|
clientProfile.setHttpProfile(httpProfile);
|
||||||
//设置请求参数
|
// 实例化要请求产品的client对象,clientProfile是可选的
|
||||||
reqest.setMerchantId(merchantId);
|
FaceidClient client = new FaceidClient(cred, "", clientProfile);
|
||||||
GetEidTokenResponse respIdenAuth = clientIdenAuth.GetEidToken(reqest);
|
// 实例化一个请求对象,每个接口都会对应一个request对象
|
||||||
String respJSON = GetEidTokenResponse.toJsonString(respIdenAuth);
|
GetEidTokenRequest req = new GetEidTokenRequest();
|
||||||
JSONObject objJSON = JSON.parseObject(respJSON);
|
// 返回的resp是一个GetEidTokenResponse的实例,与请求对象对应
|
||||||
String eidToken = objJSON.getString("EidToken");
|
GetEidTokenResponse resp = client.GetEidToken(req);
|
||||||
String requestId = objJSON.getString("RequestId");
|
// 输出json格式的字符串回包
|
||||||
identityAuthentication.setEidToken(eidToken);
|
System.out.println(GetEidTokenResponse.toJsonString(resp));
|
||||||
}catch (TencentCloudSDKException e) {
|
String respJSON = GetEidTokenResponse.toJsonString(resp);
|
||||||
log.error("获取Eidtoke异常:", e);
|
objJSON = JSON.parseObject(respJSON);
|
||||||
throw new RuntimeException("获取Eidtoke异常");
|
} catch (TencentCloudSDKException e) {
|
||||||
|
System.out.println(e.toString());
|
||||||
|
System.out.println("获取Eidtoken失败");
|
||||||
}
|
}
|
||||||
|
return objJSON;
|
||||||
return identityAuthentication;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public IdentityAuthentication selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication) {
|
public JSONObject selectIdentityAuthenticaRespon(IdentityAuthentication ientityAuthentication) {
|
||||||
String eidToken = ientityAuthentication.getEidToken();
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user