From ad2aabb7fb69c7e4bec3308dac39cdc1b50d81f1 Mon Sep 17 00:00:00 2001 From: czp3009 Date: Thu, 24 May 2018 16:32:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BC=B9=E5=B9=95=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E6=95=B0=E6=8D=AE=E5=8C=85=20ROOM=5FRANK?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +- build.gradle | 6 +- .../bullet_screen_stream_json/ROOM_RANK.json | 10 ++ .../live/socket/entity/RoomRankEntity.java | 92 +++++++++++++++++++ .../socket/event/RoomRankPackageEvent.java | 10 ++ .../socket/handler/LiveClientHandler.java | 10 +- 6 files changed, 125 insertions(+), 6 deletions(-) create mode 100644 record/bullet_screen_stream_json/ROOM_RANK.json create mode 100644 src/main/java/com/hiczp/bilibili/api/live/socket/entity/RoomRankEntity.java create mode 100644 src/main/java/com/hiczp/bilibili/api/live/socket/event/RoomRankPackageEvent.java diff --git a/README.md b/README.md index 2d2cafc..c5d091e 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ # 添加依赖 ## Gradle - compile group: 'com.hiczp', name: 'bilibili-api', version: '0.0.13' + compile group: 'com.hiczp', name: 'bilibili-api', version: '0.0.14' # 名词解释 B站不少参数都是瞎取的, 并且不统一, 经常混用, 以下给出一些常见参数对应的含义 @@ -335,6 +335,7 @@ API 文档 | RoomAdminsPackageEvent | 收到 ROOM_ADMINS 数据包 | | RoomBlockMsgPackageEvent | 收到 ROOM_BLOCK_MSG 数据包 | | RoomLockPackageEvent | 收到 ROOM_LOCK 数据包 | +| RoomRankPackageEvent | 收到 ROOM_RANK 数据包 | | RoomShieldPackageEvent | 收到 ROOM_SHIELD 数据包 | | RoomSilentOffPackageEvent | 收到 ROOM_SILENT_OFF 数据包 | | RoomSilentOnPackageEvent | 收到 ROOM_SILENT_ON 数据包 | diff --git a/build.gradle b/build.gradle index 7ad8558..96fa2b4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group = 'com.hiczp' -version = '0.0.13' +version = '0.0.14' description = 'Bilibili android client API library written in Java' apply plugin: 'idea' @@ -19,13 +19,13 @@ dependencies { // https://mvnrepository.com/artifact/com.squareup.retrofit2/converter-gson compile group: 'com.squareup.retrofit2', name: 'converter-gson', version: '2.4.0' // https://mvnrepository.com/artifact/com.google.code.gson/gson - compile group: 'com.google.code.gson', name: 'gson', version: '2.8.4' + compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5' // https://mvnrepository.com/artifact/com.squareup.okhttp3/logging-interceptor compile group: 'com.squareup.okhttp3', name: 'logging-interceptor', version: '3.10.0' // https://mvnrepository.com/artifact/org.slf4j/slf4j-api compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25' // https://mvnrepository.com/artifact/io.netty/netty-all - compile group: 'io.netty', name: 'netty-all', version: '4.1.24.Final' + compile group: 'io.netty', name: 'netty-all', version: '4.1.25.Final' // https://mvnrepository.com/artifact/com.google.guava/guava compile group: 'com.google.guava', name: 'guava', version: '25.0-jre' } diff --git a/record/bullet_screen_stream_json/ROOM_RANK.json b/record/bullet_screen_stream_json/ROOM_RANK.json new file mode 100644 index 0000000..ca793dd --- /dev/null +++ b/record/bullet_screen_stream_json/ROOM_RANK.json @@ -0,0 +1,10 @@ +{ + "cmd": "ROOM_RANK", + "data": { + "roomid": 1241012, + "rank_desc": "小时榜 182", + "color": "#FB7299", + "h5_url": "https://live.bilibili.com/p/eden/rank-h5-current?anchor_uid\u003d35577726", + "timestamp": 1527148082 + } +} diff --git a/src/main/java/com/hiczp/bilibili/api/live/socket/entity/RoomRankEntity.java b/src/main/java/com/hiczp/bilibili/api/live/socket/entity/RoomRankEntity.java new file mode 100644 index 0000000..ec36df8 --- /dev/null +++ b/src/main/java/com/hiczp/bilibili/api/live/socket/entity/RoomRankEntity.java @@ -0,0 +1,92 @@ +package com.hiczp.bilibili.api.live.socket.entity; + +import com.google.gson.annotations.SerializedName; + +public class RoomRankEntity implements DataEntity { + /** + * cmd : ROOM_RANK + * data : {"roomid":1241012,"rank_desc":"小时榜 182","color":"#FB7299","h5_url":"https://live.bilibili.com/p/eden/rank-h5-current?anchor_uid=35577726","timestamp":1527148082} + */ + + @SerializedName("cmd") + private String cmd; + @SerializedName("data") + private Data data; + + public String getCmd() { + return cmd; + } + + public void setCmd(String cmd) { + this.cmd = cmd; + } + + public Data getData() { + return data; + } + + public void setData(Data data) { + this.data = data; + } + + public static class Data { + /** + * roomid : 1241012 + * rank_desc : 小时榜 182 + * color : #FB7299 + * h5_url : https://live.bilibili.com/p/eden/rank-h5-current?anchor_uid=35577726 + * timestamp : 1527148082 + */ + + @SerializedName("roomid") + private long roomId; + @SerializedName("rank_desc") + private String rankDescription; + @SerializedName("color") + private String color; + @SerializedName("h5_url") + private String h5Url; + @SerializedName("timestamp") + private long timestamp; + + public long getRoomId() { + return roomId; + } + + public void setRoomId(long roomId) { + this.roomId = roomId; + } + + public String getRankDescription() { + return rankDescription; + } + + public void setRankDescription(String rankDescription) { + this.rankDescription = rankDescription; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + + public String getH5Url() { + return h5Url; + } + + public void setH5Url(String h5Url) { + this.h5Url = h5Url; + } + + public long getTimestamp() { + return timestamp; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + } +} diff --git a/src/main/java/com/hiczp/bilibili/api/live/socket/event/RoomRankPackageEvent.java b/src/main/java/com/hiczp/bilibili/api/live/socket/event/RoomRankPackageEvent.java new file mode 100644 index 0000000..1efe117 --- /dev/null +++ b/src/main/java/com/hiczp/bilibili/api/live/socket/event/RoomRankPackageEvent.java @@ -0,0 +1,10 @@ +package com.hiczp.bilibili.api.live.socket.event; + +import com.hiczp.bilibili.api.live.socket.LiveClient; +import com.hiczp.bilibili.api.live.socket.entity.RoomRankEntity; + +public class RoomRankPackageEvent extends ReceiveDataPackageEvent { + public RoomRankPackageEvent(LiveClient source, RoomRankEntity entity) { + super(source, entity); + } +} diff --git a/src/main/java/com/hiczp/bilibili/api/live/socket/handler/LiveClientHandler.java b/src/main/java/com/hiczp/bilibili/api/live/socket/handler/LiveClientHandler.java index 8bfb2b8..ef340cf 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/socket/handler/LiveClientHandler.java +++ b/src/main/java/com/hiczp/bilibili/api/live/socket/handler/LiveClientHandler.java @@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory; import java.io.ByteArrayInputStream; import java.io.InputStreamReader; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; @@ -68,11 +69,12 @@ public class LiveClientHandler extends SimpleChannelInboundHandler { JsonObject jsonObject; String cmd; try { - jsonObject = JSON_PARSER.parse(new InputStreamReader(new ByteArrayInputStream(msg.getContent()))) + //强制使用 UTF-8, 避免在 NT 平台可能出现的乱码问题 + jsonObject = JSON_PARSER.parse(new InputStreamReader(new ByteArrayInputStream(msg.getContent()), StandardCharsets.UTF_8)) .getAsJsonObject(); cmd = jsonObject.get("cmd").getAsString(); } catch (JsonSyntaxException | IllegalStateException | NullPointerException e) { - LOGGER.error("Receive invalid json: \n{}", new String(msg.getContent())); + LOGGER.error("Receive invalid json: \n{}", new String(msg.getContent(), StandardCharsets.UTF_8)); e.printStackTrace(); break; } @@ -171,6 +173,10 @@ public class LiveClientHandler extends SimpleChannelInboundHandler { eventCreationExpression = () -> new TVEndPackageEvent(liveClient, GSON.fromJson(jsonObject, TVEndEntity.class)); } break; + case "ROOM_RANK": { + eventCreationExpression = () -> new RoomRankPackageEvent(liveClient, GSON.fromJson(jsonObject, RoomRankEntity.class)); + } + break; //欢迎(活动) case "WELCOME_ACTIVITY": { eventCreationExpression = () -> new WelcomeActivityPackageEvent(liveClient, GSON.fromJson(jsonObject, WelcomeActivityEntity.class));