|
@@ -0,0 +1,58 @@
|
|
|
+package com.ematou.wxbase;
|
|
|
+
|
|
|
+import com.ematou.wxbase.service.EidTokenRecordService;
|
|
|
+import com.ematou.wxbase.service.TokenRecordService;
|
|
|
+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.GetEidTokenRequest;
|
|
|
+import com.tencentcloudapi.faceid.v20180301.models.GetEidTokenResponse;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+
|
|
|
+/**
|
|
|
+ * E证通 token 单元测试
|
|
|
+ *
|
|
|
+ * @author frankeleyn
|
|
|
+ * @email lvjian@qhdswl.com
|
|
|
+ * @date 2023/2/16 15:22
|
|
|
+ */
|
|
|
+@SpringBootTest
|
|
|
+public class EidTokenTest {
|
|
|
+
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(TokenRecordService.class);
|
|
|
+
|
|
|
+ private final static String secretId = "AKIDIRYotrdCZnqkT0LTVzJSQFrGmLoALLJA";
|
|
|
+ private final static String secretKey = "jICxWrJchWBg8RYO2RZYLwMXh0bR6imd";
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void getEidToken() {
|
|
|
+ try {
|
|
|
+ // 创建访问凭据
|
|
|
+ Credential cred = new Credential(secretId, secretKey);
|
|
|
+ // 实例化一个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对象
|
|
|
+ GetEidTokenRequest req = new GetEidTokenRequest();
|
|
|
+
|
|
|
+ // 返回的resp是一个GetEidTokenResponse的实例,与请求对象对应
|
|
|
+ GetEidTokenResponse resp = client.GetEidToken(req);
|
|
|
+ // 输出json格式的字符串回包
|
|
|
+ System.out.println(GetEidTokenResponse.toJsonString(resp));
|
|
|
+ } catch (TencentCloudSDKException e) {
|
|
|
+ logger.error("腾讯云 SDK Error", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|