package org.jeecg.modules.app.ezt;

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.faceid.v20180301.FaceidClient;
import com.tencentcloudapi.faceid.v20180301.models.GetEidTokenConfig;
import com.tencentcloudapi.faceid.v20180301.models.GetEidTokenRequest;
import com.tencentcloudapi.faceid.v20180301.models.GetEidTokenResponse;

public class GetEidToken {
    private static final String SECRET_ID = "AKIDDIDyWsIZfYIrDOWTLCzkU7bsyrX2LQK2 "; // TODO 您账号的腾讯云密钥
    private static final String SECRET_KEY = "Yt0vfDZhdNvHPK3ZzEG4f4FCvRlsm073"; // TODO 您账号的腾讯云密钥
    private static final String REGION = "ap-guangzhou";
    public static String getEidToken(String idCard, String name) throws Exception {
        // Step 1. 初始化客户端实例
        Credential credential = new Credential(SECRET_ID, SECRET_KEY);
        FaceidClient faceidClient = new FaceidClient(credential, REGION);
        // Step 2. 使用Tencent Cloud API SDK组装请求体，填充参数
        // 详细的接口文档请参考：https://cloud.tencent.com/document/product/1007/54089
        GetEidTokenRequest request = new GetEidTokenRequest();
        request.setMerchantId("00EI2508221332333922"); // 商户ID，请在控制台查看已经申请的商户ID
        GetEidTokenConfig config = new GetEidTokenConfig();
        config.setInputType("4"); // 指定姓名和身份证号输入方式
        request.setConfig(config);
        request.setIdCard(idCard);
        request.setName(name);
        try {
            // Step 3. 调用接口
            GetEidTokenResponse response = faceidClient.GetEidToken(request);
            return GetEidTokenResponse.toJsonString(response);
        } catch (TencentCloudSDKException e) {
            // 调用接口异常在这里处理
            System.err.println("invoke error, code: " + e.getErrorCode() + "message: " + e.getMessage());
            e.printStackTrace();
        }
        return null;
    }
}
