From d08d1fbd8c26d2b6192e6a0cc420f0cc2332dc5d Mon Sep 17 00:00:00 2001 From: czp3009 Date: Tue, 31 Jul 2018 19:26:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 99 +++---- .../hiczp/bilibili/api/live/LiveService.java | 12 +- .../api/live/entity/ActivityGiftsEntity.java | 10 +- .../api/live/entity/AllListEntity.java | 10 +- .../live/entity/AssistantRoomInfoEntity.java | 10 +- .../api/live/entity/AwardsEntity.java | 10 +- .../api/live/entity/BulletScreenEntity.java | 28 +- .../bilibili/api/live/entity/GiftEntity.java | 4 +- .../api/live/entity/GiftTopEntity.java | 10 +- .../LiveHistoryBulletScreensEntity.java | 10 +- .../api/live/entity/LiveRoomInfoEntity.java | 60 ++--- .../api/live/entity/MyTitleListEntity.java | 10 +- .../entity/OpenCapsuleResponseEntity.java | 10 +- .../api/live/entity/PlayerBagEntity.java | 10 +- .../RecommendRoomRefreshResponseEntity.java | 10 +- .../live/entity/SendGiftResponseEntity.java | 10 +- .../api/live/entity/UserTasksEntity.java | 30 +-- .../api/live/entity/WearTitleEntity.java | 10 +- .../bilibili/api/live/socket/LiveClient.java | 3 +- .../live/socket/entity/GuardBuyEntity.java | 20 +- .../live/socket/entity/PkProcessEntity.java | 6 +- .../socket/entity/RoomBlockMsgEntity.java | 10 +- .../live/socket/entity/SendGiftEntity.java | 50 ++-- .../socket/entity/WelcomeActivityEntity.java | 10 +- .../socket/entity/WelcomeGuardEntity.java | 10 +- .../live/socket/entity/WishBottleEntity.java | 10 +- .../socket/handler/LiveClientHandler.java | 250 ++++-------------- .../api/passport/entity/InfoEntity.java | 20 +- .../passport/entity/LoginResponseEntity.java | 12 +- .../entity/RefreshTokenResponseEntity.java | 12 +- .../com/hiczp/bilibili/api/test/Config.java | 6 +- .../bilibili/api/test/LiveClientTest.java | 2 +- 32 files changed, 320 insertions(+), 454 deletions(-) diff --git a/README.md b/README.md index 6a6bf42..ca0981b 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,9 @@ B站不少参数都是瞎取的, 并且不统一, 经常混用, 以下给出一 | roomId | 直播间的真实 ID(直播房间号在 1000 以下的房间, 真实 ID 是另外一个数字) | | cid | 直播间 ID(URL 上的短房间号以及真实房间号都叫 cid) | | ruid | 直播间房主的用户 ID | +| rcost | 该房间内消费的瓜子数量 | + +(上表仅供其他开发者参照, 本调用库中已经封装为 Java 标准全写小驼峰命名法, 例如 userId, roomId, roomUserId) # 使用 ## RESTFul API @@ -317,54 +320,54 @@ API 文档 所有的事件(有些数据包我也不知道它里面的一些值是什么含义, /record 目录下面有抓取到的 Json, 可以用来查看): -| 事件 | 抛出条件 | -| :--- | :--- | -| ActivityEventPackageEvent | 收到 ACTIVITY_EVENT 数据包 | -| ChangeRoomInfoPackageEvent | 收到 CHANGE_ROOM_INFO 数据包 | -| ComboEndPackageEvent | 收到 COMBO_END 数据包 | -| ComboSendPackageEvent | 收到 COMBO_SEND 数据包 | -| ConnectionCloseEvent | 连接断开(主动或被动) | -| ConnectSucceedEvent | 进房成功 | -| CutOffPackageEvent | 收到 CUT_OFF 数据包 | -| DanMuMsgPackageEvent | 收到 DANMU_MSG 数据包 | -| EntryEffectPackageEvent | 收到 ENTRY_EFFECT 数据包 | -| EventCmdPackageEvent | 收到 EVENT_CMD 数据包 | -| GuardBuyPackageEvent | 收到 GUARD_BUY 数据包 | -| GuardMsgPackageEvent | 收到 GUARD_MSG 数据包 | -| LivePackageEvent | 收到 LIVE 数据包 | -| PkAgainPackageEvent | 收到 PK_AGAIN 数据包 | -| PkClickAgainPackageEvent | 收到 PK_CLICK_AGAIN 数据包 | -| PkEndPackageEvent | 收到 PK_END 数据包 | -| PkMatchPackageEvent | 收到 PK_MATCH 数据包 | -| PkMicEndPackageEvent | 收到 PK_MIC_END 数据包 | -| PkPrePackageEvent | 收到 PK_PRE 数据包 | -| PkProcessPackageEvent | 收到 PK_PROCESS 数据包 | -| PkSettlePackageEvent | 收到 PK_SETTLE 数据包 | -| PkStartPackageEvent | 收到 PK_START 数据包 | -| PreparingPackageEvent | 收到 PREPARING 数据包 | -| RaffleEndPackageEvent | 收到 RAFFLE_END 数据包 | -| RaffleStartPackageEvent | 收到 RAFFLE_START 数据包 | -| ReceiveDataPackageDebugEvent | 该事件用于调试, 收到任何 Data 数据包时都会触发 | -| RoomAdminsPackageEvent | 收到 ROOM_ADMINS 数据包 | -| RoomBlockMsgPackageEvent | 收到 ROOM_BLOCK_MSG 数据包 | -| RoomLockPackageEvent | 收到 ROOM_LOCK 数据包 | -| RoomRankPackageEvent | 收到 ROOM_RANK 数据包 | -| RoomShieldPackageEvent | 收到 ROOM_SHIELD 数据包 | -| RoomSilentOffPackageEvent | 收到 ROOM_SILENT_OFF 数据包 | -| RoomSilentOnPackageEvent | 收到 ROOM_SILENT_ON 数据包 | -| SendGiftPackageEvent | 收到 SEND_GIFT 数据包 | -| SendHeartBeatPackageEvent | 每次发送心跳包后触发一次 | -| SpecialGiftPackageEvent | 收到 SPECIAL_GIFT 数据包 | -| SysGiftPackageEvent | 收到 SYS_GIFT 数据包 | -| SysMsgPackageEvent | 收到 SYS_MSG 数据包 | -| TVEndPackageEvent | 收到 TV_END 数据包 | -| TVStartPackageEvent | 收到 TV_START 数据包 | -| UnknownPackageEvent | B站新增了新种类的数据包, 出现此情况请提交 issue | -| ViewerCountPackageEvent | 收到 房间人数 数据包(不是 Json) | -| WelcomeActivityPackageEvent | 收到 WELCOME_ACTIVITY 数据包 | -| WelcomeGuardPackageEvent | 收到 WELCOME_GUARD 数据包 | -| WelcomePackageEvent | 收到 WELCOME 数据包 | -| WishBottlePackageEvent | 收到 WISH_BOTTLE 数据包 | +| 事件 | 抛出条件 | 含义 | +| :--- | :--- | :--- | +| ActivityEventPackageEvent | 收到 ACTIVITY_EVENT 数据包 | 活动事件 | +| ChangeRoomInfoPackageEvent | 收到 CHANGE_ROOM_INFO 数据包 | 更换房间背景图片 | +| ComboEndPackageEvent | 收到 COMBO_END 数据包 | 礼物连发结束 | +| ComboSendPackageEvent | 收到 COMBO_SEND 数据包 | 礼物连发开始 | +| ConnectionCloseEvent | 连接断开(主动或被动) | | +| ConnectSucceedEvent | 进房成功 | | +| CutOffPackageEvent | 收到 CUT_OFF 数据包 | 被 B站 管理员强制中断 | +| DanMuMsgPackageEvent | 收到 DANMU_MSG 数据包 | 弹幕消息 | +| EntryEffectPackageEvent | 收到 ENTRY_EFFECT 数据包 | 尚不明确 | +| EventCmdPackageEvent | 收到 EVENT_CMD 数据包 | 尚不明确 | +| GuardBuyPackageEvent | 收到 GUARD_BUY 数据包 | 船票购买 | +| GuardMsgPackageEvent | 收到 GUARD_MSG 数据包 | 舰队消息(登船) | +| LivePackageEvent | 收到 LIVE 数据包 | 开始直播 | +| PkAgainPackageEvent | 收到 PK_AGAIN 数据包 | 下面几个都是 PK 有关的事件 | +| PkClickAgainPackageEvent | 收到 PK_CLICK_AGAIN 数据包 | | +| PkEndPackageEvent | 收到 PK_END 数据包 | | +| PkMatchPackageEvent | 收到 PK_MATCH 数据包 | | +| PkMicEndPackageEvent | 收到 PK_MIC_END 数据包 | | +| PkPrePackageEvent | 收到 PK_PRE 数据包 | | +| PkProcessPackageEvent | 收到 PK_PROCESS 数据包 | | +| PkSettlePackageEvent | 收到 PK_SETTLE 数据包 | | +| PkStartPackageEvent | 收到 PK_START 数据包 | | +| PreparingPackageEvent | 收到 PREPARING 数据包 | 停止直播 | +| RaffleEndPackageEvent | 收到 RAFFLE_END 数据包 | 抽奖结束(小奖, 通常是不定期活动) | +| RaffleStartPackageEvent | 收到 RAFFLE_START 数据包 | 抽奖开始(小奖) | +| ReceiveDataPackageDebugEvent | 该事件用于调试, 收到任何 Data 数据包时都会触发 | | +| RoomAdminsPackageEvent | 收到 ROOM_ADMINS 数据包 | 房管变更 | +| RoomBlockMsgPackageEvent | 收到 ROOM_BLOCK_MSG 数据包 | 房间黑名单(房间管理员添加了一个用户到黑名单) | +| RoomLockPackageEvent | 收到 ROOM_LOCK 数据包 | 房间被封 | +| RoomRankPackageEvent | 收到 ROOM_RANK 数据包 | 小时榜 | +| RoomShieldPackageEvent | 收到 ROOM_SHIELD 数据包 | 房间屏蔽 | +| RoomSilentOffPackageEvent | 收到 ROOM_SILENT_OFF 数据包 | 房间结束禁言 | +| RoomSilentOnPackageEvent | 收到 ROOM_SILENT_ON 数据包 | 房间开启了禁言(禁止某一等级以下的用户发言) | +| SendGiftPackageEvent | 收到 SEND_GIFT 数据包 | 送礼 | +| SendHeartBeatPackageEvent | 每次发送心跳包后触发一次 | | +| SpecialGiftPackageEvent | 收到 SPECIAL_GIFT 数据包 | 节奏风暴(20 倍以下的)(只在对应房间内有, 不会全站广播) | +| SysGiftPackageEvent | 收到 SYS_GIFT 数据包 | 系统礼物(20 倍以上节奏风暴, 活动抽奖等) | +| SysMsgPackageEvent | 收到 SYS_MSG 数据包 | 系统消息(小电视等) | +| TVEndPackageEvent | 收到 TV_END 数据包 | 小电视抽奖结束(大奖的获得者信息) | +| TVStartPackageEvent | 收到 TV_START 数据包 | 小电视抽奖开始 | +| UnknownPackageEvent | B站新增了新种类的数据包, 出现此情况请提交 issue | | +| ViewerCountPackageEvent | 收到 房间人数 数据包(不是 Json) | | +| WelcomePackageEvent | 收到 WELCOME 数据包 | 欢迎(通常是 VIP) | +| WelcomeActivityPackageEvent | 收到 WELCOME_ACTIVITY 数据包 | 欢迎(活动) | +| WelcomeGuardPackageEvent | 收到 WELCOME_GUARD 数据包 | 欢迎(舰队) | +| WishBottlePackageEvent | 收到 WISH_BOTTLE 数据包 | 许愿瓶 | 事件里面可以取到解析好的 POJO, 然后可以从里面取数据, 见上面的监听器示例. diff --git a/src/main/java/com/hiczp/bilibili/api/live/LiveService.java b/src/main/java/com/hiczp/bilibili/api/live/LiveService.java index 368deb9..a752db6 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/LiveService.java +++ b/src/main/java/com/hiczp/bilibili/api/live/LiveService.java @@ -204,8 +204,8 @@ public interface LiveService { /** * 发送一条弹幕 * - * @param cid 房间号 - * @param mid 自己的用户 ID + * @param roomId 房间号 + * @param userId 自己的用户 ID * @param message 内容 * @param random 随机数 * @param mode 弹幕模式 @@ -218,8 +218,8 @@ public interface LiveService { */ @POST("api/sendmsg") @FormUrlEncoded - Call sendBulletScreen(@Field("cid") long cid, - @Field("mid") long mid, + Call sendBulletScreen(@Field("cid") long roomId, + @Field("mid") long userId, @Field("msg") String message, @Field("rnd") long random, @Field("mode") int mode, @@ -236,8 +236,8 @@ public interface LiveService { */ default Call sendBulletScreen(BulletScreenEntity bulletScreenEntity) { return sendBulletScreen( - bulletScreenEntity.getCid(), - bulletScreenEntity.getMid(), + bulletScreenEntity.getRoomId(), + bulletScreenEntity.getUserId(), bulletScreenEntity.getMessage(), bulletScreenEntity.getRandom(), bulletScreenEntity.getMode(), diff --git a/src/main/java/com/hiczp/bilibili/api/live/entity/ActivityGiftsEntity.java b/src/main/java/com/hiczp/bilibili/api/live/entity/ActivityGiftsEntity.java index adbfa11..4846927 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/entity/ActivityGiftsEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/entity/ActivityGiftsEntity.java @@ -54,7 +54,7 @@ public class ActivityGiftsEntity extends ResponseEntity { @SerializedName("name") private String name; @SerializedName("num") - private int num; + private int number; @SerializedName("img") private String img; @SerializedName("gift_url") @@ -92,12 +92,12 @@ public class ActivityGiftsEntity extends ResponseEntity { this.name = name; } - public int getNum() { - return num; + public int getNumber() { + return number; } - public void setNum(int num) { - this.num = num; + public void setNumber(int number) { + this.number = number; } public String getImg() { diff --git a/src/main/java/com/hiczp/bilibili/api/live/entity/AllListEntity.java b/src/main/java/com/hiczp/bilibili/api/live/entity/AllListEntity.java index a0f94ae..8ba1653 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/entity/AllListEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/entity/AllListEntity.java @@ -1075,7 +1075,7 @@ public class AllListEntity extends ResponseEntity { @SerializedName("face") private String face; @SerializedName("mid") - private int mid; + private long userId; @SerializedName("name") private String name; @@ -1087,12 +1087,12 @@ public class AllListEntity extends ResponseEntity { this.face = face; } - public int getMid() { - return mid; + public long getUserId() { + return userId; } - public void setMid(int mid) { - this.mid = mid; + public void setUserId(long userId) { + this.userId = userId; } public String getName() { diff --git a/src/main/java/com/hiczp/bilibili/api/live/entity/AssistantRoomInfoEntity.java b/src/main/java/com/hiczp/bilibili/api/live/entity/AssistantRoomInfoEntity.java index e02f851..039b3ad 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/entity/AssistantRoomInfoEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/entity/AssistantRoomInfoEntity.java @@ -69,7 +69,7 @@ public class AssistantRoomInfoEntity extends ResponseEntity { @SerializedName("uname") private String username; @SerializedName("rcost") - private int rcost; + private int roomCost; @SerializedName("online") private int online; @SerializedName("status") @@ -141,12 +141,12 @@ public class AssistantRoomInfoEntity extends ResponseEntity { this.username = username; } - public int getRcost() { - return rcost; + public int getRoomCost() { + return roomCost; } - public void setRcost(int rcost) { - this.rcost = rcost; + public void setRoomCost(int roomCost) { + this.roomCost = roomCost; } public int getOnline() { diff --git a/src/main/java/com/hiczp/bilibili/api/live/entity/AwardsEntity.java b/src/main/java/com/hiczp/bilibili/api/live/entity/AwardsEntity.java index 69fc490..9ffb6bb 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/entity/AwardsEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/entity/AwardsEntity.java @@ -95,7 +95,7 @@ public class AwardsEntity extends ResponseEntity { @SerializedName("id") private int id; @SerializedName("uid") - private int uid; + private long userId; @SerializedName("gift_name") private String giftName; @SerializedName("gift_type") @@ -137,12 +137,12 @@ public class AwardsEntity extends ResponseEntity { this.id = id; } - public int getUid() { - return uid; + public long getUserId() { + return userId; } - public void setUid(int uid) { - this.uid = uid; + public void setUserId(long userId) { + this.userId = userId; } public String getGiftName() { diff --git a/src/main/java/com/hiczp/bilibili/api/live/entity/BulletScreenEntity.java b/src/main/java/com/hiczp/bilibili/api/live/entity/BulletScreenEntity.java index 3685eb3..d67bd30 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/entity/BulletScreenEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/entity/BulletScreenEntity.java @@ -3,9 +3,11 @@ package com.hiczp.bilibili.api.live.entity; import com.google.gson.annotations.SerializedName; public class BulletScreenEntity { - private long cid; + @SerializedName("cid") + private long roomId; - private long mid; + @SerializedName("mid") + private long userId; /** * 弹幕长度限制为 LiveRoomInfoEntity.getData().getMsgLength(), 对于每个用户而言, 每个房间都一样 @@ -50,27 +52,27 @@ public class BulletScreenEntity { /** * 实际上并不需要包含 mid 就可以正常发送弹幕, 但是真实的 Android 客户端确实发送了 mid */ - public BulletScreenEntity(long cid, long mid, String message) { - this.cid = cid; - this.mid = mid; + public BulletScreenEntity(long roomId, long userId, String message) { + this.roomId = roomId; + this.userId = userId; this.message = message; } - public long getCid() { - return cid; + public long getRoomId() { + return roomId; } - public BulletScreenEntity setCid(long cid) { - this.cid = cid; + public BulletScreenEntity setRoomId(long roomId) { + this.roomId = roomId; return this; } - public long getMid() { - return mid; + public long getUserId() { + return userId; } - public BulletScreenEntity setMid(long mid) { - this.mid = mid; + public BulletScreenEntity setUserId(long userId) { + this.userId = userId; return this; } diff --git a/src/main/java/com/hiczp/bilibili/api/live/entity/GiftEntity.java b/src/main/java/com/hiczp/bilibili/api/live/entity/GiftEntity.java index 2ce8acf..a9de08d 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/entity/GiftEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/entity/GiftEntity.java @@ -45,7 +45,7 @@ public class GiftEntity { } public GiftEntity(long giftId, long bagId, long number, LiveRoomInfoEntity.LiveRoom liveRoom) { - this(giftId, bagId, number, liveRoom.getRoomId(), liveRoom.getMid()); + this(giftId, bagId, number, liveRoom.getRoomId(), liveRoom.getUserId()); } public GiftEntity(PlayerBagEntity.BagGift bagGift, long number, long roomId, long roomUserId) { @@ -53,7 +53,7 @@ public class GiftEntity { } public GiftEntity(PlayerBagEntity.BagGift bagGift, long number, LiveRoomInfoEntity.LiveRoom liveRoom) { - this(bagGift.getGiftId(), bagGift.getId(), number, liveRoom.getRoomId(), liveRoom.getMid()); + this(bagGift.getGiftId(), bagGift.getId(), number, liveRoom.getRoomId(), liveRoom.getUserId()); } public long getGiftId() { diff --git a/src/main/java/com/hiczp/bilibili/api/live/entity/GiftTopEntity.java b/src/main/java/com/hiczp/bilibili/api/live/entity/GiftTopEntity.java index a3a105f..9956112 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/entity/GiftTopEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/entity/GiftTopEntity.java @@ -105,7 +105,7 @@ public class GiftTopEntity extends ResponseEntity { */ @SerializedName("uid") - private int uid; + private long userId; @SerializedName("rank") private int rank; @SerializedName("isSelf") @@ -121,12 +121,12 @@ public class GiftTopEntity extends ResponseEntity { @SerializedName("guard_level") private int guardLevel; - public int getUid() { - return uid; + public long getUserId() { + return userId; } - public void setUid(int uid) { - this.uid = uid; + public void setUserId(long userId) { + this.userId = userId; } public int getRank() { diff --git a/src/main/java/com/hiczp/bilibili/api/live/entity/LiveHistoryBulletScreensEntity.java b/src/main/java/com/hiczp/bilibili/api/live/entity/LiveHistoryBulletScreensEntity.java index 9cc9435..9005c29 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/entity/LiveHistoryBulletScreensEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/entity/LiveHistoryBulletScreensEntity.java @@ -77,7 +77,7 @@ public class LiveHistoryBulletScreensEntity extends ResponseEntity { @SerializedName("text") private String text; @SerializedName("uid") - private int uid; + private long userId; @SerializedName("nickname") private String nickname; @SerializedName("timeline") @@ -113,12 +113,12 @@ public class LiveHistoryBulletScreensEntity extends ResponseEntity { this.text = text; } - public int getUid() { - return uid; + public long getUserId() { + return userId; } - public void setUid(int uid) { - this.uid = uid; + public void setUserId(long userId) { + this.userId = userId; } public String getNickname() { diff --git a/src/main/java/com/hiczp/bilibili/api/live/entity/LiveRoomInfoEntity.java b/src/main/java/com/hiczp/bilibili/api/live/entity/LiveRoomInfoEntity.java index ce10593..b9efc8a 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/entity/LiveRoomInfoEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/entity/LiveRoomInfoEntity.java @@ -96,13 +96,13 @@ public class LiveRoomInfoEntity extends ResponseEntity { @SerializedName("cover") private String cover; @SerializedName("mid") - private long mid; + private long userId; @SerializedName("uname") private String username; @SerializedName("face") private String face; @SerializedName("m_face") - private String mFace; + private String mobileFace; @SerializedName("background_id") private int backgroundId; @SerializedName("attention") @@ -116,7 +116,7 @@ public class LiveRoomInfoEntity extends ResponseEntity { @SerializedName("create_at") private String createAt; @SerializedName("sch_id") - private int schId; + private int scheduleId; @SerializedName("status") private String status; @SerializedName("area") @@ -218,12 +218,12 @@ public class LiveRoomInfoEntity extends ResponseEntity { this.cover = cover; } - public long getMid() { - return mid; + public long getUserId() { + return userId; } - public void setMid(long mid) { - this.mid = mid; + public void setUserId(long userId) { + this.userId = userId; } public String getUsername() { @@ -242,12 +242,12 @@ public class LiveRoomInfoEntity extends ResponseEntity { this.face = face; } - public String getMFace() { - return mFace; + public String getMobileFace() { + return mobileFace; } - public void setMFace(String mFace) { - this.mFace = mFace; + public void setMobileFace(String mobileFace) { + this.mobileFace = mobileFace; } public int getBackgroundId() { @@ -298,12 +298,12 @@ public class LiveRoomInfoEntity extends ResponseEntity { this.createAt = createAt; } - public int getSchId() { - return schId; + public int getScheduleId() { + return scheduleId; } - public void setSchId(int schId) { - this.schId = schId; + public void setScheduleId(int scheduleId) { + this.scheduleId = scheduleId; } public String getStatus() { @@ -630,11 +630,11 @@ public class LiveRoomInfoEntity extends ResponseEntity { @SerializedName("cid") private long cid; @SerializedName("sch_id") - private int schId; + private int scheduleId; @SerializedName("title") private String title; @SerializedName("mid") - private long mid; + private long userId; @SerializedName("start") private long start; @SerializedName("start_at") @@ -662,12 +662,12 @@ public class LiveRoomInfoEntity extends ResponseEntity { this.cid = cid; } - public int getSchId() { - return schId; + public int getScheduleId() { + return scheduleId; } - public void setSchId(int schId) { - this.schId = schId; + public void setScheduleId(int scheduleId) { + this.scheduleId = scheduleId; } public String getTitle() { @@ -678,12 +678,12 @@ public class LiveRoomInfoEntity extends ResponseEntity { this.title = title; } - public long getMid() { - return mid; + public long getUserId() { + return userId; } - public void setMid(long mid) { - this.mid = mid; + public void setUserId(long userId) { + this.userId = userId; } public long getStart() { @@ -941,7 +941,7 @@ public class LiveRoomInfoEntity extends ResponseEntity { @SerializedName("face") private String face; @SerializedName("mid") - private int mid; + private long userId; @SerializedName("name") private String name; @@ -953,12 +953,12 @@ public class LiveRoomInfoEntity extends ResponseEntity { this.face = face; } - public int getMid() { - return mid; + public long getUserId() { + return userId; } - public void setMid(int mid) { - this.mid = mid; + public void setUserId(long userId) { + this.userId = userId; } public String getName() { diff --git a/src/main/java/com/hiczp/bilibili/api/live/entity/MyTitleListEntity.java b/src/main/java/com/hiczp/bilibili/api/live/entity/MyTitleListEntity.java index 6e72986..0d1ae05 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/entity/MyTitleListEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/entity/MyTitleListEntity.java @@ -59,7 +59,7 @@ public class MyTitleListEntity extends ResponseEntity { */ @SerializedName("uid") - private int uid; + private long userId; @SerializedName("had") private boolean had; @SerializedName("title") @@ -77,12 +77,12 @@ public class MyTitleListEntity extends ResponseEntity { @SerializedName("category") private List category; - public int getUid() { - return uid; + public long getUserId() { + return userId; } - public void setUid(int uid) { - this.uid = uid; + public void setUserId(long userId) { + this.userId = userId; } public boolean isHad() { diff --git a/src/main/java/com/hiczp/bilibili/api/live/entity/OpenCapsuleResponseEntity.java b/src/main/java/com/hiczp/bilibili/api/live/entity/OpenCapsuleResponseEntity.java index 42564ff..0e8d689 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/entity/OpenCapsuleResponseEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/entity/OpenCapsuleResponseEntity.java @@ -130,7 +130,7 @@ public class OpenCapsuleResponseEntity extends ResponseEntity { @SerializedName("name") private String name; @SerializedName("num") - private String num; + private String number; @SerializedName("img") private String img; @@ -142,12 +142,12 @@ public class OpenCapsuleResponseEntity extends ResponseEntity { this.name = name; } - public String getNum() { - return num; + public String getNumber() { + return number; } - public void setNum(String num) { - this.num = num; + public void setNumber(String number) { + this.number = number; } public String getImg() { diff --git a/src/main/java/com/hiczp/bilibili/api/live/entity/PlayerBagEntity.java b/src/main/java/com/hiczp/bilibili/api/live/entity/PlayerBagEntity.java index 4cfe906..dd64484 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/entity/PlayerBagEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/entity/PlayerBagEntity.java @@ -53,7 +53,7 @@ public class PlayerBagEntity extends ResponseEntity { @SerializedName("id") private long id; @SerializedName("uid") - private long uid; + private long userId; @SerializedName("gift_id") private long giftId; @SerializedName("gift_num") @@ -85,12 +85,12 @@ public class PlayerBagEntity extends ResponseEntity { this.id = id; } - public long getUid() { - return uid; + public long getUserId() { + return userId; } - public void setUid(long uid) { - this.uid = uid; + public void setUserId(long userId) { + this.userId = userId; } public long getGiftId() { diff --git a/src/main/java/com/hiczp/bilibili/api/live/entity/RecommendRoomRefreshResponseEntity.java b/src/main/java/com/hiczp/bilibili/api/live/entity/RecommendRoomRefreshResponseEntity.java index adbc813..1673b2b 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/entity/RecommendRoomRefreshResponseEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/entity/RecommendRoomRefreshResponseEntity.java @@ -578,7 +578,7 @@ public class RecommendRoomRefreshResponseEntity extends ResponseEntity { @SerializedName("face") private String face; @SerializedName("mid") - private int mid; + private long userId; @SerializedName("name") private String name; @@ -590,12 +590,12 @@ public class RecommendRoomRefreshResponseEntity extends ResponseEntity { this.face = face; } - public int getMid() { - return mid; + public long getUserId() { + return userId; } - public void setMid(int mid) { - this.mid = mid; + public void setUserId(long userId) { + this.userId = userId; } public String getName() { diff --git a/src/main/java/com/hiczp/bilibili/api/live/entity/SendGiftResponseEntity.java b/src/main/java/com/hiczp/bilibili/api/live/entity/SendGiftResponseEntity.java index ac93a8b..6e48512 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/entity/SendGiftResponseEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/entity/SendGiftResponseEntity.java @@ -125,7 +125,7 @@ public class SendGiftResponseEntity extends ResponseEntity { @SerializedName("uname") private String username; @SerializedName("rcost") - private int rcost; + private int roomCost; @SerializedName("uid") private int uid; @SerializedName("timestamp") @@ -206,12 +206,12 @@ public class SendGiftResponseEntity extends ResponseEntity { this.username = username; } - public int getRcost() { - return rcost; + public int getRoomCost() { + return roomCost; } - public void setRcost(int rcost) { - this.rcost = rcost; + public void setRoomCost(int roomCost) { + this.roomCost = roomCost; } public int getUid() { diff --git a/src/main/java/com/hiczp/bilibili/api/live/entity/UserTasksEntity.java b/src/main/java/com/hiczp/bilibili/api/live/entity/UserTasksEntity.java index d087f33..9eb7895 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/entity/UserTasksEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/entity/UserTasksEntity.java @@ -171,7 +171,7 @@ public class UserTasksEntity extends ResponseEntity { @SerializedName("type") private String type; @SerializedName("num") - private int num; + private int number; public String getName() { return name; @@ -189,12 +189,12 @@ public class UserTasksEntity extends ResponseEntity { this.type = type; } - public int getNum() { - return num; + public int getNumber() { + return number; } - public void setNum(int num) { - this.num = num; + public void setNumber(int number) { + this.number = number; } } } @@ -288,7 +288,7 @@ public class UserTasksEntity extends ResponseEntity { @SerializedName("type") private String type; @SerializedName("num") - private int num; + private int number; public String getName() { return name; @@ -306,12 +306,12 @@ public class UserTasksEntity extends ResponseEntity { this.type = type; } - public int getNum() { - return num; + public int getNumber() { + return number; } - public void setNum(int num) { - this.num = num; + public void setNumber(int number) { + this.number = number; } } } @@ -427,7 +427,7 @@ public class UserTasksEntity extends ResponseEntity { @SerializedName("type") private String type; @SerializedName("num") - private int num; + private int number; public String getName() { return name; @@ -445,12 +445,12 @@ public class UserTasksEntity extends ResponseEntity { this.type = type; } - public int getNum() { - return num; + public int getNumber() { + return number; } - public void setNum(int num) { - this.num = num; + public void setNumber(int number) { + this.number = number; } } } diff --git a/src/main/java/com/hiczp/bilibili/api/live/entity/WearTitleEntity.java b/src/main/java/com/hiczp/bilibili/api/live/entity/WearTitleEntity.java index e06871a..e660c9d 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/entity/WearTitleEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/entity/WearTitleEntity.java @@ -58,7 +58,7 @@ public class WearTitleEntity extends ResponseEntity { @SerializedName("tid") private String tid; @SerializedName("num") - private String num; + private String number; @SerializedName("score") private String score; @SerializedName("create_time") @@ -104,12 +104,12 @@ public class WearTitleEntity extends ResponseEntity { this.tid = tid; } - public String getNum() { - return num; + public String getNumber() { + return number; } - public void setNum(String num) { - this.num = num; + public void setNumber(String number) { + this.number = number; } public String getScore() { diff --git a/src/main/java/com/hiczp/bilibili/api/live/socket/LiveClient.java b/src/main/java/com/hiczp/bilibili/api/live/socket/LiveClient.java index 06899a7..c96cb55 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/socket/LiveClient.java +++ b/src/main/java/com/hiczp/bilibili/api/live/socket/LiveClient.java @@ -38,9 +38,9 @@ public class LiveClient { private final BilibiliServiceProvider bilibiliServiceProvider; private final EventLoopGroup eventLoopGroup; private final long userId; - private final EventBus eventBus = new EventBus("BilibiliLiveClientEventBus"); private Long showRoomId; private Long realRoomId; + private final EventBus eventBus; private boolean useRealRoomIdForConstructing; private LiveRoomInfoEntity.LiveRoom liveRoom; @@ -57,6 +57,7 @@ public class LiveClient { showRoomId = roomId; } this.userId = userId; + this.eventBus = new EventBus(String.format("BilibiliLiveClientEventBus-%s", getShowRoomIdOrRoomId())); } public LiveClient(@Nonnull BilibiliServiceProvider bilibiliServiceProvider, @Nonnull EventLoopGroup eventLoopGroup, long showRoomId, long userId) { diff --git a/src/main/java/com/hiczp/bilibili/api/live/socket/entity/GuardBuyEntity.java b/src/main/java/com/hiczp/bilibili/api/live/socket/entity/GuardBuyEntity.java index 0afc145..4603eba 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/socket/entity/GuardBuyEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/socket/entity/GuardBuyEntity.java @@ -50,20 +50,20 @@ public class GuardBuyEntity implements DataEntity { */ @SerializedName("uid") - private int uid; + private long userId; @SerializedName("username") private String username; @SerializedName("guard_level") private int guardLevel; @SerializedName("num") - private int num; + private int number; - public int getUid() { - return uid; + public long getUserId() { + return userId; } - public void setUid(int uid) { - this.uid = uid; + public void setUserId(long userId) { + this.userId = userId; } public String getUsername() { @@ -82,12 +82,12 @@ public class GuardBuyEntity implements DataEntity { this.guardLevel = guardLevel; } - public int getNum() { - return num; + public int getNumber() { + return number; } - public void setNum(int num) { - this.num = num; + public void setNumber(int number) { + this.number = number; } } } diff --git a/src/main/java/com/hiczp/bilibili/api/live/socket/entity/PkProcessEntity.java b/src/main/java/com/hiczp/bilibili/api/live/socket/entity/PkProcessEntity.java index 8415239..49e7404 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/socket/entity/PkProcessEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/socket/entity/PkProcessEntity.java @@ -72,7 +72,7 @@ public class PkProcessEntity implements DataEntity { */ @SerializedName("uid") - private int userId; + private long userId; @SerializedName("init_votes") private int initVotes; @SerializedName("match_votes") @@ -80,11 +80,11 @@ public class PkProcessEntity implements DataEntity { @SerializedName("user_votes") private int userVotes; - public int getUserId() { + public long getUserId() { return userId; } - public void setUserId(int userId) { + public void setUserId(long userId) { this.userId = userId; } diff --git a/src/main/java/com/hiczp/bilibili/api/live/socket/entity/RoomBlockMsgEntity.java b/src/main/java/com/hiczp/bilibili/api/live/socket/entity/RoomBlockMsgEntity.java index f757a7d..b0e91c9 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/socket/entity/RoomBlockMsgEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/socket/entity/RoomBlockMsgEntity.java @@ -13,7 +13,7 @@ public class RoomBlockMsgEntity implements DataEntity { @SerializedName("cmd") private String cmd; @SerializedName("uid") - private String uid; + private String userId; @SerializedName("uname") private String username; @SerializedName("roomid") @@ -28,12 +28,12 @@ public class RoomBlockMsgEntity implements DataEntity { this.cmd = cmd; } - public String getUid() { - return uid; + public String getUserId() { + return userId; } - public void setUid(String uid) { - this.uid = uid; + public void setUserId(String userId) { + this.userId = userId; } public String getUsername() { diff --git a/src/main/java/com/hiczp/bilibili/api/live/socket/entity/SendGiftEntity.java b/src/main/java/com/hiczp/bilibili/api/live/socket/entity/SendGiftEntity.java index cc1896b..ce4286a 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/socket/entity/SendGiftEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/socket/entity/SendGiftEntity.java @@ -73,13 +73,13 @@ public class SendGiftEntity implements DataEntity { @SerializedName("giftName") private String giftName; @SerializedName("num") - private int num; + private int number; @SerializedName("uname") private String username; @SerializedName("rcost") - private int rcost; + private int roomCost; @SerializedName("uid") - private long uid; + private long userId; @SerializedName("timestamp") private long timestamp; @SerializedName("giftId") @@ -156,12 +156,12 @@ public class SendGiftEntity implements DataEntity { this.giftName = giftName; } - public int getNum() { - return num; + public int getNumber() { + return number; } - public void setNum(int num) { - this.num = num; + public void setNumber(int number) { + this.number = number; } public String getUsername() { @@ -172,20 +172,20 @@ public class SendGiftEntity implements DataEntity { this.username = username; } - public int getRcost() { - return rcost; + public int getRoomCost() { + return roomCost; } - public void setRcost(int rcost) { - this.rcost = rcost; + public void setRoomCost(int roomCost) { + this.roomCost = roomCost; } - public long getUid() { - return uid; + public long getUserId() { + return userId; } - public void setUid(long uid) { - this.uid = uid; + public void setUserId(long userId) { + this.userId = userId; } public long getTimestamp() { @@ -477,7 +477,7 @@ public class SendGiftEntity implements DataEntity { @SerializedName("hadJoin") private int hadJoin; @SerializedName("num") - private int num; + private int number; @SerializedName("content") private String content; @SerializedName("action") @@ -509,12 +509,12 @@ public class SendGiftEntity implements DataEntity { this.hadJoin = hadJoin; } - public int getNum() { - return num; + public int getNumber() { + return number; } - public void setNum(int num) { - this.num = num; + public void setNumber(int number) { + this.number = number; } public String getContent() { @@ -727,7 +727,7 @@ public class SendGiftEntity implements DataEntity { */ @SerializedName("uid") - private int uid; + private long userId; @SerializedName("uname") private String username; @SerializedName("face") @@ -741,12 +741,12 @@ public class SendGiftEntity implements DataEntity { @SerializedName("isSelf") private int isSelf; - public int getUid() { - return uid; + public long getUserId() { + return userId; } - public void setUid(int uid) { - this.uid = uid; + public void setUserId(long userId) { + this.userId = userId; } public String getUsername() { diff --git a/src/main/java/com/hiczp/bilibili/api/live/socket/entity/WelcomeActivityEntity.java b/src/main/java/com/hiczp/bilibili/api/live/socket/entity/WelcomeActivityEntity.java index 302c5fb..0b6699b 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/socket/entity/WelcomeActivityEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/socket/entity/WelcomeActivityEntity.java @@ -39,7 +39,7 @@ public class WelcomeActivityEntity implements DataEntity { */ @SerializedName("uid") - private long uid; + private long userId; @SerializedName("uname") private String username; @SerializedName("type") @@ -47,12 +47,12 @@ public class WelcomeActivityEntity implements DataEntity { @SerializedName("display_mode") private int displayMode; - public long getUid() { - return uid; + public long getUserId() { + return userId; } - public void setUid(long uid) { - this.uid = uid; + public void setUserId(long userId) { + this.userId = userId; } public String getUsername() { diff --git a/src/main/java/com/hiczp/bilibili/api/live/socket/entity/WelcomeGuardEntity.java b/src/main/java/com/hiczp/bilibili/api/live/socket/entity/WelcomeGuardEntity.java index 4858d9b..40c8044 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/socket/entity/WelcomeGuardEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/socket/entity/WelcomeGuardEntity.java @@ -50,7 +50,7 @@ public class WelcomeGuardEntity implements DataEntity { */ @SerializedName("uid") - private int uid; + private long userId; @SerializedName("username") private String username; @SerializedName("guard_level") @@ -58,12 +58,12 @@ public class WelcomeGuardEntity implements DataEntity { @SerializedName("water_god") private Integer waterGod; - public int getUid() { - return uid; + public long getUserId() { + return userId; } - public void setUid(int uid) { - this.uid = uid; + public void setUserId(long userId) { + this.userId = userId; } public String getUsername() { diff --git a/src/main/java/com/hiczp/bilibili/api/live/socket/entity/WishBottleEntity.java b/src/main/java/com/hiczp/bilibili/api/live/socket/entity/WishBottleEntity.java index c9ac6e6..baf15ba 100644 --- a/src/main/java/com/hiczp/bilibili/api/live/socket/entity/WishBottleEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/live/socket/entity/WishBottleEntity.java @@ -87,7 +87,7 @@ public class WishBottleEntity implements DataEntity { @SerializedName("id") private long id; @SerializedName("uid") - private long uid; + private long userId; @SerializedName("type") private int type; @SerializedName("type_id") @@ -113,12 +113,12 @@ public class WishBottleEntity implements DataEntity { this.id = id; } - public long getUid() { - return uid; + public long getUserId() { + return userId; } - public void setUid(long uid) { - this.uid = uid; + public void setUserId(long userId) { + this.userId = userId; } public int getType() { 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 e10dcb5..3ad6629 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 @@ -19,6 +19,8 @@ import java.io.InputStreamReader; import java.lang.reflect.ParameterizedType; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.TimeUnit; public class LiveClientHandler extends SimpleChannelInboundHandler { @@ -26,6 +28,56 @@ public class LiveClientHandler extends SimpleChannelInboundHandler { private static final Gson GSON = new Gson(); private static final Gson PRETTY_PRINTING_GSON = new GsonBuilder().setPrettyPrinting().create(); private static final JsonParser JSON_PARSER = new JsonParser(); + private static final Object[] CMD_AND_EVENT_ARRAY = new Object[]{ + "ACTIVITY_EVENT", ActivityEventPackageEvent.class, //活动事件 + "CHANGE_ROOM_INFO", ChangeRoomInfoPackageEvent.class, //更换房间背景图片 + "COMBO_END", ComboEndPackageEvent.class, //COMBO + "COMBO_SEND", ComboSendPackageEvent.class, + "CUT_OFF", CutOffPackageEvent.class, //被 B站 管理员强制中断 + "DANMU_MSG", DanMuMsgPackageEvent.class, //弹幕消息 + "ENTRY_EFFECT", EntryEffectPackageEvent.class, //TODO 尚不明确 EntryEffect 和普通 Welcome 的区别 + "EVENT_CMD", EventCmdPackageEvent.class, //TODO 尚不明确 EVENT_CMD 的含义 + "GUARD_BUY", GuardBuyPackageEvent.class, //船票购买 + "GUARD_MSG", GuardMsgPackageEvent.class, //舰队消息(登船) + "LIVE", LivePackageEvent.class, //开始直播 + "PK_AGAIN", PkAgainPackageEvent.class, //PK + "PK_CLICK_AGAIN", PkClickAgainPackageEvent.class, + "PK_END", PkEndPackageEvent.class, + "PK_MATCH", PkMatchPackageEvent.class, + "PK_MIC_END", PkMicEndPackageEvent.class, + "PK_PRE", PkPrePackageEvent.class, + "PK_PROCESS", PkProcessPackageEvent.class, + "PK_SETTLE", PkSettlePackageEvent.class, + "PK_START", PkStartPackageEvent.class, + "PREPARING", PreparingPackageEvent.class, //停止直播 + "RAFFLE_END", RaffleEndPackageEvent.class, //抽奖结束 + "RAFFLE_START", RaffleStartPackageEvent.class, //抽奖开始(小奖, 通常是不定期活动) + "ROOM_ADMINS", RoomAdminsPackageEvent.class, //房管变更 + "ROOM_BLOCK_MSG", RoomBlockMsgPackageEvent.class, //房间黑名单(房间管理员添加了一个用户到黑名单) + "ROOM_LOCK", RoomLockPackageEvent.class, //房间被封 + "ROOM_RANK", RoomRankPackageEvent.class, //小时榜 + "ROOM_SHIELD", RoomShieldPackageEvent.class, //房间屏蔽 + "ROOM_SILENT_OFF", RoomSilentOffPackageEvent.class, //房间结束禁言 + "ROOM_SILENT_ON", RoomSilentOnPackageEvent.class, //房间开启了禁言(禁止某一等级以下的用户发言) + "SEND_GIFT", SendGiftPackageEvent.class, //送礼 + "SPECIAL_GIFT", SpecialGiftPackageEvent.class, //节奏风暴(20 倍以下的) + "SYS_GIFT", SysGiftPackageEvent.class, //系统礼物(节奏风暴, 活动抽奖等) + "SYS_MSG", SysMsgPackageEvent.class, //系统消息(小电视等) + "TV_END", TVEndPackageEvent.class, //小电视抽奖结束(大奖的获得者信息) + "TV_START", TVStartPackageEvent.class, //小电视抽奖开始 + "WELCOME", WelcomePackageEvent.class, //欢迎(通常是 VIP) + "WELCOME_ACTIVITY", WelcomeActivityPackageEvent.class, //欢迎(活动) + "WELCOME_GUARD", WelcomeGuardPackageEvent.class, //欢迎(舰队) + "WISH_BOTTLE", WishBottlePackageEvent.class //许愿瓶 + }; + private static final Map> EVENT_MAP = new HashMap<>(); + + static { + for (int i = 0; i < CMD_AND_EVENT_ARRAY.length; i += 2) { + //noinspection unchecked + EVENT_MAP.put((String) CMD_AND_EVENT_ARRAY[i], (Class) CMD_AND_EVENT_ARRAY[i + 1]); + } + } private final LiveClient liveClient; private final EventBus eventBus; @@ -79,201 +131,9 @@ public class LiveClientHandler extends SimpleChannelInboundHandler { e.printStackTrace(); break; } - eventBus.post(new ReceiveDataPackageDebugEvent(liveClient, jsonObject, cmd)); - Class eventType = null; - switch (cmd) { - //弹幕消息 - case "DANMU_MSG": { - eventType = DanMuMsgPackageEvent.class; - } - break; - //送礼 - case "SEND_GIFT": { - eventType = SendGiftPackageEvent.class; - } - break; - //combo - case "COMBO_SEND": { - eventType = ComboSendPackageEvent.class; - } - break; - case "COMBO_END": { - eventType = ComboEndPackageEvent.class; - } - break; - //欢迎 - case "WELCOME": { - eventType = WelcomePackageEvent.class; - } - break; - //许愿瓶 - case "WISH_BOTTLE": { - eventType = WishBottlePackageEvent.class; - } - break; - //欢迎(舰队) - case "WELCOME_GUARD": { - eventType = WelcomeGuardPackageEvent.class; - } - break; - //TODO 尚不明确 EntryEffect 和普通 Welcome 的区别 - case "ENTRY_EFFECT": { - eventType = EntryEffectPackageEvent.class; - } - break; - //PK - case "PK_MATCH": { - eventType = PkMatchPackageEvent.class; - } - break; - case "PK_PRE": { - eventType = PkPrePackageEvent.class; - } - break; - case "PK_START": { - eventType = PkStartPackageEvent.class; - } - break; - case "PK_PROCESS": { - eventType = PkProcessPackageEvent.class; - } - break; - case "PK_END": { - eventType = PkEndPackageEvent.class; - } - break; - case "PK_MIC_END": { - eventType = PkMicEndPackageEvent.class; - } - break; - case "PK_SETTLE": { - eventType = PkSettlePackageEvent.class; - } - break; - case "PK_AGAIN": { - eventType = PkAgainPackageEvent.class; - } - break; - case "PK_CLICK_AGAIN": { - eventType = PkClickAgainPackageEvent.class; - } - break; - //系统消息(小电视等) - case "SYS_MSG": { - eventType = SysMsgPackageEvent.class; - } - break; - //系统礼物(节奏风暴, 活动抽奖等) - case "SYS_GIFT": { - eventType = SysGiftPackageEvent.class; - } - break; - //活动事件 - case "ACTIVITY_EVENT": { - eventType = ActivityEventPackageEvent.class; - } - break; - //节奏风暴(20 倍以下的) - case "SPECIAL_GIFT": { - eventType = SpecialGiftPackageEvent.class; - } - break; - //抽奖开始(小奖, 通常是不定期活动) - case "RAFFLE_START": { - eventType = RaffleStartPackageEvent.class; - } - break; - //抽奖结束 - case "RAFFLE_END": { - eventType = RaffleEndPackageEvent.class; - } - break; - //TODO 尚不明确 EVENT_CMD 的含义 - case "EVENT_CMD": { - eventType = EventCmdPackageEvent.class; - } - break; - //房间黑名单(房间管理员添加了一个用户到黑名单) - case "ROOM_BLOCK_MSG": { - eventType = RoomBlockMsgPackageEvent.class; - } - break; - //房间开启了禁言(禁止某一等级以下的用户发言) - case "ROOM_SILENT_ON": { - eventType = RoomSilentOnPackageEvent.class; - } - break; - //房间结束禁言 - case "ROOM_SILENT_OFF": { - eventType = RoomSilentOffPackageEvent.class; - } - break; - //船票购买 - case "GUARD_BUY": { - eventType = GuardBuyPackageEvent.class; - } - break; - //舰队消息(登船) - case "GUARD_MSG": { - eventType = GuardMsgPackageEvent.class; - } - break; - //小电视抽奖开始 - case "TV_START": { - eventType = TVStartPackageEvent.class; - } - break; - //小电视抽奖结束(大奖的获得者信息) - case "TV_END": { - eventType = TVEndPackageEvent.class; - } - break; - //小时榜 - case "ROOM_RANK": { - eventType = RoomRankPackageEvent.class; - } - break; - //欢迎(活动) - case "WELCOME_ACTIVITY": { - eventType = WelcomeActivityPackageEvent.class; - } - break; - //房管变更 - case "ROOM_ADMINS": { - eventType = RoomAdminsPackageEvent.class; - } - break; - //开始直播 - case "LIVE": { - eventType = LivePackageEvent.class; - } - break; - //停止直播 - case "PREPARING": { - eventType = PreparingPackageEvent.class; - } - break; - //房间屏蔽 - case "ROOM_SHIELD": { - eventType = RoomShieldPackageEvent.class; - } - break; - //更换房间背景图片 - case "CHANGE_ROOM_INFO": { - eventType = ChangeRoomInfoPackageEvent.class; - } - break; - //被 B站 管理员强制中断 - case "CUT_OFF": { - eventType = CutOffPackageEvent.class; - } - break; - //房间被封 - case "ROOM_LOCK": { - eventType = RoomLockPackageEvent.class; - } - break; - } + eventBus.post(new ReceiveDataPackageDebugEvent(liveClient, jsonObject, cmd)); //debug 用 + + Class eventType = EVENT_MAP.get(cmd); //UnknownPackage if (eventType == null) { diff --git a/src/main/java/com/hiczp/bilibili/api/passport/entity/InfoEntity.java b/src/main/java/com/hiczp/bilibili/api/passport/entity/InfoEntity.java index 1f2b53d..6d0dd9b 100644 --- a/src/main/java/com/hiczp/bilibili/api/passport/entity/InfoEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/passport/entity/InfoEntity.java @@ -51,7 +51,7 @@ public class InfoEntity extends ResponseEntity { */ @SerializedName("mid") - private long mid; + private long userId; @SerializedName("appid") private int appId; @SerializedName("access_token") @@ -59,16 +59,16 @@ public class InfoEntity extends ResponseEntity { @SerializedName("expires_in") private long expiresIn; @SerializedName("userid") - private String userId; + private String userIdString; @SerializedName("uname") private String username; - public long getMid() { - return mid; + public long getUserId() { + return userId; } - public void setMid(long mid) { - this.mid = mid; + public void setUserId(long userId) { + this.userId = userId; } public int getAppId() { @@ -95,12 +95,12 @@ public class InfoEntity extends ResponseEntity { this.expiresIn = expiresIn; } - public String getUserId() { - return userId; + public String getUserIdString() { + return userIdString; } - public void setUserId(String userId) { - this.userId = userId; + public void setUserIdString(String userIdString) { + this.userIdString = userIdString; } public String getUsername() { diff --git a/src/main/java/com/hiczp/bilibili/api/passport/entity/LoginResponseEntity.java b/src/main/java/com/hiczp/bilibili/api/passport/entity/LoginResponseEntity.java index 077c75e..ca18b12 100644 --- a/src/main/java/com/hiczp/bilibili/api/passport/entity/LoginResponseEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/passport/entity/LoginResponseEntity.java @@ -45,7 +45,7 @@ public class LoginResponseEntity extends ResponseEntity { return new BilibiliAccount( this.data.accessToken, this.data.refreshToken, - this.data.mid, + this.data.userId, this.data.expiresIn, this.timestamp ); @@ -64,7 +64,7 @@ public class LoginResponseEntity extends ResponseEntity { @SerializedName("refresh_token") private String refreshToken; @SerializedName("mid") - private long mid; + private long userId; @SerializedName("expires_in") private long expiresIn; @@ -84,12 +84,12 @@ public class LoginResponseEntity extends ResponseEntity { this.refreshToken = refreshToken; } - public long getMid() { - return mid; + public long getUserId() { + return userId; } - public void setMid(long mid) { - this.mid = mid; + public void setUserId(long userId) { + this.userId = userId; } public long getExpiresIn() { diff --git a/src/main/java/com/hiczp/bilibili/api/passport/entity/RefreshTokenResponseEntity.java b/src/main/java/com/hiczp/bilibili/api/passport/entity/RefreshTokenResponseEntity.java index 8e30245..bfc32e1 100644 --- a/src/main/java/com/hiczp/bilibili/api/passport/entity/RefreshTokenResponseEntity.java +++ b/src/main/java/com/hiczp/bilibili/api/passport/entity/RefreshTokenResponseEntity.java @@ -45,7 +45,7 @@ public class RefreshTokenResponseEntity extends ResponseEntity { return new BilibiliAccount( this.data.accessToken, this.data.refreshToken, - this.data.mid, + this.data.userId, this.data.expiresIn, this.ts ); @@ -60,7 +60,7 @@ public class RefreshTokenResponseEntity extends ResponseEntity { */ @SerializedName("mid") - private long mid; + private long userId; @SerializedName("refresh_token") private String refreshToken; @SerializedName("access_token") @@ -68,12 +68,12 @@ public class RefreshTokenResponseEntity extends ResponseEntity { @SerializedName("expires_in") private long expiresIn; - public long getMid() { - return mid; + public long getUserId() { + return userId; } - public void setMid(long mid) { - this.mid = mid; + public void setUserId(long userId) { + this.userId = userId; } public String getRefreshToken() { diff --git a/src/test/java/com/hiczp/bilibili/api/test/Config.java b/src/test/java/com/hiczp/bilibili/api/test/Config.java index eea2a12..368489c 100644 --- a/src/test/java/com/hiczp/bilibili/api/test/Config.java +++ b/src/test/java/com/hiczp/bilibili/api/test/Config.java @@ -8,7 +8,7 @@ public class Config { private String username; private String password; - private int roomId; + private long roomId; static Config getInstance() { return config; @@ -34,11 +34,11 @@ public class Config { this.password = password; } - int getRoomId() { + long getRoomId() { return roomId; } - public void setRoomId(int roomId) { + public void setRoomId(long roomId) { this.roomId = roomId; } diff --git a/src/test/java/com/hiczp/bilibili/api/test/LiveClientTest.java b/src/test/java/com/hiczp/bilibili/api/test/LiveClientTest.java index 80e3b71..ee0c176 100644 --- a/src/test/java/com/hiczp/bilibili/api/test/LiveClientTest.java +++ b/src/test/java/com/hiczp/bilibili/api/test/LiveClientTest.java @@ -130,7 +130,7 @@ public class LiveClientTest { LOGGER.info("[SendGift] {} give {}*{}", data.getUsername(), data.getGiftName(), - data.getNum() + data.getNumber() ); }