mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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 "";
    }
 
}