package com.stylefeng.guns.modular.system.util;
|
|
import com.tencentcloudapi.common.AbstractModel;
|
import com.tencentcloudapi.common.Credential;
|
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.*;
|
|
public class UserUtil
|
{
|
|
|
public static Boolean idCardAuth(String name, String idCard){
|
try{
|
// 密钥信息从环境变量读取,需要提前在环境变量中设置 TENCENTCLOUD_SECRET_ID 和 TENCENTCLOUD_SECRET_KEY
|
// 使用环境变量方式可以避免密钥硬编码在代码中,提高安全性
|
// 生产环境建议使用更安全的密钥管理方案,如密钥管理系统(KMS)、容器密钥注入等
|
// 请参见:https://cloud.tencent.com/document/product/1278/85305
|
// 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
|
Credential cred = new Credential("AKIDZBew0rJbghYnt20oRr44qQpDViu6HMGx", "pRvd9ez71iBSXO1PYrwnPyMVRAew53mH");
|
// 使用临时密钥示例
|
// Credential cred = new Credential("SecretId", "SecretKey", "Token");
|
// 实例化一个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对象
|
IdCardVerificationRequest req = new IdCardVerificationRequest();
|
req.setIdCard(idCard);
|
req.setName(name);
|
// 返回的resp是一个IdCardVerificationResponse的实例,与请求对象对应
|
IdCardVerificationResponse resp = client.IdCardVerification(req);
|
// 输出json格式的字符串回包
|
System.out.println(AbstractModel.toJsonString(resp));
|
if(resp.getResult().equals("0")){
|
return true;
|
}
|
} catch (TencentCloudSDKException e) {
|
System.out.println(e.toString());
|
}
|
return false;
|
}
|
|
public static void main(String [] args) {
|
try{
|
// 密钥信息从环境变量读取,需要提前在环境变量中设置 TENCENTCLOUD_SECRET_ID 和 TENCENTCLOUD_SECRET_KEY
|
// 使用环境变量方式可以避免密钥硬编码在代码中,提高安全性
|
// 生产环境建议使用更安全的密钥管理方案,如密钥管理系统(KMS)、容器密钥注入等
|
// 请参见:https://cloud.tencent.com/document/product/1278/85305
|
// 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
|
Credential cred = new Credential("AKIDZBew0rJbghYnt20oRr44qQpDViu6HMGx", "pRvd9ez71iBSXO1PYrwnPyMVRAew53mH");
|
// 使用临时密钥示例
|
// Credential cred = new Credential("SecretId", "SecretKey", "Token");
|
// 实例化一个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对象
|
IdCardVerificationRequest req = new IdCardVerificationRequest();
|
req.setIdCard("511028200002150816");
|
req.setName("刘杰");
|
// 返回的resp是一个IdCardVerificationResponse的实例,与请求对象对应
|
IdCardVerificationResponse resp = client.IdCardVerification(req);
|
if(resp.getResult().equals("0")){
|
System.out.println("认证成功");
|
}
|
// 输出json格式的字符串回包
|
System.out.println(AbstractModel.toJsonString(resp));
|
} catch (TencentCloudSDKException e) {
|
System.out.println(e.toString());
|
}
|
}
|
}
|