diff --git a/plugin/LiveSignIn/LiveSignIn.php b/plugin/LiveSignIn/LiveSignIn.php new file mode 100644 index 0000000..d147c63 --- /dev/null +++ b/plugin/LiveSignIn/LiveSignIn.php @@ -0,0 +1,95 @@ + __CLASS__, // hook + 'name' => 'LiveSignIn', // 插件名称 + 'version' => '0.0.1', // 插件版本 + 'desc' => '直播签到', // 插件描述 + 'author' => 'Lkeme',// 作者 + 'priority' => 1103, // 插件优先级 + 'cycle' => '24(小时)', // 运行周期 + ]; + + /** + * @param Plugin $plugin + */ + public function __construct(Plugin &$plugin) + { + // + TimeLock::initTimeLock(); + // $this::class + $plugin->register($this, 'execute'); + } + + /** + * @use 执行 + * @return void + */ + public function execute(): void + { + if (TimeLock::getTimes() > time() || !getEnable('live_sign_in')) return; + // + if ($this->signInTask()) { + TimeLock::setTimes(24 * 60 * 60); + } else { + TimeLock::setTimes(mt_rand(6, 8) * 60 * 60); + } + } + + /** + * @return bool + */ + protected function signInTask(): bool + { + // {"code":0,"message":"0","ttl":1,"data":{"text":"","specialText":"","status":0,"allDays":30,"curMonth":6,"curYear":2022,"curDay":4,"curDate":"2022-6-4","hadSignDays":0,"newTask":0,"signDaysList":[],"signBonusDaysList":[]}} + $response = ApiXLiveSign::webGetSignInfo(); + // + if ($response['code']) { + Log::warning("直播签到: 获取签到信息失败 {$response['code']} -> {$response['message']}"); + return false; + } + // + if ($response['data']['status'] == 1) { + Log::notice("直播签到: 今日已经签到过了哦~ 已连续签到 {$response['data']['hadSignDays']} 天"); + return true; + } + // + $response = ApiXLiveSign::doSign(); + if ($response['code']) { + Log::warning("直播签到: 签到失败 {$response['code']} -> {$response['message']}"); + return false; + } + // + Log::notice("直播签到: 签到成功~ 连续签到 {$response['data']['hadSignDays']} 天 {$response['data']['specialText']}"); + return true; + } + +} + \ No newline at end of file diff --git a/profile/example/config/user.ini b/profile/example/config/user.ini index c6a1399..6b5c993 100644 --- a/profile/example/config/user.ini +++ b/profile/example/config/user.ini @@ -45,6 +45,10 @@ enable = true [love_club] enable = true +; 直播签到 +[live_sign_in] +enable =true + ####################### # 通知设置 # ####################### diff --git a/src/Api/XLive/ApiXLiveSign.php b/src/Api/XLive/ApiXLiveSign.php new file mode 100644 index 0000000..7ba6687 --- /dev/null +++ b/src/Api/XLive/ApiXLiveSign.php @@ -0,0 +1,56 @@ + 'https://link.bilibili.com', + 'referer' => 'https://link.bilibili.com/p/center/index' + ]; + // {"code":0,"message":"0","ttl":1,"data":{"text":"","specialText":"","status":0,"allDays":30,"curMonth":6,"curYear":2022,"curDay":4,"curDate":"2022-6-4","hadSignDays":0,"newTask":0,"signDaysList":[],"signBonusDaysList":[]}} + return Request::getJson(true, 'pc', $url, $payload, $headers); + } + + /** + * @use 签到 + * @return array + */ + public static function doSign(): array + { + $url = 'https://api.live.bilibili.com/sign/doSign'; + $url = 'https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign'; + $payload = []; + $headers = [ + 'origin' => 'https://link.bilibili.com', + 'referer' => 'https://link.bilibili.com/p/center/index' + ]; + // {"code":0,"message":"0","ttl":1,"data":{"text":"3000点用户经验,2根辣条","specialText":"再签到4天可以获得666银瓜子","allDays":30,"hadSignDays":1,"isBonusDay":0}} + return Request::getJson(true, 'pc', $url, $payload, $headers); + } +} \ No newline at end of file