添加获取list接口

This commit is contained in:
孙小云 2025-12-10 16:54:02 +08:00
parent 4325f1cf1d
commit 6d55dbfea5
1 changed files with 65 additions and 0 deletions

View File

@ -28,6 +28,11 @@ public class WvpClient {
WvpClient client = new WvpClient("http://114.67.89.4:9090",loginResponse.getData().getAccessToken());
JsonNode result = client.getPushList();
// 调用获取通道列表方法
System.out.println("\n获取通道列表:");
JsonNode channelList = client.getChannelList();
System.out.println(channelList.toPrettyString());
}
private final String wvpBaseUrl;
@ -110,6 +115,66 @@ public class WvpClient {
return getPushList(1, 10, null, true, null);
}
/**
* 获取通道列表
*
* @param page 当前页默认 1
* @param count 每页数量默认 15
* @param channelType 通道类型可选
* @param query 查询内容可选
* @param online 是否在线可选
* @return 通道列表的 JSON 响应
* @throws Exception 请求失败时抛出异常
*/
public JsonNode getChannelList(int page, int count, String channelType, String query, String online) throws Exception {
// 构建查询参数
Map<String, String> params = new HashMap<>();
params.put("page", String.valueOf(page));
params.put("count", String.valueOf(count));
if (channelType != null && !channelType.isEmpty()) {
params.put("channelType", channelType);
}
if (query != null && !query.isEmpty()) {
params.put("query", query);
}
if (online != null && !online.isEmpty()) {
params.put("online", online);
}
// 构建 URL
String url = buildUrl("/api/common/channel/list", params);
// 发送 GET 请求
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("access-token", accessToken)
.header("Content-Type", "application/json")
.GET()
.timeout(Duration.ofSeconds(30))
.build();
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
// 检查响应状态
if (response.statusCode() != 200) {
throw new RuntimeException("获取通道列表失败,状态码: " + response.statusCode() + ", 响应: " + response.body());
}
// 解析 JSON 响应
return objectMapper.readTree(response.body());
}
/**
* 获取通道列表使用默认参数
*
* @return 通道列表的 JSON 响应
* @throws Exception 请求失败时抛出异常
*/
public JsonNode getChannelList() throws Exception {
return getChannelList(1, 15, "", "", "");
}
/**
* 获取播放地址
*