From 6d55dbfea54383f5c0a482f72e41ecb304e3325e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=B0=8F=E4=BA=91?= Date: Wed, 10 Dec 2025 16:54:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96list?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/tuoheng/WvpClient.java | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/main/java/com/tuoheng/WvpClient.java b/src/main/java/com/tuoheng/WvpClient.java index fbef06c..74a4cdd 100644 --- a/src/main/java/com/tuoheng/WvpClient.java +++ b/src/main/java/com/tuoheng/WvpClient.java @@ -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 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 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, "", "", ""); + } + /** * 获取播放地址 *