package com.panzhihua.common.utlis;
|
|
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.faceid.v20180301.FaceidClient;
|
import com.tencentcloudapi.faceid.v20180301.models.*;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@Slf4j
|
public class TencentUtils {
|
|
private static final String secretId = "AKIDCG5h4EArJVTCesseAQQCiyzlIZicHgpk";
|
private static final String secretKey = "jCPM5appZ4KK4YrvjHaeS0JNCl5C4g5E";
|
/**
|
* 商户id
|
*/
|
private static final String merchantId = "0NSJ2106041331155797";
|
/**
|
* 请求地址
|
*/
|
private static final String url = "faceid.tencentcloudapi.com";
|
|
/**
|
* 获取用户EidToken接口
|
*
|
* @param name
|
* 姓名
|
* @param idCard
|
* 身份证号
|
* @return 调用结果
|
*/
|
public static String getEidToken(String name, String idCard) {
|
try {
|
Credential cred = new Credential(secretId, secretKey);
|
|
HttpProfile httpProfile = new HttpProfile();
|
httpProfile.setEndpoint(url);
|
|
ClientProfile clientProfile = new ClientProfile();
|
clientProfile.setHttpProfile(httpProfile);
|
|
FaceidClient client = new FaceidClient(cred, "", clientProfile);
|
|
GetEidTokenRequest req = new GetEidTokenRequest();
|
req.setIdCard(idCard);
|
req.setName(name);
|
GetEidTokenConfig getEidTokenConfig1 = new GetEidTokenConfig();
|
getEidTokenConfig1.setInputType("4");
|
req.setConfig(getEidTokenConfig1);
|
|
req.setMerchantId(merchantId);
|
GetEidTokenResponse resp = client.GetEidToken(req);
|
return GetEidTokenResponse.toJsonString(resp);
|
} catch (TencentCloudSDKException e) {
|
log.error("人脸核身获取Token接口调用失败,错误信息:" + e.toString());
|
}
|
return "";
|
}
|
|
/**
|
* 获取用户核身结果接口
|
*
|
* @param eidToken
|
* 用户token
|
* @return 调用结果
|
*/
|
public static String getEidResult(String eidToken) {
|
try {
|
Credential cred = new Credential(secretId, secretKey);
|
HttpProfile httpProfile = new HttpProfile();
|
httpProfile.setEndpoint(url);
|
ClientProfile clientProfile = new ClientProfile();
|
clientProfile.setHttpProfile(httpProfile);
|
FaceidClient client = new FaceidClient(cred, "", clientProfile);
|
GetEidResultRequest req = new GetEidResultRequest();
|
req.setEidToken(eidToken);
|
GetEidResultResponse resp = client.GetEidResult(req);
|
return GetEidTokenResponse.toJsonString(resp);
|
} catch (TencentCloudSDKException e) {
|
log.error("人脸核身获取结果接口调用失败,错误信息:" + e.toString());
|
}
|
return "";
|
}
|
|
}
|