diff --git a/composer.json b/composer.json index 1ad3703..0f2ca84 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ "guzzlehttp/guzzle": "^6.5.5", "mathieuviossat/arraytotexttable": "^1.0.8", "klkvsk/json-decode-stream": "^1.0", - "sven/file-config": "^3.1" + "sven/file-config": "^3.1", + "hassankhan/config": "^2.2" }, "license": "MIT", "authors": [ diff --git a/composer.lock b/composer.lock index 6f574d2..4db83f8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a9407272d4bb9ca1632a2aa728429bf0", + "content-hash": "7b0e5cfde9ebb70a16c941f59fd2a71d", "packages": [ { "name": "amphp/amp", @@ -460,16 +460,16 @@ }, { "name": "guzzlehttp/psr7", - "version": "1.8.1", + "version": "1.8.2", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "35ea11d335fd638b5882ff1725228b3d35496ab1" + "reference": "dc960a912984efb74d0a90222870c72c87f10c91" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/35ea11d335fd638b5882ff1725228b3d35496ab1", - "reference": "35ea11d335fd638b5882ff1725228b3d35496ab1", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/dc960a912984efb74d0a90222870c72c87f10c91", + "reference": "dc960a912984efb74d0a90222870c72c87f10c91", "shasum": "", "mirrors": [ { @@ -535,9 +535,77 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/1.8.1" + "source": "https://github.com/guzzle/psr7/tree/1.8.2" }, - "time": "2021-03-21T16:25:00+00:00" + "time": "2021-04-26T09:17:50+00:00" + }, + { + "name": "hassankhan/config", + "version": "2.2.0", + "source": { + "type": "git", + "url": "https://github.com/hassankhan/config.git", + "reference": "62b0fd17540136efa94ab6b39f04044c6dc5e4a7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hassankhan/config/zipball/62b0fd17540136efa94ab6b39f04044c6dc5e4a7", + "reference": "62b0fd17540136efa94ab6b39f04044c6dc5e4a7", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.5.9" + }, + "require-dev": { + "phpunit/phpunit": "~4.8.36 || ~5.7 || ~6.5 || ~7.5", + "scrutinizer/ocular": "~1.1", + "squizlabs/php_codesniffer": "~2.2", + "symfony/yaml": "~3.4" + }, + "suggest": { + "symfony/yaml": "~3.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "Noodlehaus\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Hassan Khan", + "homepage": "http://hassankhan.me/", + "role": "Developer" + } + ], + "description": "Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files", + "homepage": "http://hassankhan.me/config/", + "keywords": [ + "config", + "configuration", + "ini", + "json", + "microphp", + "unframework", + "xml", + "yaml", + "yml" + ], + "support": { + "issues": "https://github.com/hassankhan/config/issues", + "source": "https://github.com/hassankhan/config/tree/2.2.0" + }, + "time": "2020-12-07T16:04:15+00:00" }, { "name": "klkvsk/json-decode-stream", @@ -1229,16 +1297,16 @@ }, { "name": "psr/log", - "version": "1.1.3", + "version": "1.1.4", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc" + "reference": "d49695b909c3b7628b6289db5479a1c204601f11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc", - "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc", + "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11", "shasum": "", "mirrors": [ { @@ -1268,7 +1336,7 @@ "authors": [ { "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "homepage": "https://www.php-fig.org/" } ], "description": "Common interface for logging libraries", @@ -1279,9 +1347,9 @@ "psr-3" ], "support": { - "source": "https://github.com/php-fig/log/tree/1.1.3" + "source": "https://github.com/php-fig/log/tree/1.1.4" }, - "time": "2020-03-23T09:12:05+00:00" + "time": "2021-05-03T11:20:27+00:00" }, { "name": "ralouphie/getallheaders", diff --git a/data/activity_infos.json b/data/activity_infos.json index 90c1d60..61dcc47 100644 --- a/data/activity_infos.json +++ b/data/activity_infos.json @@ -87,6 +87,39 @@ "share": "true", "draw_times": 1, "expire_at": "2021-04-25 23:59:59" + }, + { + "url": "https://www.bilibili.com/blackboard/activity-Tpo81ydpiW.html", + "title": "和平精英周年庆嘉年华1次", + "description": "活动期间每天分享页面,新增一次机会。", + "sid": "e2d93baa-96b9-11eb-8597-246e966235d8", + "login": "true", + "follow": "false", + "share": "true", + "draw_times": 1, + "expire_at": "2021-06-15 23:59:59" + }, + { + "url": "https://www.bilibili.com/blackboard/activity-Tpo81ydpiW.html", + "title": "和平精英周年庆嘉年华2次", + "description": "活动期间每天分享页面,新增一次机会。", + "sid": "e2d93baa-96b9-11eb-8597-246e966235d8", + "login": "true", + "follow": "false", + "share": "true", + "draw_times": 1, + "expire_at": "2021-06-15 23:59:59" + }, + { + "url": "https://www.bilibili.com/blackboard/activity-Tpo81ydpiW.html", + "title": "和平精英周年庆嘉年华3次", + "description": "活动期间每天分享页面,新增一次机会。", + "sid": "e2d93baa-96b9-11eb-8597-246e966235d8", + "login": "true", + "follow": "false", + "share": "true", + "draw_times": 1, + "expire_at": "2021-06-15 23:59:59" } ] } \ No newline at end of file diff --git a/data/latest.json b/data/latest.json new file mode 100644 index 0000000..1f9e8b1 --- /dev/null +++ b/data/latest.json @@ -0,0 +1,10 @@ +{ + "code": 0, + "project":"BiliHelper-personal", + "branch": "master", + "source": "https://github.com/lkeme/BiliHelper-personal", + "raw_url": "https://cdn.jsdelivr.net/gh/lkeme/BiliHelper-personal@master/data/latest.json", + "version": "0.8.1.210423", + "des": "程序有更新哦,请及时线上查看。", + "time": '2021年5月6日15:42:40' +} \ No newline at end of file diff --git a/src/core/App.php b/src/core/App.php index fccc7d2..fd17205 100644 --- a/src/core/App.php +++ b/src/core/App.php @@ -66,6 +66,7 @@ class App public function start() { $plugins = [ + 'CheckUpdate', 'Login', 'Schedule', 'MainSite', diff --git a/src/plugin/CheckUpdate.php b/src/plugin/CheckUpdate.php new file mode 100644 index 0000000..86afdb9 --- /dev/null +++ b/src/plugin/CheckUpdate.php @@ -0,0 +1,91 @@ + time()) { + return; + } + self::check(); + self::setLock(8 * 60 * 60); + } + + /** + * @use 检查 + */ + private static function check() + { + Log::info('开始检查项目更新'); + self::loadJsonData(); + Log::info('拉取线上最新配置'); + self::fetchLatest(); + if (!self::compareVersion()) { + Log::info('项目已是最新版本'); + } else { + Log::notice('项目有更新'); + // TODO 完善提示信息 + $time = self::$latest_conf->get('time'); + $version = self::$latest_conf->get('version'); + $des = self::$latest_conf->get('des'); + $info = "最新版本-{$version}, {$des}"; + Notice::push('update', $info); + } + } + + /** + * @use 拉取最新 + */ + private static function fetchLatest() + { + $url = self::$conf->get('raw_url'); + $payload = []; + $raw = Curl::get('other', $url, $payload); + self::$latest_conf = new Config($raw, new Json, true); + } + + /** + * @use 加载本地JSON DATA + */ + private static function loadJsonData() + { + self::$conf = new Config(self::$repository); + } + + /** + * @use 比较版本号 + * @return bool + */ + private static function compareVersion(): bool + { + $current_version = self::$conf->get('version'); + $latest_version = self::$latest_conf->get('version'); + // true 有更新 false 无更新 + return !($current_version == $latest_version); + } + +} \ No newline at end of file diff --git a/src/plugin/Login.php b/src/plugin/Login.php index 0fd04ab..18eff7f 100644 --- a/src/plugin/Login.php +++ b/src/plugin/Login.php @@ -48,7 +48,6 @@ class Login self::setLock(3600); } - /** * @use 登录控制中心 */ @@ -92,12 +91,11 @@ class Login self::$password = self::publicKeyEnc($pass); } - /** * @use 保持认证 * @return bool */ - private static function keepAuth() + private static function keepAuth(): bool { if (self::getLock() > time()) { return true; @@ -119,7 +117,7 @@ class Login * @use 获取令牌信息 * @return bool */ - private static function checkToken() + private static function checkToken(): bool { $url = 'https://passport.bilibili.com/api/v2/oauth2/info'; $payload = [ @@ -135,11 +133,10 @@ class Login return $data['data']['expires_in'] > 14400; } - /** * @use 刷新Token */ - private static function refreshToken() + private static function refreshToken(): bool { $url = 'https://passport.bilibili.com/api/v2/oauth2/refresh_token'; $payload = [ @@ -163,35 +160,6 @@ class Login return true; } - /** - * @use 检查Cookie - */ - private static function checkCookie() - { - - } - - - /** - * @use 刷新Cookie - */ - private static function refreshCookie() - { - $url = 'https://passport.bilibili.com/api/login/sso'; - $payload = [ - 'gourl' => 'https%3A%2F%2Faccount.bilibili.com%2Faccount%2Fhome' - ]; - $response = Curl::headers('app', $url, Sign::common($payload)); - $headers = $response['Set-Cookie']; - $cookies = []; - foreach ($headers as $header) { - preg_match_all('/^(.*);/iU', $header, $cookie); - array_push($cookies, $cookie[0][0]); - } - return implode("", array_reverse($cookies)); - } - - /** * @use 公钥加密 * @param $plaintext @@ -218,7 +186,6 @@ class Login return base64_encode($crypt); } - /** * @use 获取验证码 * @return array|string[] @@ -273,7 +240,6 @@ class Login ]; } - /** * @use 验证码登录 * @param string $mode @@ -293,8 +259,8 @@ class Login */ private static function accountLogin(string $validate = '', string $challenge = '', string $mode = '账密模式') { - Log::info("尝试{$mode}登录"); -// $url = 'https://passport.bilibili.com/api/v3/oauth2/login'; + Log::info("尝试 {$mode} 登录"); + // $url = 'https://passport.bilibili.com/api/v3/oauth2/login'; $url = 'https://passport.bilibili.com/x/passport-login/oauth2/login'; $payload = [ 'seccode' => $validate ? "{$validate}|jordan" : '', @@ -314,50 +280,7 @@ class Login // {"ts":1593082432,"code":0,"data":{"status":0,"token_info":{"mid":123456,"access_token":"123123","refresh_token":"123123","expires_in":2592000},"cookie_info":{"cookies":[{"name":"bili_jct","value":"123123","http_only":0,"expires":1595674432},{"name":"DedeUserID","value":"123456","http_only":0,"expires":1595674432},{"name":"DedeUserID__ckMd5","value":"123123","http_only":0,"expires":1595674432},{"name":"sid","value":"bd6aagp7","http_only":0,"expires":1595674432},{"name":"SESSDATA","value":"6d74d850%123%2Cf0e36b61","http_only":1,"expires":1595674432}],"domains":[".bilibili.com",".biligame.com",".bigfunapp.cn"]},"sso":["https://passport.bilibili.com/api/v2/sso","https://passport.biligame.com/api/v2/sso","https://passport.bigfunapp.cn/api/v2/sso"]}} // {"ts":1610254019,"code":0,"data":{"status":2,"url":"https://passport.bilibili.com/account/mobile/security/managephone/phone/verify?tmp_token=2bc5dd260df7158xx860565fxx0d5311&requestId=dffcfxx052fe11xxa9c8e2667739c15c&source=risk","message":"您的账号存在高危异常行为,为了您的账号安全,请验证手机号后登录帐号"}} // https://passport.bilibili.com/mobile/verifytel_h5.html - switch ($de_raw['code']) { - case 0: - // 二次判断 - switch ($de_raw['data']['status']) { - case 0: - // 正常登录 - Log::info("{$mode}登录成功"); - $access_token = $de_raw['data']['token_info']['access_token']; - $refresh_token = $de_raw['data']['token_info']['refresh_token']; - self::saveConfig('ACCESS_TOKEN', $access_token); - self::saveConfig('REFRESH_TOKEN', $refresh_token); - self::saveCookie($de_raw); - Log::info('信息配置完毕'); - break; - case 2: - // 异常高危 - Log::error('登录失败', ['msg' => $de_raw['data']['message']]); - die(); - default: - Log::error('登录失败', ['msg' => '未知错误: ' . $de_raw['data']['message']]); - die(); - break; - } - break; - case -105: - // 需要验证码 - Log::error('登录失败', ['msg' => '此次登录需要验证码或' . $de_raw['message']]); - die(); - break; - case -629: - // 密码错误 - Log::error('登录失败', ['msg' => $de_raw['message']]); - die(); - break; - case -2100: - // 验证手机号 - Log::error('登录失败', ['msg' => '账号启用了设备锁或异地登录需验证手机号']); - die(); - break; - default: - Log::error('登录失败', ['msg' => '未知错误: ' . $de_raw['message']]); - die(); - break; - } + self::loginAfter($mode, $de_raw['code'], $de_raw); } /** @@ -366,7 +289,7 @@ class Login */ private static function smsLogin(string $mode = '短信模式') { - Log::info("尝试{$mode}登录"); + Log::info("尝试 {$mode} 登录"); self::checkPhone(self::$username); $captcha = self::sendSms(self::$username); $url = 'https://passport.bilibili.com/x/passport-login/login/sms'; @@ -379,38 +302,7 @@ class Login ]; $raw = Curl::post('app', $url, Sign::login($payload)); $de_raw = json_decode($raw, true); - switch ($de_raw['code']) { - case 0: - // 正常登录 - Log::info("{$mode}登录成功"); - $access_token = $de_raw['data']['token_info']['access_token']; - $refresh_token = $de_raw['data']['token_info']['refresh_token']; - self::saveConfig('ACCESS_TOKEN', $access_token); - self::saveConfig('REFRESH_TOKEN', $refresh_token); - self::saveCookie($de_raw); - Log::info('信息配置完毕'); - break; - case -105: - // 需要验证码 - Log::error('登录失败', ['msg' => '此次登录需要验证码或' . $de_raw['message']]); - die(); - break; - case -629: - // 密码错误 - Log::error('登录失败', ['msg' => $de_raw['message']]); - die(); - break; - case -2100: - // 验证手机号 - Log::error('登录失败', ['msg' => '账号启用了设备锁或异地登录需验证手机号']); - die(); - break; - default: - Log::error('登录失败', ['msg' => '未知错误: ' . $de_raw['message']]); - die(); - break; - } - + self::loginAfter($mode, $de_raw['code'], $de_raw); } /** @@ -454,6 +346,85 @@ class Login die(); } + /** + * @use 登录之后 + * @param $mode + * @param $code + * @param $data + */ + private static function loginAfter($mode, $code, $data) + { + switch ($code) { + case 0: + // data->data->status number + if (array_key_exists('status', $data['data'])) { + // 二次判断 + switch ($data['data']['status']) { + case 0: + // 正常登录 + self::loginSuccess($mode, $data); + break; + case 2: + // 异常高危 + self::loginFail($mode, $data['data']['message']); + break; + default: + // 未知错误 + self::loginFail($mode, '未知错误: ' . $data['data']['message']); + break; + } + } + // 正常登录 + self::loginSuccess($mode, $data); + break; + case -105: + // 需要验证码 + self::loginFail($mode, '此次登录需要验证码或' . $data['message']); + break; + case -629: + // 密码错误 + self::loginFail($mode, $data['message']); + break; + case -2100: + // 验证手机号 + self::loginFail($mode, '账号启用了设备锁或异地登录需验证手机号'); + break; + default: + // 未知错误 + self::loginFail($mode, '未知错误: ' . $data['message']); + break; + } + + } + + /** + * @use 登陆成功 + * @param $mode + * @param $data + */ + private static function loginSuccess($mode, $data) + { + Log::info("{$mode} 登录成功"); + $access_token = $data['data']['token_info']['access_token']; + $refresh_token = $data['data']['token_info']['refresh_token']; + self::saveConfig('ACCESS_TOKEN', $access_token); + self::saveConfig('REFRESH_TOKEN', $refresh_token); + self::saveCookie($data); + Log::info('信息配置完毕'); + } + + /** + * @use 登陆失败 + * @param $mode + * @param $data + */ + private static function loginFail($mode, $data) + { + Log::error("{$mode} 登录失败"); + Log::error('登录失败', ['msg' => $data]); + die(); + } + /** * @use 检查手机号格式 * @param string $phone @@ -475,7 +446,7 @@ class Login private static function saveConfig(string $key, string $value, $hide = true) { Config::put($key, $value); - Log::info(" > {$key}: " . ($hide ? Common::replaceStar($value,4,4) : $value)); + Log::info(" > {$key}: " . ($hide ? Common::replaceStar($value, 4, 4) : $value)); } /** @@ -503,5 +474,23 @@ class Login } } + /** + * @use 刷新Cookie + */ + private static function refreshCookie(): string + { + $url = 'https://passport.bilibili.com/api/login/sso'; + $payload = [ + 'gourl' => 'https%3A%2F%2Faccount.bilibili.com%2Faccount%2Fhome' + ]; + $response = Curl::headers('app', $url, Sign::common($payload)); + $headers = $response['Set-Cookie']; + $cookies = []; + foreach ($headers as $header) { + preg_match_all('/^(.*);/iU', $header, $cookie); + array_push($cookies, $cookie[0][0]); + } + return implode("", array_reverse($cookies)); + } } \ No newline at end of file diff --git a/src/plugin/PolishTheMetal.php b/src/plugin/PolishTheMetal.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/src/plugin/PolishTheMetal.php @@ -0,0 +1 @@ +