diff --git a/CHANGELOG.md b/CHANGELOG.md
index a8a0fc7..c6909ad 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,19 @@
# Release Notes
# 本项目Log
+## v0.3.0.200410 alpha (2020-04-10)
+
+### Added
+-
+
+### Changed
+-
+
+### Fixed
+- 修复备用监控无法获取
+- 修复获取分区ID异常
+-
+
## v0.3.0.200404 alpha (2020-04-04)
### Added
diff --git a/DOC.md b/DOC.md
index 002b6e0..ab32281 100644
--- a/DOC.md
+++ b/DOC.md
@@ -2,7 +2,7 @@

-
+
@@ -15,30 +15,30 @@ B 站直播实用脚本
|plugin |version |description |
|--------------------|--------------------|--------------------|
-|Login |20.04.04 |账号登录 |
-|Schedule |20.04.04 |休眠控制 |
-|MasterSite |20.04.04 |主站助手 |
-|Daily |20.04.04 |每日礼包 |
-|Heart |20.04.04 |双端心跳 |
-|Task |20.04.04 |每日任务 |
-|Silver |20.04.04 |银瓜子宝箱 |
-|Barrage |20.04.04 |活跃弹幕 |
-|Silver2Coin |20.04.04 |银瓜子换硬币 |
-|GiftSend |20.04.04 |礼物赠送 |
-|Judge |20.04.04 |风纪 |
-|GroupSignIn |20.04.04 |友爱社签到 |
-|ManGa |20.04.04 |漫画签到分享 |
-|GiftHeart |20.04.04 |心跳礼物 |
-|MaterialObject |20.04.04 |实物抽奖 |
-|AloneTcpClient |20.04.04 |独立监控 |
-|ZoneTcpClient |20.04.04 |分区监控 |
-|StormRaffle |20.04.04 |节奏风暴 |
-|GiftRaffle |20.04.04 |活动礼物 |
-|PkRaffle |20.04.04 |大乱斗 |
-|GuardRaffle |20.04.04 |舰长总督 |
-|AnchorRaffle |20.04.04 |天选时刻 |
-|AwardRecord |20.04.04 |获奖通知 |
-|Statistics |20.04.04 |数据统计 |
+|Login |20.04.10 |账号登录 |
+|Schedule |20.04.10 |休眠控制 |
+|MasterSite |20.04.10 |主站助手 |
+|Daily |20.04.10 |每日礼包 |
+|Heart |20.04.10 |双端心跳 |
+|Task |20.04.10 |每日任务 |
+|Silver |20.04.10 |银瓜子宝箱 |
+|Barrage |20.04.10 |活跃弹幕 |
+|Silver2Coin |20.04.10 |银瓜子换硬币 |
+|GiftSend |20.04.10 |礼物赠送 |
+|Judge |20.04.10 |风纪 |
+|GroupSignIn |20.04.10 |友爱社签到 |
+|ManGa |20.04.10 |漫画签到分享 |
+|GiftHeart |20.04.10 |心跳礼物 |
+|MaterialObject |20.04.10 |实物抽奖 |
+|AloneTcpClient |20.04.10 |独立监控 |
+|ZoneTcpClient |20.04.10 |分区监控 |
+|StormRaffle |20.04.10 |节奏风暴 |
+|GiftRaffle |20.04.10 |活动礼物 |
+|PkRaffle |20.04.10 |大乱斗 |
+|GuardRaffle |20.04.10 |舰长总督 |
+|AnchorRaffle |20.04.10 |天选时刻 |
+|AwardRecord |20.04.10 |获奖通知 |
+|Statistics |20.04.10 |数据统计 |
## 打赏赞助
diff --git a/README.md b/README.md
index 7e5a149..cd097a5 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@ Group: [55308141](https://jq.qq.com/?_wv=1027&k=5AIDaJg) | **仅用于BUG提交
## 公告
-Currently for Personal Edition **0.3.0.200404 alpha**
+Currently for Personal Edition **0.3.0.200410 alpha**
## 文档
diff --git a/src/plugin/Live.php b/src/plugin/Live.php
index a44e412..f4dbe87 100644
--- a/src/plugin/Live.php
+++ b/src/plugin/Live.php
@@ -62,7 +62,7 @@ class Live
$raw = Curl::get('other', $url, $payload);
$de_raw = json_decode($raw, true);
// 防止异常
- if (!isset($de_raw['data']) || $de_raw['code']) {
+ if (!isset($de_raw['data']) || $de_raw['code'] || count($de_raw['data']) == 0) {
Log::warning("获取直播分区异常: " . $de_raw['msg']);
$area_info = [
'area_id' => $area_id,
@@ -142,6 +142,35 @@ class Live
return json_decode($raw, true);
}
+ /**
+ * @use 获取直播间弹幕信息
+ * @param $room_id
+ * @return array
+ */
+ public static function getDanMuConf($room_id): array
+ {
+ $url = 'https://api.live.bilibili.com/room/v1/Danmu/getConf';
+ $payload = [
+ 'room_id' => $room_id,
+ 'platform' => 'pc',
+ 'player' => 'web'
+ ];
+ $raw = Curl::get('other', $url, $payload);
+ return json_decode($raw, true);
+ }
+
+
+ /**
+ * @use 获取弹幕信息Token
+ * @param $room_id
+ * @return string
+ */
+ public static function getDanMuToken($room_id): string
+ {
+ $data = self::getDanMuConf($room_id);
+ return $data['data']['token'];
+ }
+
/**
* @use web端获取直播间信息
diff --git a/src/plugin/ZoneTcpClient.php b/src/plugin/ZoneTcpClient.php
index 5b3f5a0..6d97c0b 100644
--- a/src/plugin/ZoneTcpClient.php
+++ b/src/plugin/ZoneTcpClient.php
@@ -149,6 +149,9 @@ class ZoneTcpClient
*/
private static function analyJson($data = '', $assoc = true)
{
+ if (is_array($data)) {
+ return $data;
+ }
$data = json_decode($data, $assoc);
if (($data && is_object($data)) || (is_array($data) && !empty($data))) {
return $data;
@@ -183,6 +186,24 @@ class ZoneTcpClient
}
$data = [];
switch ($de_raw['cmd']) {
+ case 'TV_START':
+ // 小电视
+ break;
+ case 'RAFFLE_START':
+ // 活动礼物
+ break;
+ case 'LOTTERY_START':
+ // 抽奖
+ break;
+ case 'PK_LOTTERY_START':
+ // 乱斗
+ break;
+ case 'GUARD_LOTTERY_START':
+ // 舰长
+ break;
+ case 'ALL_MSG':
+ // 未知
+ break;
case 'NOTICE_MSG':
$msg_type = $de_raw['msg_type'];
$msg_self = $de_raw['msg_self'];
@@ -311,8 +332,13 @@ class ZoneTcpClient
private static function genHandshakePkg($room_id): string
{
return self::packMsg(json_encode([
- 'uid' => mt_rand(1000000, 2999999),
- 'roomid' => intval($room_id),
+ "uid" => 0,
+ "roomid" => intval($room_id),
+ "protover" => 2,
+ "platform" => "web",
+ "clientver" => "1.10.6",
+ "type" => 2,
+ "key" => Live::getDanMuToken($room_id)
]), 0x0007);
}
@@ -336,8 +362,10 @@ class ZoneTcpClient
*/
private static function unPackMsg($value)
{
- $res = unpack('Npacklen/nheadlen/nver/Nop/Nseq', $value);
- return $res;
+ if (strlen($value) < 4) exit();
+ $head = unpack('Npacklen/nheadlen/nver/Nop/Nseq', $value);
+ // Log::info(json_encode($head, true));
+ return $head;
}
@@ -448,11 +476,38 @@ class ZoneTcpClient
if (!$len_body)
continue;
$body = self::reader($len_body);
- if ($body)
- self::onMessage($body, $type);
+ if ($body) {
+ if ($head['ver'] == 2) {
+ $data_list = self::v2_split($body, $len_body);
+ foreach ($data_list as $body) {
+ self::onMessage($body, $type);
+ }
+ } else {
+ self::onMessage($body, $type);
+ }
+ }
}
}
+ private static function v2_split($bin, $total)
+ {
+ $list = [];
+ $step = 0;
+ $data = gzuncompress($bin);
+ $total = strlen($data);
+ while (true) {
+ if ($step > 65535) exit();
+ if ($step == $total) break;
+ $bin = substr($data, $step, 16);
+ $head = self::unPackMsg($bin);
+ $length = isset($head['packlen']) ? $head['packlen'] : 16;
+ $body = substr($data, $step + 16, $length - 16);
+ $step += $length;
+ array_push($list, $body);
+ }
+ return $list;
+ }
+
/*
* @use replace delay by select
*/