diff --git a/.gitignore b/.gitignore index c78a40b..d5399c1 100644 --- a/.gitignore +++ b/.gitignore @@ -22,5 +22,6 @@ Traits/ README1.md conf/user.conf /conf/user.conf +/conf/test.conf /log/ /src/backup/ \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 510524d..d8288a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,21 @@ # Release Notes # 本项目Log +## v0.6.5.200808 alpha (2020-08-08) + +### Added +- 添加小心心支持 +- 添加活动抽奖 +- + +### Changed +- 去掉无效双端观看 +- 过期小心心赠送 + +### Fixed +- 修复小心心心跳错误 +- + ## v0.6.0.200730 alpha (2020-07-30) ### Added diff --git a/DOC.md b/DOC.md index 0acb539..8072dbb 100644 --- a/DOC.md +++ b/DOC.md @@ -2,7 +2,7 @@

- +

@@ -15,34 +15,35 @@ B 站直播实用脚本 |plugin |version |description | |--------------------|--------------------|--------------------| -|Login |20.07.30 |账号登录 | -|Schedule |20.07.30 |休眠控制 | -|MasterSite |20.07.30 |主站助手 | -|Daily |20.07.30 |每日礼包 | -|Heart |20.07.30 |双端心跳 | -|Task |20.07.30 |每日任务 | -|Silver |20.07.30 |银瓜子宝箱 | -|Barrage |20.07.30 |活跃弹幕 | -|Silver2Coin |20.07.30 |银瓜子换硬币 | -|GiftSend |20.07.30 |礼物赠送 | -|Judge |20.07.30 |风纪 | -|GroupSignIn |20.07.30 |友爱社签到 | -|ManGa |20.07.30 |漫画签到分享 | -|Match |20.07.30 |赛事签到分享 | -|GiftHeart |20.07.30 |心跳礼物 | -|MaterialObject |20.07.30 |实物抽奖 | -|AloneTcpClient |20.07.30 |独立监控 | -|ZoneTcpClient |20.07.30 |分区监控 | -|StormRaffle |20.07.30 |节奏风暴 | -|GiftRaffle |20.07.30 |活动礼物 | -|PkRaffle |20.07.30 |大乱斗 | -|GuardRaffle |20.07.30 |舰长总督 | -|AnchorRaffle |20.07.30 |天选时刻 | -|AwardRecord |20.07.30 |获奖通知 | -|Statistics |20.07.30 |数据统计 | -|Competition |20.07.30 |赛事竞猜 | -|SmallHeart |20.07.30 |小心心 | - +|Login |20.08.08 |账号登录 | +|Schedule |20.08.08 |休眠控制 | +|MasterSite |20.08.08 |主站助手 | +|Daily |20.08.08 |每日礼包 | +|Heart |20.08.08 |双端心跳 | +|Task |20.08.08 |每日任务 | +|Silver |20.08.08 |银瓜子宝箱 | +|Barrage |20.08.08 |活跃弹幕 | +|Silver2Coin |20.08.08 |银瓜子换硬币 | +|GiftSend |20.08.08 |礼物赠送 | +|Judge |20.08.08 |风纪 | +|GroupSignIn |20.08.08 |友爱社签到 | +|ManGa |20.08.08 |漫画签到分享 | +|Match |20.08.08 |赛事签到分享 | +|GiftHeart |20.08.08 |心跳礼物 | +|MaterialObject |20.08.08 |实物抽奖 | +|AloneTcpClient |20.08.08 |独立监控 | +|ZoneTcpClient |20.08.08 |分区监控 | +|StormRaffle |20.08.08 |节奏风暴 | +|GiftRaffle |20.08.08 |活动礼物 | +|PkRaffle |20.08.08 |大乱斗 | +|GuardRaffle |20.08.08 |舰长总督 | +|AnchorRaffle |20.08.08 |天选时刻 | +|AwardRecord |20.08.08 |获奖通知 | +|Statistics |20.08.08 |数据统计 | +|Competition |20.08.08 |赛事竞猜 | +|SmallHeart |20.08.08 |小心心 | +|ActivityLottery |20.08.08 |主站活动 | + ## 打赏赞助 ![](https://i.loli.net/2019/07/13/5d2963e5cc1eb22973.png) diff --git a/README.md b/README.md index 3290d61..9d3e3e5 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.6.0.200730 alpha** +> Currently for Personal Edition **0.6.5.200808 alpha** ```notice ---- 免费的东西总是得不到人的珍惜。 diff --git a/conf/user.conf.example b/conf/user.conf.example index 21ceb54..df262f3 100644 --- a/conf/user.conf.example +++ b/conf/user.conf.example @@ -67,6 +67,9 @@ USE_MANGA=false # 赛事助手 USE_MATCH=false +# 活动助手 +USE_ACTIVITY=false + # 破产机|每日竞猜次数|每次竞猜硬币(1-10)|下注(1.压大,2.压小,3.随机) USE_COMPETITION=false COMPET_MAX_NUM=20 diff --git a/src/core/App.php b/src/core/App.php index 67f66b1..381290d 100644 --- a/src/core/App.php +++ b/src/core/App.php @@ -70,6 +70,7 @@ class App 'Daily', 'ManGa', 'Match', + 'ActivityLottery', 'Competition', 'Heart', 'Task', diff --git a/src/core/Env.php b/src/core/Env.php index f620ef0..25d9561 100644 --- a/src/core/Env.php +++ b/src/core/Env.php @@ -13,7 +13,7 @@ namespace BiliHelper\Core; class Env { private $app_name = 'BiliHelper Personal'; - private $app_version = '0.6.0.*'; + private $app_version = '0.6.5.*'; /** * Env constructor. diff --git a/src/plugin/ActivityLottery.php b/src/plugin/ActivityLottery.php new file mode 100644 index 0000000..7baf1ae --- /dev/null +++ b/src/plugin/ActivityLottery.php @@ -0,0 +1,153 @@ + [ + 'sid' => 'dd83a687-c800-11ea-8597-246e966235d8', + 'action_types' => [3, 4], // 4 关注 3 分享 + 'referer' => 'https://www.bilibili.com/blackboard/2020SummerMusic.html', + 'expired_time' => 1599318000, // 2020-09-05 23:00:00 + 'draw_times' => 3, + ], + ]; + + public static function run() + { + if (self::getLock() > time() || getenv('USE_ACTIVITY') == 'false') { + return; + } + self::workTask(); + self::setLock(self::timing(5)); + } + + + /** + * @use 运行任务 + */ + private static function workTask() + { + foreach (self::$activity_infos as $title => $activity) { + // 过期 + if ($activity['expired_time'] < time()) { + Log::info('跳过'); + continue; + } + Log::info("启动 {$title} 抽奖任务"); + self::initTimes($activity['sid'], $activity['referer']); + foreach ($activity['action_types'] as $action_type) { + sleep(1); + self::addTimes($activity['sid'], $activity['referer'], $action_type); + } + foreach (range(1, $activity['draw_times']) as $num) { + sleep(5); + self::doLottery($activity['sid'], $activity['referer'], $num); + } + } + } + + + /** + * @use 获取抽奖机会 + * @param string $sid + * @param string $referer + * @return bool + */ + private static function initTimes(string $sid, string $referer): bool + { + $url = 'https://api.bilibili.com/x/activity/lottery/mytimes'; + $headers = [ + 'origin' => 'https://www.bilibili.com', + 'referer' => $referer + ]; + $payload = [ + 'sid' => $sid, + ]; + $raw = Curl::get('pc', $url, $payload, $headers); + $de_raw = json_decode($raw, true); + Log::info("获取抽奖机会 {$raw}"); + // {"code":0,"message":"0","ttl":1,"data":{"times":2}} + if ($de_raw['code'] == 0) { + return true; + } + return false; + } + + /** + * @use 增加抽奖机会 + * @param string $sid + * @param string $referer + * @param int $action_type + * @return bool + */ + private static function addTimes(string $sid, string $referer, int $action_type): bool + { + $url = 'https://api.bilibili.com/x/activity/lottery/addtimes'; + $headers = [ + 'origin' => 'https://www.bilibili.com', + 'referer' => $referer + ]; + $user_info = User::parseCookies(); + $payload = [ + 'sid' => $sid, + 'action_type' => $action_type, + 'csrf' => $user_info['token'] + ]; + $raw = Curl::post('pc', $url, $payload, $headers); + $de_raw = json_decode($raw, true); + Log::info("增加抽奖机会#{$action_type} {$raw}"); + // {"code":0,"message":"0","ttl":1} + if ($de_raw['code'] == 0) { + return true; + } + return false; + } + + /** + * @use 开始抽奖 + * @param string $sid + * @param string $referer + * @param int $num + * @return bool + */ + private static function doLottery(string $sid, string $referer, int $num): bool + { + $url = 'https://api.bilibili.com/x/activity/lottery/do'; + $headers = [ + 'origin' => 'https://www.bilibili.com', + 'referer' => $referer + ]; + $user_info = User::parseCookies(); + $payload = [ + 'sid' => $sid, + 'type' => 1, + 'csrf' => $user_info['token'] + ]; + $raw = Curl::post('pc', $url, $payload, $headers); + $de_raw = json_decode($raw, true); + Log::notice("开始抽奖#{$num} {$raw}"); + // {"code":0,"message":"0","ttl":1,"data":[{"id":0,"mid":4133274,"num":1,"gift_id":1152,"gift_name":"硬币x6","gift_type":0,"img_url":"https://i0.hdslb.com/bfs/activity-plat/static/b6e956937ee4aefd1e19c01283145fc0/JQ9Y9-KCm_w96_h102.png","type":5,"ctime":1596255796,"cid":0}]} + if ($de_raw['code'] == 0) { + return true; + } + return false; + } + + +} \ No newline at end of file diff --git a/src/plugin/AloneTcpClient.php b/src/plugin/AloneTcpClient.php index 6501f7b..6a9d1fa 100644 --- a/src/plugin/AloneTcpClient.php +++ b/src/plugin/AloneTcpClient.php @@ -25,6 +25,7 @@ class AloneTcpClient private static $server_addr = null; private static $server_key = null; private static $socket_timeout = 0; + private static $max_errors_num = 0; // 最大连续错误5次 /** * @use 入口 @@ -226,15 +227,19 @@ class AloneTcpClient case 'entered': // 握手确认 Log::info("确认到推送服务器 {$raw_data['type']}"); + self::$max_errors_num = 0; break; case 'error': // 产生错误 - Log::error("推送服务器异常 {$raw_data['data']['msg']}, 程序挂起请手动关闭!"); - // KEY到期推送提醒 - Notice::push('key_expired', ''); - // 程序挂起 防止systemd无限重启导致触发过多推送提醒 - sleep(86400); - exit(); + Log::error("推送服务器异常 {$raw_data['data']['msg']}, 程序错误5次后将挂起, 请手动关闭!"); + if (self::$max_errors_num == 5) { + // KEY到期推送提醒 + Notice::push('key_expired', ''); + // 程序挂起 防止systemd无限重启导致触发过多推送提醒 + sleep(86400); + exit(); + } + self::$max_errors_num += 1; break; case 'heartbeat': // 服务端心跳推送 diff --git a/src/plugin/SmallHeart.php b/src/plugin/SmallHeart.php index ed47c3e..b88dcdf 100644 --- a/src/plugin/SmallHeart.php +++ b/src/plugin/SmallHeart.php @@ -138,6 +138,7 @@ class SmallHeart $x_data = self::xHeartBeat(self::$hb_count); if (!$x_data['status']) { // 错误级别 + self::resetVar(); return; } self::$hb_count += 1; diff --git a/src/plugin/Task.php b/src/plugin/Task.php index d4b4f83..1a88d12 100644 --- a/src/plugin/Task.php +++ b/src/plugin/Task.php @@ -25,9 +25,9 @@ class Task } $data = self::check(); - if (isset($data['data']['double_watch_info'])) { - self::double_watch_info($data['data']['double_watch_info']); - } + // if (isset($data['data']['double_watch_info'])) { + // self::double_watch_info($data['data']['double_watch_info']); + // } if (isset($data['data']['sign_info'])) { self::sign_info($data['data']['sign_info']); }