mirror of
https://github.com/lkeme/BiliHelper-personal.git
synced 2025-12-21 19:20:06 +08:00
[fix] ZoneTcpClient
This commit is contained in:
parent
efc8ef84e9
commit
15bb434c1b
13
CHANGELOG.md
13
CHANGELOG.md
@ -1,6 +1,19 @@
|
|||||||
# Release Notes
|
# Release Notes
|
||||||
# 本项目Log
|
# 本项目Log
|
||||||
|
|
||||||
|
## v0.3.0.200410 alpha (2020-04-10)
|
||||||
|
|
||||||
|
### Added
|
||||||
|
-
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
-
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- 修复备用监控无法获取
|
||||||
|
- 修复获取分区ID异常
|
||||||
|
-
|
||||||
|
|
||||||
## v0.3.0.200404 alpha (2020-04-04)
|
## v0.3.0.200404 alpha (2020-04-04)
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
50
DOC.md
50
DOC.md
@ -2,7 +2,7 @@
|
|||||||
<p align="center"><img width="300px" src="https://i.loli.net/2018/04/20/5ad97bd395912.jpeg"></p>
|
<p align="center"><img width="300px" src="https://i.loli.net/2018/04/20/5ad97bd395912.jpeg"></p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://img.shields.io/badge/version-0.3.0.200404 alpha-green.svg?longCache=true&style=for-the-badge">
|
<img src="https://img.shields.io/badge/version-0.3.0.200410 alpha-green.svg?longCache=true&style=for-the-badge">
|
||||||
<img src="https://img.shields.io/badge/license-mit-blue.svg?longCache=true&style=for-the-badge">
|
<img src="https://img.shields.io/badge/license-mit-blue.svg?longCache=true&style=for-the-badge">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@ -15,30 +15,30 @@ B 站直播实用脚本
|
|||||||
|
|
||||||
|plugin |version |description |
|
|plugin |version |description |
|
||||||
|--------------------|--------------------|--------------------|
|
|--------------------|--------------------|--------------------|
|
||||||
|Login |20.04.04 |账号登录 |
|
|Login |20.04.10 |账号登录 |
|
||||||
|Schedule |20.04.04 |休眠控制 |
|
|Schedule |20.04.10 |休眠控制 |
|
||||||
|MasterSite |20.04.04 |主站助手 |
|
|MasterSite |20.04.10 |主站助手 |
|
||||||
|Daily |20.04.04 |每日礼包 |
|
|Daily |20.04.10 |每日礼包 |
|
||||||
|Heart |20.04.04 |双端心跳 |
|
|Heart |20.04.10 |双端心跳 |
|
||||||
|Task |20.04.04 |每日任务 |
|
|Task |20.04.10 |每日任务 |
|
||||||
|Silver |20.04.04 |银瓜子宝箱 |
|
|Silver |20.04.10 |银瓜子宝箱 |
|
||||||
|Barrage |20.04.04 |活跃弹幕 |
|
|Barrage |20.04.10 |活跃弹幕 |
|
||||||
|Silver2Coin |20.04.04 |银瓜子换硬币 |
|
|Silver2Coin |20.04.10 |银瓜子换硬币 |
|
||||||
|GiftSend |20.04.04 |礼物赠送 |
|
|GiftSend |20.04.10 |礼物赠送 |
|
||||||
|Judge |20.04.04 |风纪 |
|
|Judge |20.04.10 |风纪 |
|
||||||
|GroupSignIn |20.04.04 |友爱社签到 |
|
|GroupSignIn |20.04.10 |友爱社签到 |
|
||||||
|ManGa |20.04.04 |漫画签到分享 |
|
|ManGa |20.04.10 |漫画签到分享 |
|
||||||
|GiftHeart |20.04.04 |心跳礼物 |
|
|GiftHeart |20.04.10 |心跳礼物 |
|
||||||
|MaterialObject |20.04.04 |实物抽奖 |
|
|MaterialObject |20.04.10 |实物抽奖 |
|
||||||
|AloneTcpClient |20.04.04 |独立监控 |
|
|AloneTcpClient |20.04.10 |独立监控 |
|
||||||
|ZoneTcpClient |20.04.04 |分区监控 |
|
|ZoneTcpClient |20.04.10 |分区监控 |
|
||||||
|StormRaffle |20.04.04 |节奏风暴 |
|
|StormRaffle |20.04.10 |节奏风暴 |
|
||||||
|GiftRaffle |20.04.04 |活动礼物 |
|
|GiftRaffle |20.04.10 |活动礼物 |
|
||||||
|PkRaffle |20.04.04 |大乱斗 |
|
|PkRaffle |20.04.10 |大乱斗 |
|
||||||
|GuardRaffle |20.04.04 |舰长总督 |
|
|GuardRaffle |20.04.10 |舰长总督 |
|
||||||
|AnchorRaffle |20.04.04 |天选时刻 |
|
|AnchorRaffle |20.04.10 |天选时刻 |
|
||||||
|AwardRecord |20.04.04 |获奖通知 |
|
|AwardRecord |20.04.10 |获奖通知 |
|
||||||
|Statistics |20.04.04 |数据统计 |
|
|Statistics |20.04.10 |数据统计 |
|
||||||
|
|
||||||
## 打赏赞助
|
## 打赏赞助
|
||||||
|
|
||||||
|
|||||||
@ -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**
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
|
|||||||
@ -62,7 +62,7 @@ class Live
|
|||||||
$raw = Curl::get('other', $url, $payload);
|
$raw = Curl::get('other', $url, $payload);
|
||||||
$de_raw = json_decode($raw, true);
|
$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']);
|
Log::warning("获取直播分区异常: " . $de_raw['msg']);
|
||||||
$area_info = [
|
$area_info = [
|
||||||
'area_id' => $area_id,
|
'area_id' => $area_id,
|
||||||
@ -142,6 +142,35 @@ class Live
|
|||||||
return json_decode($raw, true);
|
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端获取直播间信息
|
* @use web端获取直播间信息
|
||||||
|
|||||||
@ -149,6 +149,9 @@ class ZoneTcpClient
|
|||||||
*/
|
*/
|
||||||
private static function analyJson($data = '', $assoc = true)
|
private static function analyJson($data = '', $assoc = true)
|
||||||
{
|
{
|
||||||
|
if (is_array($data)) {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
$data = json_decode($data, $assoc);
|
$data = json_decode($data, $assoc);
|
||||||
if (($data && is_object($data)) || (is_array($data) && !empty($data))) {
|
if (($data && is_object($data)) || (is_array($data) && !empty($data))) {
|
||||||
return $data;
|
return $data;
|
||||||
@ -183,6 +186,24 @@ class ZoneTcpClient
|
|||||||
}
|
}
|
||||||
$data = [];
|
$data = [];
|
||||||
switch ($de_raw['cmd']) {
|
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':
|
case 'NOTICE_MSG':
|
||||||
$msg_type = $de_raw['msg_type'];
|
$msg_type = $de_raw['msg_type'];
|
||||||
$msg_self = $de_raw['msg_self'];
|
$msg_self = $de_raw['msg_self'];
|
||||||
@ -311,8 +332,13 @@ class ZoneTcpClient
|
|||||||
private static function genHandshakePkg($room_id): string
|
private static function genHandshakePkg($room_id): string
|
||||||
{
|
{
|
||||||
return self::packMsg(json_encode([
|
return self::packMsg(json_encode([
|
||||||
'uid' => mt_rand(1000000, 2999999),
|
"uid" => 0,
|
||||||
'roomid' => intval($room_id),
|
"roomid" => intval($room_id),
|
||||||
|
"protover" => 2,
|
||||||
|
"platform" => "web",
|
||||||
|
"clientver" => "1.10.6",
|
||||||
|
"type" => 2,
|
||||||
|
"key" => Live::getDanMuToken($room_id)
|
||||||
]), 0x0007);
|
]), 0x0007);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,8 +362,10 @@ class ZoneTcpClient
|
|||||||
*/
|
*/
|
||||||
private static function unPackMsg($value)
|
private static function unPackMsg($value)
|
||||||
{
|
{
|
||||||
$res = unpack('Npacklen/nheadlen/nver/Nop/Nseq', $value);
|
if (strlen($value) < 4) exit();
|
||||||
return $res;
|
$head = unpack('Npacklen/nheadlen/nver/Nop/Nseq', $value);
|
||||||
|
// Log::info(json_encode($head, true));
|
||||||
|
return $head;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -448,9 +476,36 @@ class ZoneTcpClient
|
|||||||
if (!$len_body)
|
if (!$len_body)
|
||||||
continue;
|
continue;
|
||||||
$body = self::reader($len_body);
|
$body = self::reader($len_body);
|
||||||
if ($body)
|
if ($body) {
|
||||||
|
if ($head['ver'] == 2) {
|
||||||
|
$data_list = self::v2_split($body, $len_body);
|
||||||
|
foreach ($data_list as $body) {
|
||||||
self::onMessage($body, $type);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user