一、2.1 获取密钥
在服务端集成之前,请你参阅控制台 云 API 密钥 页面获取密钥相关信息。
二、2.2 获取SDK
获取 Java SDK 请参考 腾讯云SDK README,如果需要获取其他语言的 SDK 可以阅读对应语言 SDK README 获取。
三、3. 接口说明
E 证通小程序服务端集成主要包含两个接口:GetEidToken 和 GetEidResult。每次调用E证通服务前,需先调用 GetEidToken 接口获取EidToken,用来串联E证通核身认证流程,在验证完成后,通过调用 GetEidResult 接口获取认证结果信息。在服务端集成接口前,你也可以通过腾讯云提供的 在线调试 功能查看每次调用的请求内容和返回结果以及自动生成 SDK 调用示例。详细的接口调用可以参考以下调用示例。
四、4.1 获取EidToken
package com.tencent;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 = ""; // TODO 你账号的腾讯云密钥 private static final String SECRET_KEY = ""; // TODO 你账号的腾讯云密钥 private static final String REGION = "ap-guangzhou"; public static void main(String[] args) { // 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(""); // 商户ID,请在控制台查看已经申请的商户ID GetEidTokenConfig config = new GetEidTokenConfig(); config.setInputType("3"); // 指定姓名和身份证号输入方式 request.setConfig(config); try { // Step 3. 调用接口 GetEidTokenResponse response = faceidClient.GetEidToken(request); System.out.println("SDK response: " + GetEidTokenResponse.toJsonString(response)); } catch (TencentCloudSDKException e) { // 调用接口异常在这里处理 System.err.println("invoke error, code: " + e.getErrorCode() + "message: " + e.getMessage()); e.printStackTrace(); } }}
五、4.2 查询E证通核身结果
package com.tencent;import com.tencentcloudapi.common.Credential;import com.tencentcloudapi.common.exception.TencentCloudSDKException;import com.tencentcloudapi.faceid.v20180301.FaceidClient;import com.tencentcloudapi.faceid.v20180301.models.GetEidResultRequest;import com.tencentcloudapi.faceid.v20180301.models.GetEidResultResponse;public class GetEidResult { private static final String SECRET_ID = ""; // TODO 你账号的腾讯云密钥 private static final String SECRET_KEY = ""; // TODO 你账号的腾讯云密钥 private static final String REGION = "ap-guangzhou"; public static void main(String[] args) { // 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/54090 GetEidResultRequest request = new GetEidResultRequest(); request.setEidToken(""); // 通过GetEidResult接口获取到的EidToken request.setInfoType("0"); // 指定拉取的结果信息 try { // Step 3. 调用接口 GetEidResultResponse response = faceidClient.GetEidResult(request); System.out.println("SDK response: " + GetEidResultResponse.toJsonString(response)); } catch (TencentCloudSDKException e) { // 调用接口异常在这里处理 System.err.println("invoke error, code: " + e.getErrorCode() + "message: " + e.getMessage()); e.printStackTrace(); } }}
六、5. 错误码列表
错误码列表请参考文档 错误码列表 中服务端错误码部分。