diff --git a/plugin/LiveGoldBox/LiveGoldBox.php b/plugin/LiveGoldBox/LiveGoldBox.php index 6a1d322..4e7fa37 100644 --- a/plugin/LiveGoldBox/LiveGoldBox.php +++ b/plugin/LiveGoldBox/LiveGoldBox.php @@ -22,6 +22,7 @@ use Bhp\Log\Log; use Bhp\Plugin\BasePlugin; use Bhp\Plugin\Plugin; use Bhp\TimeLock\TimeLock; +use Bhp\Util\Exceptions\NoLoginException; class LiveGoldBox extends BasePlugin { @@ -70,6 +71,7 @@ class LiveGoldBox extends BasePlugin /** * 执行 * @return void + * @throws NoLoginException */ public function execute(): void { @@ -127,7 +129,7 @@ class LiveGoldBox extends BasePlugin /** * 抽奖 * @param array $lottery_list - * @return bool + * @return void */ protected function drawLottery(array $lottery_list): void { @@ -145,6 +147,7 @@ class LiveGoldBox extends BasePlugin /** * 获取抽奖 * @return array + * @throws NoLoginException */ protected function fetchLotteryList(): array { @@ -203,6 +206,7 @@ class LiveGoldBox extends BasePlugin * 抽奖盒子信息 * @param int $aid * @return array + * @throws NoLoginException */ protected function boxInfos(int $aid): array { @@ -210,16 +214,20 @@ class LiveGoldBox extends BasePlugin // {"code":0,"data":{"title":"荣耀宝箱抽奖","rule":"a 抽奖时间按如下规则抽取一次,重复无效。\nb 获奖者需要再获奖名单公布后一周内反馈姓名、邮寄地址、联系方式,因获奖者逾期查看获奖名单、逾期提交个人资料或个人资料有误,将视为自动放弃获奖资格及由此产生的权利。","current_round":2,"typeB":[{"startTime":"2020-05-18 18:30:00","imgUrl":"https://i0.hdslb.com/bfs/live/f600b89f2c2550b600612feba90e39901a9f027c.jpg","join_start_time":1589796000,"join_end_time":1589797800,"status":4,"list":[{"jp_name":"荣耀路由3","jp_num":"1","jp_id":3181,"jp_type":2,"ex_text":"","jp_pic":"https://i0.hdslb.com/bfs/live/f600b89f2c2550b600612feba90e39901a9f027c.jpg"}],"round_num":1},{"startTime":"2020-05-18 19:00:00","imgUrl":"https://i0.hdslb.com/bfs/live/f600b89f2c2550b600612feba90e39901a9f027c.jpg","join_start_time":1589797800,"join_end_time":1589799600,"status":0,"list":[{"jp_name":"荣耀路由3","jp_num":"1","jp_id":3182,"jp_type":2,"ex_text":"","jp_pic":"https://i0.hdslb.com/bfs/live/f600b89f2c2550b600612feba90e39901a9f027c.jpg"}],"round_num":2},{"startTime":"2020-05-18 19:30:00","imgUrl":"https://i0.hdslb.com/bfs/live/9fcde6f26a546b9dfb5ffc7a0c4f4503a05e16f2.jpg","join_start_time":1589799600,"join_end_time":1589801400,"status":-1,"list":[{"jp_name":"荣耀平板V6","jp_num":"1","jp_id":3183,"jp_type":2,"ex_text":"","jp_pic":"https://i0.hdslb.com/bfs/live/9fcde6f26a546b9dfb5ffc7a0c4f4503a05e16f2.jpg"}],"round_num":3},{"startTime":"2020-05-18 20:00:00","imgUrl":"https://i0.hdslb.com/bfs/live/9fcde6f26a546b9dfb5ffc7a0c4f4503a05e16f2.jpg","join_start_time":1589801400,"join_end_time":1589803200,"status":-1,"list":[{"jp_name":"荣耀平板V6","jp_num":"1","jp_id":3184,"jp_type":2,"ex_text":"","jp_pic":"https://i0.hdslb.com/bfs/live/9fcde6f26a546b9dfb5ffc7a0c4f4503a05e16f2.jpg"}],"round_num":4},{"startTime":"2020-05-18 20:30:00","imgUrl":"https://i0.hdslb.com/bfs/live/9fcde6f26a546b9dfb5ffc7a0c4f4503a05e16f2.jpg","join_start_time":1589803200,"join_end_time":1589805000,"status":-1,"list":[{"jp_name":"荣耀平板V6","jp_num":"1","jp_id":3185,"jp_type":2,"ex_text":"","jp_pic":"https://i0.hdslb.com/bfs/live/9fcde6f26a546b9dfb5ffc7a0c4f4503a05e16f2.jpg"}],"round_num":5},{"startTime":"2020-05-18 21:00:00","imgUrl":"https://i0.hdslb.com/bfs/live/73db69bd5a9e5dedb7d2f32d72fd6248b860e238.jpg","join_start_time":1589805000,"join_end_time":1589806800,"status":-1,"list":[{"jp_name":"荣耀MagicBook Pro","jp_num":"1","jp_id":3186,"jp_type":2,"ex_text":"","jp_pic":"https://i0.hdslb.com/bfs/live/73db69bd5a9e5dedb7d2f32d72fd6248b860e238.jpg"}],"round_num":6},{"startTime":"2020-05-18 22:00:00","imgUrl":"https://i0.hdslb.com/bfs/live/4dba1e8b58c174d5e2311de339b1e02a3ac77a98.jpg","join_start_time":1589806800,"join_end_time":1589810400,"status":-1,"list":[{"jp_name":"荣耀智慧屏新品,荣耀MagicBook Pro,荣耀平板V6,荣耀路由3","jp_num":"1","jp_id":3187,"jp_type":2,"ex_text":"","jp_pic":"https://i0.hdslb.com/bfs/live/4dba1e8b58c174d5e2311de339b1e02a3ac77a98.jpg"}],"round_num":7}],"activity_pic":"https://i0.hdslb.com/bfs/live/c3ed87683f6e87d256d1f5fdddbfb220fc4c2cdf.png","activity_id":556,"weight":20,"background":"https://i0.hdslb.com/bfs/live/84cd59bcb1e977359df618dbeb0f7828751f457c.png","title_color":"#FFFFFF","closeable":0,"jump_url":"https://live.bilibili.com/p/html/live-app-treasurebox/index.html?is_live_half_webview=1\u0026hybrid_biz=live-app-treasurebox\u0026hybrid_rotate_d=1\u0026hybrid_half_ui=1,3,100p,70p,0,0,30,100;2,2,375,100p,0,0,30,100;3,3,100p,70p,0,0,30,100;4,2,375,100p,0,0,30,100;5,3,100p,70p,0,0,30,100;6,3,100p,70p,0,0,30,100;7,3,100p,70p,0,0,30,100\u0026aid=556"},"message":"","msg":""} $response = ApiBox::getStatus($aid); // - if ($response['code']) { - Log::warning("金色宝箱: 获取宝箱{$aid}状态失败 {$response['code']} -> {$response['message']}"); - return []; + switch ($response['code']) { + case -500: + throw new NoLoginException($response['message']); + case 0: + // + if (is_null($response['data'])) { + return []; + } + // + return $response['data']; + default: + Log::warning("金色宝箱: 获取宝箱{$aid}状态失败 {$response['code']} -> {$response['message']}"); + return []; } - // - if (is_null($response['data'])) { - return []; - } - // - return $response['data']; } /** @@ -227,6 +235,7 @@ class LiveGoldBox extends BasePlugin * @param int $min * @param int $max * @return void + * @throws NoLoginException */ protected function calcAidRange(int $min, int $max): void { @@ -257,4 +266,3 @@ class LiveGoldBox extends BasePlugin } } - \ No newline at end of file diff --git a/plugin/LiveSignIn/LiveSignIn.php b/plugin/LiveSignIn/LiveSignIn.php index 4ad1aff..97ae30a 100644 --- a/plugin/LiveSignIn/LiveSignIn.php +++ b/plugin/LiveSignIn/LiveSignIn.php @@ -20,6 +20,7 @@ use Bhp\Log\Log; use Bhp\Plugin\BasePlugin; use Bhp\Plugin\Plugin; use Bhp\TimeLock\TimeLock; +use Bhp\Util\Exceptions\NoLoginException; class LiveSignIn extends BasePlugin { @@ -51,6 +52,7 @@ class LiveSignIn extends BasePlugin /** * 执行 * @return void + * @throws NoLoginException */ public function execute(): void { @@ -65,21 +67,28 @@ class LiveSignIn extends BasePlugin /** * @return bool + * @throws NoLoginException */ 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; + switch ($response['code']) { + case -101: + throw new NoLoginException($response['message']); + case 0: + // + if ($response['data']['status'] == 1) { + Log::notice("直播签到: 今日已经签到过了哦~ 已连续签到 {$response['data']['hadSignDays']} 天"); + return true; + } + break; + default: + Log::warning("直播签到: 获取签到信息失败 {$response['code']} -> {$response['message']}"); + return false; } + // 您被封禁了,无法进行操作 // {"code":1011040,"message":"今日已签到过,无法重复签到","ttl":1,"data":null} // {"code":0,"message":"0","ttl":1,"data":{"text":"3000点用户经验,2根辣条","specialText":"再签到3天可以获得666银瓜子","allDays":31,"hadSignDays":2,"isBonusDay":0}} @@ -95,4 +104,3 @@ class LiveSignIn extends BasePlugin } } - \ No newline at end of file diff --git a/plugin/Login/Login.php b/plugin/Login/Login.php index 81049f7..ea7324e 100644 --- a/plugin/Login/Login.php +++ b/plugin/Login/Login.php @@ -546,7 +546,14 @@ class Login extends BasePlugin { // {"code":0,"message":"0","ttl":1,"data":{"is_new":false,"captcha_key":"4e292933816755442c1568e2043b8e41","recaptcha_url":""}} // {"code":0,"message":"0","ttl":1,"data":{"is_new":false,"captcha_key":"","recaptcha_url":"https://www.bilibili.com/h5/project-msg-auth/verify?ct=geetest\u0026recaptcha_token=ad520c3a4a3c46e29b1974d85efd2c4b\u0026gee_gt=1c0ea7c7d47d8126dda19ee3431a5f38\u0026gee_challenge=c772673050dce482b9f63ff45b681ceb\u0026hash=ea2850a43cc6b4f1f7b925d601098e5e"}} - $raw = ApiLogin::sendSms($phone, $cid); + // TODO 参数位置调整 + $payload = [ + 'cid' => $cid, + 'tel' => $phone, + 'statistics' => '{"appId":1,"platform":3,"version":"6.86.0","abtest":""}', + ]; + + $raw = ApiLogin::sendSms($payload); $response = json_decode($raw, true); // if ($response['code'] == 0 && isset($response['data']['captcha_key']) && $response['data']['recaptcha_url'] == '') { @@ -623,4 +630,4 @@ class Login extends BasePlugin return implode("", array_reverse($cookies)); } -} \ No newline at end of file +} diff --git a/plugin/LoveClub/LoveClub.php b/plugin/LoveClub/LoveClub.php index 2b4a89f..f90de84 100644 --- a/plugin/LoveClub/LoveClub.php +++ b/plugin/LoveClub/LoveClub.php @@ -20,6 +20,7 @@ use Bhp\Log\Log; use Bhp\Plugin\BasePlugin; use Bhp\Plugin\Plugin; use Bhp\TimeLock\TimeLock; +use Bhp\Util\Exceptions\NoLoginException; class LoveClub extends BasePlugin { @@ -51,6 +52,7 @@ class LoveClub extends BasePlugin /** * 执行 * @return void + * @throws NoLoginException */ public function execute(): void { @@ -68,27 +70,33 @@ class LoveClub extends BasePlugin /** * 获取友爱社列表 * @return array + * @throws NoLoginException */ protected function getGroupList(): array { $response = ApiLoveClub::myGroups(); // - if ($response['code']) { - Log::warning("友爱社: 获取应援团失败 {$response['code']} -> {$response['message']}"); - return []; + + switch ($response['code']) { + case -101: + throw new NoLoginException($response['message']); + case 0: + // + if (empty($response['data']['list'])) { + Log::notice('友爱社: 没有需要签到的应援团哦~'); + return []; + } + // + return $response['data']['list']; + default: + Log::warning("友爱社: 获取应援团失败 {$response['code']} -> {$response['message']}"); + return []; } - // - if (empty($response['data']['list'])) { - Log::notice('友爱社: 没有需要签到的应援团哦~'); - return []; - } - // - return $response['data']['list']; } /** * 签到 - * @param array $groupInfo + * @param array $group * @return bool */ protected function signInGroup(array $group): bool @@ -114,4 +122,3 @@ class LoveClub extends BasePlugin } } - \ No newline at end of file diff --git a/plugin/MainSite/MainSite.php b/plugin/MainSite/MainSite.php index cf1952b..4824036 100644 --- a/plugin/MainSite/MainSite.php +++ b/plugin/MainSite/MainSite.php @@ -24,6 +24,7 @@ use Bhp\Log\Log; use Bhp\Plugin\BasePlugin; use Bhp\Plugin\Plugin; use Bhp\TimeLock\TimeLock; +use Bhp\Util\Exceptions\NoLoginException; class MainSite extends BasePlugin { @@ -55,6 +56,7 @@ class MainSite extends BasePlugin /** * 执行 * @return void + * @throws NoLoginException */ public function execute(): void { @@ -266,6 +268,7 @@ class MainSite extends BasePlugin /** * 分享任务 * @return bool + * @throws NoLoginException */ protected function shareTask(): bool { @@ -276,12 +279,16 @@ class MainSite extends BasePlugin $aid = (string)$info['aid']; // $response = ApiShare::share($aid); - if ($response['code']) { - Log::warning("主站任务: $aid 分享失败 {$response['code']} -> {$response['message']}"); - return false; + switch ($response['code']) { + case 137004: + throw new NoLoginException($response['message']); + case 0: + Log::notice("主站任务: $aid 分享成功"); + return true; + default: + Log::warning("主站任务: $aid 分享失败 {$response['code']} -> {$response['message']}"); + return false; } - Log::notice("主站任务: $aid 分享成功"); - return true; } /** @@ -343,4 +350,3 @@ class MainSite extends BasePlugin } } - \ No newline at end of file diff --git a/plugin/Manga/Manga.php b/plugin/Manga/Manga.php index 5d7243e..931147e 100644 --- a/plugin/Manga/Manga.php +++ b/plugin/Manga/Manga.php @@ -20,6 +20,7 @@ use Bhp\Log\Log; use Bhp\Plugin\BasePlugin; use Bhp\Plugin\Plugin; use Bhp\TimeLock\TimeLock; +use Bhp\Util\Exceptions\NoLoginException; class Manga extends BasePlugin { @@ -51,6 +52,7 @@ class Manga extends BasePlugin /** * 执行 * @return void + * @throws NoLoginException */ public function execute(): void { @@ -91,6 +93,7 @@ class Manga extends BasePlugin /** * 分享任务 * @return bool + * @throws NoLoginException */ protected function shareTask(): bool { @@ -106,18 +109,13 @@ class Manga extends BasePlugin Log::notice("漫画: 分享成功,经验值+{$response['data']['point']}"); } break; + case 'unauthenticated': + throw new NoLoginException($response['message']); default: Log::warning("漫画: 分享失败 {$response['code']} -> {$response['msg']}"); return false; } return true; - - - if ($response['code']) { - Log::warning("漫画: 分享失败或者重复分享 {$response['code']} -> {$response['msg']}"); - } else { - } - return true; } /** @@ -136,4 +134,3 @@ class Manga extends BasePlugin } - \ No newline at end of file diff --git a/plugin/Silver2Coin/Silver2Coin.php b/plugin/Silver2Coin/Silver2Coin.php index 8cededf..342b216 100644 --- a/plugin/Silver2Coin/Silver2Coin.php +++ b/plugin/Silver2Coin/Silver2Coin.php @@ -20,6 +20,7 @@ use Bhp\Log\Log; use Bhp\Plugin\BasePlugin; use Bhp\Plugin\Plugin; use Bhp\TimeLock\TimeLock; +use Bhp\Util\Exceptions\NoLoginException; class Silver2Coin extends BasePlugin { @@ -51,6 +52,7 @@ class Silver2Coin extends BasePlugin /** * 执行 * @return void + * @throws NoLoginException */ public function execute(): void { @@ -78,26 +80,31 @@ class Silver2Coin extends BasePlugin /** * @return bool + * @throws NoLoginException */ protected function before(): bool { $response = ApiRevenueWallet::getStatus(); // - if ($response['code']) { - Log::warning("银瓜子兑换硬币: 获取钱包状态失败 {$response['code']} -> {$response['message']}"); - return true; + switch ($response['code']) { + case -101: + throw new NoLoginException($response['message']); + case 0: + // + if ($response['data']['silver_2_coin_left'] == 0) { + Log::notice("银瓜子兑换硬币: 今日已兑换过一次了哦~"); + return false; + } + // + if ($response['data']['silver'] < 700) { + Log::notice("银瓜子兑换硬币: 瓜子余额不足以兑换哦~~"); + return false; + } + return true; + default: + Log::warning("银瓜子兑换硬币: 获取钱包状态失败 {$response['code']} -> {$response['message']}"); + return false; } - // - if ($response['data']['silver_2_coin_left'] == 0) { - Log::notice("银瓜子兑换硬币: 今日已兑换过一次了哦~"); - return false; - } - // - if ($response['data']['silver'] < 700) { - Log::notice("银瓜子兑换硬币: 瓜子余额不足以兑换哦~~"); - return false; - } - return true; } /** @@ -142,4 +149,3 @@ class Silver2Coin extends BasePlugin } } - \ No newline at end of file diff --git a/src/Api/LinkGroup/ApiLoveClub.php b/src/Api/LinkGroup/ApiLoveClub.php index 85dde2c..6732fc1 100644 --- a/src/Api/LinkGroup/ApiLoveClub.php +++ b/src/Api/LinkGroup/ApiLoveClub.php @@ -34,11 +34,11 @@ class ApiLoveClub } /** - * @param string $group_id 应援团id - * @param string $owner_id 爱豆ID + * @param int $group_id 应援团id + * @param int $owner_id 爱豆ID * @return array */ - public static function signIn(string $group_id, string $owner_id): array + public static function signIn(int $group_id, int $owner_id): array { $url = 'https://api.vc.bilibili.com/link_setting/v1/link_setting/sign_in'; $payload = [ @@ -48,5 +48,4 @@ class ApiLoveClub return Request::getJson(true, 'app', $url, Sign::common($payload)); } - -} \ No newline at end of file +} diff --git a/src/Api/Passport/ApiLogin.php b/src/Api/Passport/ApiLogin.php index 6be6ac4..29d17b7 100644 --- a/src/Api/Passport/ApiLogin.php +++ b/src/Api/Passport/ApiLogin.php @@ -50,19 +50,18 @@ class ApiLogin /** * 发送短信验证码 - * @param string $phone - * @param string $cid + * @param array $payload * @return string */ - public static function sendSms(string $phone, string $cid): string + public static function sendSms(array $payload): string { $url = 'https://passport.bilibili.com//x/passport-login/sms/send'; // TODO 动态版本参数 - $payload = [ - 'cid' => $cid, - 'tel' => $phone, - 'statistics' => '{"appId":1,"platform":3,"version":"6.86.0","abtest":""}', - ]; +// $payload = [ +// 'cid' => $cid, +// 'tel' => $phone, +// 'statistics' => '{"appId":1,"platform":3,"version":"6.86.0","abtest":""}', +// ]; // {"code":0,"message":"0","ttl":1,"data":{"is_new":false,"captcha_key":"4e292933816755442c1568e2043b8e41","recaptcha_url":""}} // {"code":0,"message":"0","ttl":1,"data":{"is_new":false,"captcha_key":"","recaptcha_url":"https://www.bilibili.com/h5/project-msg-auth/verify?ct=geetest\u0026recaptcha_token=ad520c3a4a3c46e29b1974d85efd2c4b\u0026gee_gt=1c0ea7c7d47d8126dda19ee3431a5f38\u0026gee_challenge=c772673050dce482b9f63ff45b681ceb\u0026hash=ea2850a43cc6b4f1f7b925d601098e5e"}} return Request::post('app', $url, Sign::login($payload)); diff --git a/src/Task/Task.php b/src/Task/Task.php index f5b7031..8da2657 100644 --- a/src/Task/Task.php +++ b/src/Task/Task.php @@ -20,8 +20,10 @@ namespace Bhp\Task; use Amp\Loop; use Bhp\Log\Log; use Bhp\Plugin\Plugin; +use Bhp\Schedule\Schedule; use Bhp\TimeLock\TimeLock; use Bhp\Util\DesignPattern\SingleTon; +use Bhp\Util\Exceptions\NoLoginException; use Throwable; use function Amp\asyncCall; @@ -46,6 +48,11 @@ class Task extends SingleTon while (true) { try { Plugin::getInstance()->trigger($hook, ...$data); + } catch (NoLoginException $e) { + Schedule::restore(); + $error_msg = "MSG: {$e->getMessage()} CODE: {$e->getCode()} FILE: {$e->getFile()} LINE: {$e->getLine()}"; + Log::error($error_msg); + failExit('触发未登录错误,请重新登录哦~'); } catch (Throwable $e) { // TODO 多次错误删除tasks_***.json文件 $error_msg = "MSG: {$e->getMessage()} CODE: {$e->getCode()} FILE: {$e->getFile()} LINE: {$e->getLine()}"; @@ -65,5 +72,4 @@ class Task extends SingleTon Loop::run(); } } - - \ No newline at end of file + diff --git a/src/Util/Exceptions/NoLoginException.php b/src/Util/Exceptions/NoLoginException.php new file mode 100644 index 0000000..63b3dcc --- /dev/null +++ b/src/Util/Exceptions/NoLoginException.php @@ -0,0 +1,34 @@ +