mirror of
https://github.com/lkeme/BiliHelper-personal.git
synced 2025-12-19 09:30:10 +08:00
[add] CheckUpdate [update] Login
This commit is contained in:
parent
26329986ac
commit
34bffe404f
@ -18,7 +18,8 @@
|
|||||||
"guzzlehttp/guzzle": "^6.5.5",
|
"guzzlehttp/guzzle": "^6.5.5",
|
||||||
"mathieuviossat/arraytotexttable": "^1.0.8",
|
"mathieuviossat/arraytotexttable": "^1.0.8",
|
||||||
"klkvsk/json-decode-stream": "^1.0",
|
"klkvsk/json-decode-stream": "^1.0",
|
||||||
"sven/file-config": "^3.1"
|
"sven/file-config": "^3.1",
|
||||||
|
"hassankhan/config": "^2.2"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
|
|||||||
96
composer.lock
generated
96
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "a9407272d4bb9ca1632a2aa728429bf0",
|
"content-hash": "7b0e5cfde9ebb70a16c941f59fd2a71d",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "amphp/amp",
|
"name": "amphp/amp",
|
||||||
@ -460,16 +460,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "guzzlehttp/psr7",
|
"name": "guzzlehttp/psr7",
|
||||||
"version": "1.8.1",
|
"version": "1.8.2",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/guzzle/psr7.git",
|
"url": "https://github.com/guzzle/psr7.git",
|
||||||
"reference": "35ea11d335fd638b5882ff1725228b3d35496ab1"
|
"reference": "dc960a912984efb74d0a90222870c72c87f10c91"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/35ea11d335fd638b5882ff1725228b3d35496ab1",
|
"url": "https://api.github.com/repos/guzzle/psr7/zipball/dc960a912984efb74d0a90222870c72c87f10c91",
|
||||||
"reference": "35ea11d335fd638b5882ff1725228b3d35496ab1",
|
"reference": "dc960a912984efb74d0a90222870c72c87f10c91",
|
||||||
"shasum": "",
|
"shasum": "",
|
||||||
"mirrors": [
|
"mirrors": [
|
||||||
{
|
{
|
||||||
@ -535,9 +535,77 @@
|
|||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/guzzle/psr7/issues",
|
"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",
|
"name": "klkvsk/json-decode-stream",
|
||||||
@ -1229,16 +1297,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "psr/log",
|
"name": "psr/log",
|
||||||
"version": "1.1.3",
|
"version": "1.1.4",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/php-fig/log.git",
|
"url": "https://github.com/php-fig/log.git",
|
||||||
"reference": "0f73288fd15629204f9d42b7055f72dacbe811fc"
|
"reference": "d49695b909c3b7628b6289db5479a1c204601f11"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc",
|
"url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11",
|
||||||
"reference": "0f73288fd15629204f9d42b7055f72dacbe811fc",
|
"reference": "d49695b909c3b7628b6289db5479a1c204601f11",
|
||||||
"shasum": "",
|
"shasum": "",
|
||||||
"mirrors": [
|
"mirrors": [
|
||||||
{
|
{
|
||||||
@ -1268,7 +1336,7 @@
|
|||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "PHP-FIG",
|
"name": "PHP-FIG",
|
||||||
"homepage": "http://www.php-fig.org/"
|
"homepage": "https://www.php-fig.org/"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Common interface for logging libraries",
|
"description": "Common interface for logging libraries",
|
||||||
@ -1279,9 +1347,9 @@
|
|||||||
"psr-3"
|
"psr-3"
|
||||||
],
|
],
|
||||||
"support": {
|
"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",
|
"name": "ralouphie/getallheaders",
|
||||||
|
|||||||
@ -87,6 +87,39 @@
|
|||||||
"share": "true",
|
"share": "true",
|
||||||
"draw_times": 1,
|
"draw_times": 1,
|
||||||
"expire_at": "2021-04-25 23:59:59"
|
"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"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
10
data/latest.json
Normal file
10
data/latest.json
Normal file
@ -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'
|
||||||
|
}
|
||||||
@ -66,6 +66,7 @@ class App
|
|||||||
public function start()
|
public function start()
|
||||||
{
|
{
|
||||||
$plugins = [
|
$plugins = [
|
||||||
|
'CheckUpdate',
|
||||||
'Login',
|
'Login',
|
||||||
'Schedule',
|
'Schedule',
|
||||||
'MainSite',
|
'MainSite',
|
||||||
|
|||||||
91
src/plugin/CheckUpdate.php
Normal file
91
src/plugin/CheckUpdate.php
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Website: https://mudew.com/
|
||||||
|
* Author: Lkeme
|
||||||
|
* License: The MIT License
|
||||||
|
* Email: Useri@live.cn
|
||||||
|
* Updated: 2021 ~ 2022
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BiliHelper\Plugin;
|
||||||
|
|
||||||
|
use Noodlehaus\Config;
|
||||||
|
use Noodlehaus\Parser\Json;
|
||||||
|
use BiliHelper\Core\Log;
|
||||||
|
use BiliHelper\Core\Curl;
|
||||||
|
use BiliHelper\Util\TimeLock;
|
||||||
|
|
||||||
|
|
||||||
|
class CheckUpdate
|
||||||
|
{
|
||||||
|
use TimeLock;
|
||||||
|
|
||||||
|
private static $conf;
|
||||||
|
private static $latest_conf;
|
||||||
|
private static $repository = APP_DATA_PATH . 'latest.json';
|
||||||
|
|
||||||
|
|
||||||
|
public static function run()
|
||||||
|
{
|
||||||
|
if (self::getLock() > 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -48,7 +48,6 @@ class Login
|
|||||||
self::setLock(3600);
|
self::setLock(3600);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @use 登录控制中心
|
* @use 登录控制中心
|
||||||
*/
|
*/
|
||||||
@ -92,12 +91,11 @@ class Login
|
|||||||
self::$password = self::publicKeyEnc($pass);
|
self::$password = self::publicKeyEnc($pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @use 保持认证
|
* @use 保持认证
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private static function keepAuth()
|
private static function keepAuth(): bool
|
||||||
{
|
{
|
||||||
if (self::getLock() > time()) {
|
if (self::getLock() > time()) {
|
||||||
return true;
|
return true;
|
||||||
@ -119,7 +117,7 @@ class Login
|
|||||||
* @use 获取令牌信息
|
* @use 获取令牌信息
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private static function checkToken()
|
private static function checkToken(): bool
|
||||||
{
|
{
|
||||||
$url = 'https://passport.bilibili.com/api/v2/oauth2/info';
|
$url = 'https://passport.bilibili.com/api/v2/oauth2/info';
|
||||||
$payload = [
|
$payload = [
|
||||||
@ -135,11 +133,10 @@ class Login
|
|||||||
return $data['data']['expires_in'] > 14400;
|
return $data['data']['expires_in'] > 14400;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @use 刷新Token
|
* @use 刷新Token
|
||||||
*/
|
*/
|
||||||
private static function refreshToken()
|
private static function refreshToken(): bool
|
||||||
{
|
{
|
||||||
$url = 'https://passport.bilibili.com/api/v2/oauth2/refresh_token';
|
$url = 'https://passport.bilibili.com/api/v2/oauth2/refresh_token';
|
||||||
$payload = [
|
$payload = [
|
||||||
@ -163,35 +160,6 @@ class Login
|
|||||||
return true;
|
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 公钥加密
|
* @use 公钥加密
|
||||||
* @param $plaintext
|
* @param $plaintext
|
||||||
@ -218,7 +186,6 @@ class Login
|
|||||||
return base64_encode($crypt);
|
return base64_encode($crypt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @use 获取验证码
|
* @use 获取验证码
|
||||||
* @return array|string[]
|
* @return array|string[]
|
||||||
@ -273,7 +240,6 @@ class Login
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @use 验证码登录
|
* @use 验证码登录
|
||||||
* @param string $mode
|
* @param string $mode
|
||||||
@ -293,8 +259,8 @@ class Login
|
|||||||
*/
|
*/
|
||||||
private static function accountLogin(string $validate = '', string $challenge = '', string $mode = '账密模式')
|
private static function accountLogin(string $validate = '', string $challenge = '', string $mode = '账密模式')
|
||||||
{
|
{
|
||||||
Log::info("尝试{$mode}登录");
|
Log::info("尝试 {$mode} 登录");
|
||||||
// $url = 'https://passport.bilibili.com/api/v3/oauth2/login';
|
// $url = 'https://passport.bilibili.com/api/v3/oauth2/login';
|
||||||
$url = 'https://passport.bilibili.com/x/passport-login/oauth2/login';
|
$url = 'https://passport.bilibili.com/x/passport-login/oauth2/login';
|
||||||
$payload = [
|
$payload = [
|
||||||
'seccode' => $validate ? "{$validate}|jordan" : '',
|
'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":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":"您的账号存在高危异常行为,为了您的账号安全,请验证手机号后登录帐号"}}
|
// {"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
|
// https://passport.bilibili.com/mobile/verifytel_h5.html
|
||||||
switch ($de_raw['code']) {
|
self::loginAfter($mode, $de_raw['code'], $de_raw);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -366,7 +289,7 @@ class Login
|
|||||||
*/
|
*/
|
||||||
private static function smsLogin(string $mode = '短信模式')
|
private static function smsLogin(string $mode = '短信模式')
|
||||||
{
|
{
|
||||||
Log::info("尝试{$mode}登录");
|
Log::info("尝试 {$mode} 登录");
|
||||||
self::checkPhone(self::$username);
|
self::checkPhone(self::$username);
|
||||||
$captcha = self::sendSms(self::$username);
|
$captcha = self::sendSms(self::$username);
|
||||||
$url = 'https://passport.bilibili.com/x/passport-login/login/sms';
|
$url = 'https://passport.bilibili.com/x/passport-login/login/sms';
|
||||||
@ -379,38 +302,7 @@ class Login
|
|||||||
];
|
];
|
||||||
$raw = Curl::post('app', $url, Sign::login($payload));
|
$raw = Curl::post('app', $url, Sign::login($payload));
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
switch ($de_raw['code']) {
|
self::loginAfter($mode, $de_raw['code'], $de_raw);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -454,6 +346,85 @@ class Login
|
|||||||
die();
|
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 检查手机号格式
|
* @use 检查手机号格式
|
||||||
* @param string $phone
|
* @param string $phone
|
||||||
@ -475,7 +446,7 @@ class Login
|
|||||||
private static function saveConfig(string $key, string $value, $hide = true)
|
private static function saveConfig(string $key, string $value, $hide = true)
|
||||||
{
|
{
|
||||||
Config::put($key, $value);
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
1
src/plugin/PolishTheMetal.php
Normal file
1
src/plugin/PolishTheMetal.php
Normal file
@ -0,0 +1 @@
|
|||||||
|
<?php
|
||||||
Loading…
Reference in New Issue
Block a user