快速开始
# 👌 新手需知
- 拥有
Java
开发环境以及相应IDE
- 熟悉
Spring Boot
- 熟悉
Maven
# 📦 安 装
# 🍊 Maven
在项目的pom.xml的dependencies中加入以下内容
<dependency>
<groupId>io.github.gtcbaba</groupId>
<artifactId>gtcapi-client-sdk</artifactId>
<version>0.0.2</version>
</dependency>
1
2
3
4
5
2
3
4
5
提示 🔔️
JDK 8 +# ⚙️ 配置客户端
# 1. 前往Gong-API 接口开放平台 (opens new window) 获取开发者密钥(AccessKey、SecretKey)
# 2. 初始化GtcApiClient客户端对象
方法 1 :通过配置文件注入对象(推荐)
yml / yaml
# 在application.yml中配置如下 gtcapi: client: client: access-key: 你的 accessKey secret-key: 你的 secretKey
1
2
3
4
5
6
方法 2 :手动实例化客户端(不推荐)
String accessKey = "你的 accessKey"; String secretKey = "你的 secretKey"; GtcApiClient client = new GtcApiClient(accessKey, secretKey); GtcApiManager gtcApiManager = new GtcApiManager(); gtcApiManager.setGtcApiClient(client);
1
2
3
4
5
# 3. 注入API服务对象
@Resource
private GtcApiManager gtcApiManager;
/**
注意:
必须是第一种配置文件注入的方式,才可以通过@Resource注解直接得到Manager对象并使用
如果是第二种手动实例化的方式,则不可以通过@Resource注解得到Manager对象,必须先setGtcApiClient后才可以正常使用。
第二种方式代码冗余且容易出错,因此不推荐!
**/
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 4. 发起请求
示例:随机土味情话
- 示例(方法一) :通过配置文件 推荐👍
try {
BasicResponse sayingInfo = gtcApiManager.getSaying();
return sayingInfo.getData();
} catch (ApiException e) { //异常处理
log.error(e.getMessage());
}
1
2
3
4
5
6
2
3
4
5
6
- 示例(方法二) :手动注入 不推荐👎
try {
GtcApiClient client = new GtcApiClient("你的 accessKey", "你的 secretKey");
GtcApiManager gtcApiManager = new GtcApiManager();
gtcApiManager.setGtcApiClient(gtcApiClient);
BasicResponse sayingInfo = gtcApiManager.getSaying();
return sayingInfo.getData();
} catch (ApiException e) { //异常处理
log.error(e.getMessage());
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
响应:
{
"content": "古往传奇多少别离,我只是不经意遇到了你"
}
1
2
3
2
3
# 🐞 提供BUG反馈或建议
提交问题反馈请说明正在使用的JDK版本、Qi-API-SDK版本和相关依赖库版本。