请求代码示例
注意 🔔️
没有开发者调用凭证无法调用接口哦!!! 前往获取开发者凭证 (opens new window)
# 示例代码开发环境
java8
springboot 2.7.2
apache-maven-3.8.1
# 接口方法名对照表
接口名称 | 方法名称 |
---|---|
获取输入名称 | getUsernameByPost |
微博热搜实时榜单 | getWeiboHotSearch |
毒鸡汤 | getPoisonousChickenSoup |
星座运势 | getHoroscope |
获取公网ip | getPublicIp |
随机壁纸 | getRandomWallpaper |
天气详细信息 | getWeather |
土味情话 | getLoveTalk |
# 代码示例
我们以星座运势为例:
- 示例一 :推荐 👍
通过yml配置开发者调用凭证调用
注入Client
@Resource private GigotApiClient gigotApiClient;
1
2找到对应方法,参考请求接口方法名对照表
封装参数,参数列表可见
接口对应api文档
例:星座运势HoroscopeParams horoscopeParams = new HoroscopeParams(); horoscopeParams.setType("virgo"); horoscopeParams.setTime("week");
1
2
3调用代码
public HoroscopeResponse getHoroscope(HoroscopeParams horoscopeParams) { HoroscopeResponse horoscopeResponse = null; try { return gigotApiClient.getHoroscope(horoscopeParams); } catch (GigotApiException e) { log.error(e.getMessage()); return null; } }
1
2
3
4
5
6
7
8
9
完整代码
@Resource private GigotApiClient gigotApiClient; @Test void clientTest(){ // 1. 封装参数 如没有参数不传 HoroscopeParams horoscopeParams = new HoroscopeParams(); horoscopeParams.setType("virgo"); horoscopeParams.setTime("week"); // 2.调用自定义方法 HoroscopeResponse horoscope = getHoroscope(horoscopeParams); // 其他业务逻辑 log.info("horoscope:" + horoscope); } public HoroscopeResponse getHoroscope(HoroscopeParams horoscopeParams) { HoroscopeResponse horoscopeResponse = null; try { // 3. 调用sdk并返回结果 return gigotApiClient.getHoroscope(horoscopeParams); } catch (GigotApiException e) { log.error(e.getMessage()); return null; } }
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示例二:
找到对应方法,参考请求接口方法名对照表
封装参数,参数列表可见
接口对应api文档
例:星座运势HoroscopeParams horoscopeParams = new HoroscopeParams(); horoscopeParams.setType("virgo"); horoscopeParams.setTime("week");
1
2
3通过实例化对象的方式传入密钥
GigotApiClient gigotApiClient = new GigotApiClient("您的secretId", "您的secretKey");
1调用代码
public HoroscopeResponse getHoroscope(HoroscopeParams horoscopeParams) { HoroscopeResponse horoscopeResponse = null; try { // 3. 创建Client示例 并传入密钥 GigotApiClient gigotApiClient = new GigotApiClient("您的secretId", "您的secretKey"); // 4. 调用sdk并返回结果 return gigotApiClient.getHoroscope(horoscopeParams); } catch (GigotApiException e) { log.error(e.getMessage()); return null; } }
1
2
3
4
5
6
7
8
9
10
11
12
完整代码
@Test void clientTest(){ // 1. 封装参数 如没有参数不传 HoroscopeParams horoscopeParams = new HoroscopeParams(); horoscopeParams.setType("virgo"); horoscopeParams.setTime("week"); // 2.调用自定义方法 HoroscopeResponse horoscope = getHoroscope(horoscopeParams); // 其他业务逻辑 log.info("horoscope:" + horoscope); } public HoroscopeResponse getHoroscope(HoroscopeParams horoscopeParams) { HoroscopeResponse horoscopeResponse = null; try { // 3. 创建Client示例 并传入密钥 GigotApiClient gigotApiClient = new GigotApiClient("您的secretId", "您的secretKey"); // 4. 调用sdk并返回结果 return gigotApiClient.getHoroscope(horoscopeParams); } catch (GigotApiException e) { log.error(e.getMessage()); return null; } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
帮助我们改善此页面! (opens new window)
上次更新: 2024/03/29, 18:47:19