mirror of
https://github.com/lkeme/BiliHelper-personal.git
synced 2025-12-19 09:30:10 +08:00
[update] Version 0.3.0 fixes #15
This commit is contained in:
parent
5046962fa4
commit
1f42e90de2
1
.gitignore
vendored
1
.gitignore
vendored
@ -23,3 +23,4 @@ README1.md
|
|||||||
conf/user.conf
|
conf/user.conf
|
||||||
/conf/user.conf
|
/conf/user.conf
|
||||||
/log/
|
/log/
|
||||||
|
/src/backup/
|
||||||
19
CHANGELOG.md
19
CHANGELOG.md
@ -1,6 +1,25 @@
|
|||||||
# Release Notes
|
# Release Notes
|
||||||
# 本项目Log
|
# 本项目Log
|
||||||
|
|
||||||
|
## v0.3.0.200312 alpha (2020-03-12)
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- 引入风纪 (不稳定测试)
|
||||||
|
- 引入新库 (需要重新Composer)
|
||||||
|
-
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- 重构部分公用方法
|
||||||
|
- 重构CURL请求
|
||||||
|
-
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- 修复登陆繁忙
|
||||||
|
- 修复实物抽奖
|
||||||
|
- 修复日志输出
|
||||||
|
- 修复部分已知
|
||||||
|
-
|
||||||
|
|
||||||
## v0.2.0.200226 alpha (2020-02-26)
|
## v0.2.0.200226 alpha (2020-02-26)
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
48
DOC.md
48
DOC.md
@ -2,7 +2,7 @@
|
|||||||
<p align="center"><img width="300px" src="https://i.loli.net/2018/04/20/5ad97bd395912.jpeg"></p>
|
<p align="center"><img width="300px" src="https://i.loli.net/2018/04/20/5ad97bd395912.jpeg"></p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://img.shields.io/badge/version-0.2.0.200226 alpha-green.svg?longCache=true&style=for-the-badge">
|
<img src="https://img.shields.io/badge/version-0.3.0.200312 alpha-green.svg?longCache=true&style=for-the-badge">
|
||||||
<img src="https://img.shields.io/badge/license-mit-blue.svg?longCache=true&style=for-the-badge">
|
<img src="https://img.shields.io/badge/license-mit-blue.svg?longCache=true&style=for-the-badge">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@ -15,29 +15,29 @@ B 站直播实用脚本
|
|||||||
|
|
||||||
|plugin |version |description |
|
|plugin |version |description |
|
||||||
|--------------------|--------------------|--------------------|
|
|--------------------|--------------------|--------------------|
|
||||||
|Login |20.02.24 |账号登录 |
|
|Login |20.03.12 |账号登录 |
|
||||||
|Sleep |20.02.24 |休眠控制 |
|
|Sleep |20.03.12 |休眠控制 |
|
||||||
|MasterSite |20.02.24 |主站助手 |
|
|MasterSite |20.03.12 |主站助手 |
|
||||||
|Daily |20.02.24 |每日礼包 |
|
|Daily |20.03.12 |每日礼包 |
|
||||||
|Heart |20.02.24 |双端心跳 |
|
|Heart |20.03.12 |双端心跳 |
|
||||||
|Task |20.02.24 |每日任务 |
|
|Task |20.03.12 |每日任务 |
|
||||||
|Silver |20.02.24 |银瓜子宝箱 |
|
|Silver |20.03.12 |银瓜子宝箱 |
|
||||||
|Barrage |20.02.24 |活跃弹幕 |
|
|Barrage |20.03.12 |活跃弹幕 |
|
||||||
|Silver2Coin |20.02.24 |银瓜子换硬币 |
|
|Silver2Coin |20.03.12 |银瓜子换硬币 |
|
||||||
|GiftSend |20.02.24 |礼物赠送 |
|
|GiftSend |20.03.12 |礼物赠送 |
|
||||||
|GroupSignIn |20.02.24 |友爱社签到 |
|
|GroupSignIn |20.03.12 |友爱社签到 |
|
||||||
|ManGa |20.02.24 |漫画签到分享 |
|
|ManGa |20.03.12 |漫画签到分享 |
|
||||||
|GiftHeart |20.02.24 |心跳礼物 |
|
|GiftHeart |20.03.12 |心跳礼物 |
|
||||||
|MaterialObject |20.02.24 |实物抽奖 |
|
|MaterialObject |20.03.12 |实物抽奖 |
|
||||||
|AloneTcpClient |20.02.24 |独立监控 |
|
|AloneTcpClient |20.03.12 |独立监控 |
|
||||||
|ZoneTcpClient |20.02.24 |分区监控 |
|
|ZoneTcpClient |20.03.12 |分区监控 |
|
||||||
|StormRaffle |20.02.24 |节奏风暴 |
|
|StormRaffle |20.03.12 |节奏风暴 |
|
||||||
|GiftRaffle |20.02.24 |活动礼物 |
|
|GiftRaffle |20.03.12 |活动礼物 |
|
||||||
|PkRaffle |20.02.24 |大乱斗 |
|
|PkRaffle |20.03.12 |大乱斗 |
|
||||||
|GuardRaffle |20.02.24 |舰长总督 |
|
|GuardRaffle |20.03.12 |舰长总督 |
|
||||||
|AnchorRaffle |20.02.24 |天选时刻 |
|
|AnchorRaffle |20.03.12 |天选时刻 |
|
||||||
|AwardRecord |20.02.24 |获奖通知 |
|
|AwardRecord |20.03.12 |获奖通知 |
|
||||||
|Statistics |20.02.24 |数据统计 |
|
|Statistics |20.03.12 |数据统计 |
|
||||||
|
|
||||||
## 打赏赞助
|
## 打赏赞助
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ Group: [55308141](https://jq.qq.com/?_wv=1027&k=5AIDaJg)
|
|||||||
|
|
||||||
## 公告
|
## 公告
|
||||||
|
|
||||||
Currently for Personal Edition **0.2.0.200226 alpha**
|
Currently for Personal Edition **0.3.0.200312 alpha**
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
"clue/socket-raw": "^1.4.1",
|
"clue/socket-raw": "^1.4.1",
|
||||||
"vlucas/phpdotenv": "^4.1",
|
"vlucas/phpdotenv": "^4.1",
|
||||||
"amphp/amp": "^2.4",
|
"amphp/amp": "^2.4",
|
||||||
"ares333/php-curl": "^4.6"
|
"guzzlehttp/guzzle": "^6.5"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
@ -30,7 +30,8 @@
|
|||||||
"BiliHelper\\Core\\": "src/core",
|
"BiliHelper\\Core\\": "src/core",
|
||||||
"BiliHelper\\Plugin\\": "src/plugin",
|
"BiliHelper\\Plugin\\": "src/plugin",
|
||||||
"BiliHelper\\Util\\": "src/util",
|
"BiliHelper\\Util\\": "src/util",
|
||||||
"BiliHelper\\Tool\\": "src/tool"
|
"BiliHelper\\Tool\\": "src/tool",
|
||||||
|
"BiliHelper\\Backup\\": "src/backup"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1360
composer.lock
generated
1360
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -60,6 +60,9 @@ SLEEP_SECTION=2,3,4,5,6
|
|||||||
# 漫画助手
|
# 漫画助手
|
||||||
USE_MANGA=false
|
USE_MANGA=false
|
||||||
|
|
||||||
|
# 风纪(测试)
|
||||||
|
USE_JUDGE=false
|
||||||
|
|
||||||
#######################
|
#######################
|
||||||
# 基础设置 #
|
# 基础设置 #
|
||||||
#######################
|
#######################
|
||||||
@ -73,14 +76,6 @@ ALONE_SERVER_KEY=,*(?PVl]nIbo35sB
|
|||||||
USE_ZONE_SERVER=false
|
USE_ZONE_SERVER=false
|
||||||
ZONE_SERVER_ADDR=tcp://broadcastlv.chat.bilibili.com:2243/sub
|
ZONE_SERVER_ADDR=tcp://broadcastlv.chat.bilibili.com:2243/sub
|
||||||
|
|
||||||
# 切换HTTPS|为真则使用https协议
|
|
||||||
USE_HTTPS=true
|
|
||||||
|
|
||||||
# 是否使用代理(前提保证有效代理)
|
|
||||||
USE_PROXY=false
|
|
||||||
PROXY_IP=127.0.0.1
|
|
||||||
PROXY_PORT=8888
|
|
||||||
|
|
||||||
# SERVER酱|令牌KEY|过滤关键词|逗号分隔
|
# SERVER酱|令牌KEY|过滤关键词|逗号分隔
|
||||||
USE_SC=false
|
USE_SC=false
|
||||||
SC_KEY=
|
SC_KEY=
|
||||||
@ -102,6 +97,17 @@ ROOM_LIST=9522051
|
|||||||
# 弹幕监控房间(为空则随机)
|
# 弹幕监控房间(为空则随机)
|
||||||
SOCKET_ROOM_ID=9522051
|
SOCKET_ROOM_ID=9522051
|
||||||
|
|
||||||
|
#######################
|
||||||
|
# 网络设置 #
|
||||||
|
#######################
|
||||||
|
|
||||||
|
# 验证SSL证书|请求时验证SSL证书行为
|
||||||
|
VERIFY_SSL=true
|
||||||
|
|
||||||
|
# 是否使用代理|(http\https)
|
||||||
|
USE_PROXY=false
|
||||||
|
NETWORK_PROXY=http://127.0.0.1:8888
|
||||||
|
|
||||||
#######################
|
#######################
|
||||||
# 程序设置 #
|
# 程序设置 #
|
||||||
#######################
|
#######################
|
||||||
|
|||||||
@ -74,6 +74,7 @@ class App
|
|||||||
'Silver',
|
'Silver',
|
||||||
'Barrage',
|
'Barrage',
|
||||||
'Silver2Coin',
|
'Silver2Coin',
|
||||||
|
'Judge',
|
||||||
'GiftSend',
|
'GiftSend',
|
||||||
'GroupSignIn',
|
'GroupSignIn',
|
||||||
'GiftHeart',
|
'GiftHeart',
|
||||||
|
|||||||
@ -12,30 +12,257 @@ namespace BiliHelper\Core;
|
|||||||
|
|
||||||
class Curl
|
class Curl
|
||||||
{
|
{
|
||||||
public static $headers = array(
|
private static $client;
|
||||||
'Accept' => '*/*',
|
private static $async_opt;
|
||||||
'Accept-Encoding' => 'gzip',
|
|
||||||
'Accept-Language' => 'zh-cn',
|
|
||||||
'Connection' => 'keep-alive',
|
|
||||||
'Content-Type' => 'application/x-www-form-urlencoded',
|
|
||||||
'User-Agent' => 'bili-universal/8470 CFNetwork/978.0.7 Darwin/18.5.0',
|
|
||||||
// 'Referer' => 'https://live.bilibili.com/',
|
|
||||||
);
|
|
||||||
|
|
||||||
private static $results = [];
|
private static $results = [];
|
||||||
private static $result = [];
|
private static $result = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @use 数组
|
* @use POST请求
|
||||||
* @return array
|
* @param $os
|
||||||
|
* @param $url
|
||||||
|
* @param array $params
|
||||||
|
* @param array $headers
|
||||||
|
* @param int $timeout
|
||||||
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
private static function getResults()
|
public static function post($os, $url, $params = [], $headers = [], $timeout = 30)
|
||||||
{
|
{
|
||||||
$results = self::$results;
|
Log::debug("POST: {$url}");
|
||||||
self::$results = [];
|
$headers = self::getHeaders($os, $headers);
|
||||||
return $results;
|
$payload['form_params'] = count($params) ? $params : [];
|
||||||
|
$options = self::getClientOpt($payload, $headers);
|
||||||
|
$request = self::clientHandle($url, 'post', $options);
|
||||||
|
$body = $request->getBody();
|
||||||
|
Log::debug($body);
|
||||||
|
return $body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use GET请求
|
||||||
|
* @param $os
|
||||||
|
* @param $url
|
||||||
|
* @param array $params
|
||||||
|
* @param array $headers
|
||||||
|
* @param int $timeout
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function get($os, $url, $params = [], $headers = [], $timeout = 30)
|
||||||
|
{
|
||||||
|
Log::debug("GET: {$url}");
|
||||||
|
$headers = self::getHeaders($os, $headers);
|
||||||
|
$payload['query'] = count($params) ? $params : [];
|
||||||
|
$options = self::getClientOpt($payload, $headers);
|
||||||
|
$request = self::clientHandle($url, 'get', $options);
|
||||||
|
$body = $request->getBody();
|
||||||
|
Log::debug($body);
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use PUT请求
|
||||||
|
* @param $os
|
||||||
|
* @param $url
|
||||||
|
* @param array $params
|
||||||
|
* @param array $headers
|
||||||
|
* @param int $timeout
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function put($os, $url, $params = [], $headers = [], $timeout = 30)
|
||||||
|
{
|
||||||
|
Log::debug("PUT: {$url}");
|
||||||
|
$headers = self::getHeaders($os, $headers);
|
||||||
|
$payload['json'] = count($params) ? $params : [];
|
||||||
|
$options = self::getClientOpt($payload, $headers);
|
||||||
|
$request = self::clientHandle($url, 'post', $options);
|
||||||
|
$body = $request->getBody();
|
||||||
|
Log::debug($body);
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 并发POST请求
|
||||||
|
* @param $os
|
||||||
|
* @param $url
|
||||||
|
* @param array $tasks
|
||||||
|
* @param array $headers
|
||||||
|
* @param int $timeout
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function async($os, $url, $tasks = [], $headers = [], $timeout = 30)
|
||||||
|
{
|
||||||
|
self::$async_opt = [
|
||||||
|
'tasks' => $tasks,
|
||||||
|
'counter' => 1,
|
||||||
|
'count' => count($tasks),
|
||||||
|
'concurrency' => count($tasks) < 10 ? count($tasks) : 10
|
||||||
|
];
|
||||||
|
Log::debug("ASYNC: {$url}");
|
||||||
|
$headers = self::getHeaders($os, $headers);
|
||||||
|
$requests = function ($total) use ($url, $headers, $tasks) {
|
||||||
|
foreach ($tasks as $task) {
|
||||||
|
yield function () use ($url, $headers, $task) {
|
||||||
|
$payload['form_params'] = $task['payload'];
|
||||||
|
$options = self::getClientOpt($payload, $headers);
|
||||||
|
return self::clientHandle($url, 'postAsync', $options);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$pool = new \GuzzleHttp\Pool(self::$client, $requests(self::$async_opt['count']), [
|
||||||
|
'concurrency' => self::$async_opt['concurrency'],
|
||||||
|
'fulfilled' => function ($response, $index) {
|
||||||
|
$res = $response->getBody();
|
||||||
|
// Log::notice("启动多线程 {$index}");
|
||||||
|
array_push(self::$results, [
|
||||||
|
'content' => $res,
|
||||||
|
'source' => self::$async_opt['tasks'][$index]['source']
|
||||||
|
]);
|
||||||
|
self::countedAndCheckEnded();
|
||||||
|
},
|
||||||
|
'rejected' => function ($reason, $index) {
|
||||||
|
Log::error("多线程第{$index}个请求失败, ERROR: {$reason}");
|
||||||
|
self::countedAndCheckEnded();
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
// 开始发送请求
|
||||||
|
$promise = $pool->promise();
|
||||||
|
$promise->wait();
|
||||||
|
return self::getResults();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 单次请求
|
||||||
|
* @param $method
|
||||||
|
* @param $url
|
||||||
|
* @param array $payload
|
||||||
|
* @param array $headers
|
||||||
|
* @param int $timeout
|
||||||
|
* @return false|string|null
|
||||||
|
*/
|
||||||
|
public static function request($method, $url, $payload = [], $headers = [], $timeout = 10)
|
||||||
|
{
|
||||||
|
Log::debug("REQUEST: {$url}");
|
||||||
|
$options = array(
|
||||||
|
'http' => array(
|
||||||
|
'method' => strtoupper($method),
|
||||||
|
'header' => self::arr2str($headers),
|
||||||
|
'content' => http_build_query($payload),
|
||||||
|
'timeout' => $timeout,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$result = @file_get_contents($url, false, stream_context_create($options));
|
||||||
|
Log::debug($result);
|
||||||
|
return $result ? $result : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 计数搭配并发使用
|
||||||
|
*/
|
||||||
|
private static function countedAndCheckEnded()
|
||||||
|
{
|
||||||
|
if (self::$async_opt['counter'] < self::$async_opt['count']) {
|
||||||
|
self::$async_opt['counter']++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
# 请求结束!
|
||||||
|
self::$async_opt = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 请求中心异常处理
|
||||||
|
* @param string $url
|
||||||
|
* @param string $method
|
||||||
|
* @param array $options
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private static function clientHandle(string $url, string $method, array $options)
|
||||||
|
{
|
||||||
|
$max_retry = range(0, 30);
|
||||||
|
foreach ($max_retry as $retry) {
|
||||||
|
try {
|
||||||
|
return call_user_func_array([self::$client, $method], [$url, $options]);
|
||||||
|
} catch (\GuzzleHttp\Exception\RequestException $e) {
|
||||||
|
Log::warning("CURl -> RETRY: {$retry} ERROR: {$e->getMessage()} ERRNO: {$e->getCode()}");
|
||||||
|
// var_dump($e->getRequest());
|
||||||
|
if ($e->hasResponse()) {
|
||||||
|
var_dump($e->getResponse());
|
||||||
|
}
|
||||||
|
Log::warning("尝试重试第 {$retry} 次,等待网络恢复...");
|
||||||
|
sleep(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exit('网络异常,超出最大尝试次数,退出程序~');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 获取请求配置
|
||||||
|
* @param array $add_options
|
||||||
|
* @param array $headers
|
||||||
|
* @param float $timeout
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private static function getClientOpt(array $add_options, array $headers = [], float $timeout = 30.0)
|
||||||
|
{
|
||||||
|
self::$client = new \GuzzleHttp\Client();
|
||||||
|
$default_options = [
|
||||||
|
'headers' => $headers,
|
||||||
|
'timeout' => $timeout,
|
||||||
|
'http_errors' => false,
|
||||||
|
'verify' => getenv('VERIFY_SSL') == 'false' ? false : true,
|
||||||
|
];
|
||||||
|
if (getenv('USE_PROXY') == 'true') {
|
||||||
|
$default_options['proxy'] = getenv('NETWORK_PROXY');
|
||||||
|
}
|
||||||
|
return array_merge($default_options, $add_options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 获取Headers
|
||||||
|
* @param string $os
|
||||||
|
* @param array $headers
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private static function getHeaders(string $os = 'app', array $headers = []): array
|
||||||
|
{
|
||||||
|
$app_headers = [
|
||||||
|
'Accept' => '*/*',
|
||||||
|
'Accept-Encoding' => 'gzip',
|
||||||
|
'Accept-Language' => 'zh-cn',
|
||||||
|
'Connection' => 'keep-alive',
|
||||||
|
'Content-Type' => 'application/x-www-form-urlencoded',
|
||||||
|
'User-Agent' => 'Mozilla/5.0 BiliDroid/5.51.1 (bbcallen@gmail.com)',
|
||||||
|
// 'Referer' => 'https://live.bilibili.com/',
|
||||||
|
];
|
||||||
|
$pc_headers = [
|
||||||
|
'Accept' => "application/json, text/plain, */*",
|
||||||
|
'Accept-Encoding' => 'gzip, deflate',
|
||||||
|
'Accept-Language' => "zh-CN,zh;q=0.9",
|
||||||
|
'Content-Type' => 'application/x-www-form-urlencoded',
|
||||||
|
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/82.0.4056.0 Safari/537.36 Edg/82.0.431.0',
|
||||||
|
// 'Referer' => 'https://live.bilibili.com/',
|
||||||
|
];
|
||||||
|
$other_headers = [
|
||||||
|
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36',
|
||||||
|
];
|
||||||
|
$default_headers = isset(${$os . "_headers"}) ? ${$os . "_headers"} : $other_headers;
|
||||||
|
if (in_array($os, ['app', 'pc']) && getenv('COOKIE') != "") {
|
||||||
|
$default_headers['Cookie'] = getenv('COOKIE');
|
||||||
|
}
|
||||||
|
// return self::formatHeaders(array_merge($default_headers, $headers));
|
||||||
|
return array_merge($default_headers, $headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 格式化Headers
|
||||||
|
* @param $headers
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private static function formatHeaders(array $headers): array
|
||||||
|
{
|
||||||
|
return array_map(function ($k, $v) {
|
||||||
|
return $k . ': ' . $v;
|
||||||
|
}, array_keys($headers), $headers);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @use 字符串or其他
|
* @use 字符串or其他
|
||||||
@ -49,293 +276,14 @@ class Curl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @use 获取Headers
|
* @use 数组
|
||||||
* @param $headers
|
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private static function getHeaders($headers)
|
private static function getResults(): array
|
||||||
{
|
{
|
||||||
return array_map(function ($k, $v) {
|
$results = self::$results;
|
||||||
return $k . ': ' . $v;
|
self::$results = [];
|
||||||
}, array_keys($headers), $headers);
|
return $results;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @use 初始化Curl
|
|
||||||
* @param int $tasks_num
|
|
||||||
* @param bool $bar
|
|
||||||
* @return \Ares333\Curl\Curl
|
|
||||||
*/
|
|
||||||
private static function getMultiClient(int $tasks_num = 1, bool $bar = false)
|
|
||||||
{
|
|
||||||
$toolkit = new \Ares333\Curl\Toolkit();
|
|
||||||
$toolkit->setCurl();
|
|
||||||
$curl = $toolkit->getCurl();
|
|
||||||
$curl->maxThread = $tasks_num < 10 ? $tasks_num : 10;
|
|
||||||
if (!$bar) {
|
|
||||||
$curl->onInfo = null;
|
|
||||||
}
|
|
||||||
return $curl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @use 填充CURL_OPT
|
|
||||||
* @param $url
|
|
||||||
* @param $payload
|
|
||||||
* @param $headers
|
|
||||||
* @param $timeout
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private static function fillCurlOpts($url, $payload, $headers, $timeout): array
|
|
||||||
{
|
|
||||||
$default_opts = [
|
|
||||||
CURLOPT_URL => self::http2https($url),
|
|
||||||
CURLOPT_HEADER => 0,
|
|
||||||
CURLOPT_ENCODING => 'gzip',
|
|
||||||
CURLOPT_IPRESOLVE => 1,
|
|
||||||
CURLINFO_HEADER_OUT => true,
|
|
||||||
CURLOPT_TIMEOUT => $timeout,
|
|
||||||
CURLOPT_USERAGENT => self::$headers['User-Agent'],
|
|
||||||
CURLOPT_HTTPHEADER => is_null($headers) ? self::getHeaders(self::$headers) : self::getHeaders($headers),
|
|
||||||
CURLOPT_COOKIE => getenv('COOKIE') != "" ? getenv('COOKIE') : "",
|
|
||||||
// CURLOPT_CONNECTTIMEOUT => 10,
|
|
||||||
// CURLOPT_AUTOREFERER => true,
|
|
||||||
// CURLOPT_RETURNTRANSFER => true,
|
|
||||||
// CURLOPT_FOLLOWLOCATION => true,
|
|
||||||
// CURLOPT_SSL_VERIFYHOST => false,
|
|
||||||
// CURLOPT_SSL_VERIFYPEER => false,
|
|
||||||
// CURLOPT_MAXREDIRS => 5
|
|
||||||
];
|
|
||||||
if ($payload) {
|
|
||||||
$default_opts[CURLOPT_POST] = 1;
|
|
||||||
$payload = is_bool($payload) ? [] : (is_array($payload) ? http_build_query($payload) : $payload);
|
|
||||||
$default_opts[CURLOPT_POSTFIELDS] = $payload;
|
|
||||||
}
|
|
||||||
if (getenv('USE_PROXY') == 'true') {
|
|
||||||
$default_opts[CURLOPT_PROXY] = getenv('PROXY_IP');
|
|
||||||
$default_opts[CURLOPT_PROXYPORT] = getenv('PROXY_PORT');
|
|
||||||
}
|
|
||||||
return $default_opts;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @use async
|
|
||||||
* @param $url
|
|
||||||
* @param array $tasks
|
|
||||||
* @param null $headers
|
|
||||||
* @param int $timeout
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function asyncPost($url, $tasks = [], $headers = null, $timeout = 30)
|
|
||||||
{
|
|
||||||
$curl = self::getMultiClient(count($tasks));
|
|
||||||
$curl_options = self::fillCurlOpts($url, true, $headers, $timeout);
|
|
||||||
$curl->onTask = function ($curl) use ($curl_options, &$tasks) {
|
|
||||||
$task = array_shift($tasks);
|
|
||||||
if (is_null($task)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$payload = $task['payload'];
|
|
||||||
$curl_options[CURLOPT_POSTFIELDS] = is_array($payload) ? http_build_query($payload) : $payload;
|
|
||||||
$curl->add([
|
|
||||||
'opt' => $curl_options,
|
|
||||||
'args' => $task['source'],
|
|
||||||
], function ($response, $args) {
|
|
||||||
Log::debug($response['info']['url']);
|
|
||||||
array_push(self::$results, [
|
|
||||||
'content' => $response['body'],
|
|
||||||
'source' => $args
|
|
||||||
]);
|
|
||||||
Log::debug($response['body']);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
$curl->start();
|
|
||||||
return self::getResults();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @use post
|
|
||||||
* @param $url
|
|
||||||
* @param $payload
|
|
||||||
* @param null $headers
|
|
||||||
* @param int $timeout
|
|
||||||
* @return bool|string
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public static function post($url, $payload = null, $headers = null, $timeout = 30)
|
|
||||||
{
|
|
||||||
$url = self::http2https($url);
|
|
||||||
Log::debug($url);
|
|
||||||
$header = is_null($headers) ? self::getHeaders(self::$headers) : self::getHeaders($headers);
|
|
||||||
|
|
||||||
// 重试次数
|
|
||||||
$ret_count = 300;
|
|
||||||
$waring = 280;
|
|
||||||
|
|
||||||
while ($ret_count) {
|
|
||||||
// 网络断开判断 延时方便连接网络
|
|
||||||
if ($ret_count < $waring) {
|
|
||||||
Log::warning("正常等待网络连接状态恢复正常...");
|
|
||||||
sleep(random_int(5, 10));
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
$curl = curl_init();
|
|
||||||
if (!is_null($payload)) {
|
|
||||||
curl_setopt($curl, CURLOPT_POST, 1);
|
|
||||||
curl_setopt($curl, CURLOPT_POSTFIELDS, is_array($payload) ? http_build_query($payload) : $payload);
|
|
||||||
}
|
|
||||||
curl_setopt($curl, CURLOPT_URL, $url);
|
|
||||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
|
|
||||||
curl_setopt($curl, CURLOPT_HEADER, 0);
|
|
||||||
curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
|
|
||||||
curl_setopt($curl, CURLOPT_IPRESOLVE, 1);
|
|
||||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
||||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
|
||||||
// 超时 重要
|
|
||||||
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
|
|
||||||
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
|
|
||||||
if (($cookie = getenv('COOKIE')) != "") {
|
|
||||||
curl_setopt($curl, CURLOPT_COOKIE, $cookie);
|
|
||||||
}
|
|
||||||
if (getenv('USE_PROXY') == 'true') {
|
|
||||||
curl_setopt($curl, CURLOPT_PROXY, getenv('PROXY_IP'));
|
|
||||||
curl_setopt($curl, CURLOPT_PROXYPORT, getenv('PROXY_PORT'));
|
|
||||||
}
|
|
||||||
$raw = curl_exec($curl);
|
|
||||||
|
|
||||||
if ($err_no = curl_errno($curl)) {
|
|
||||||
throw new \Exception(curl_error($curl));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($raw === false || strpos($raw, 'timeout') !== false) {
|
|
||||||
Log::warning('获取的资源无效!');
|
|
||||||
$ret_count--;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log::debug($raw);
|
|
||||||
curl_close($curl);
|
|
||||||
return $raw;
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
Log::warning("Curl请求出错, {$e->getMessage()}!");
|
|
||||||
$ret_count--;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exit('重试次数过多,请检查代码,退出!');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @use request
|
|
||||||
* @param $url
|
|
||||||
* @param null $payload
|
|
||||||
* @param null $headers
|
|
||||||
* @param null $cookie
|
|
||||||
* @param int $timeout
|
|
||||||
* @return bool|string
|
|
||||||
*/
|
|
||||||
public static function request($url, $payload = null, $headers = null, $cookie = null, $timeout = 30)
|
|
||||||
{
|
|
||||||
Log::debug($url);
|
|
||||||
$header = is_null($headers) ? self::getHeaders(self::$headers) : self::getHeaders($headers);
|
|
||||||
|
|
||||||
// 重试次数
|
|
||||||
$ret_count = 30;
|
|
||||||
while ($ret_count) {
|
|
||||||
try {
|
|
||||||
$curl = curl_init();
|
|
||||||
if (!is_null($payload)) {
|
|
||||||
curl_setopt($curl, CURLOPT_POST, 1);
|
|
||||||
curl_setopt($curl, CURLOPT_POSTFIELDS, is_array($payload) ? http_build_query($payload) : $payload);
|
|
||||||
}
|
|
||||||
curl_setopt($curl, CURLOPT_URL, $url);
|
|
||||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
|
|
||||||
curl_setopt($curl, CURLOPT_HEADER, 0);
|
|
||||||
curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
|
|
||||||
curl_setopt($curl, CURLOPT_IPRESOLVE, 1);
|
|
||||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
||||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
|
||||||
// 超时 重要
|
|
||||||
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
|
|
||||||
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
|
|
||||||
// 认证
|
|
||||||
if (!is_null($cookie)) {
|
|
||||||
curl_setopt($curl, CURLOPT_COOKIE, $cookie);
|
|
||||||
}
|
|
||||||
if (getenv('USE_PROXY') == 'true') {
|
|
||||||
curl_setopt($curl, CURLOPT_PROXY, getenv('PROXY_IP'));
|
|
||||||
curl_setopt($curl, CURLOPT_PROXYPORT, getenv('PROXY_PORT'));
|
|
||||||
}
|
|
||||||
$raw = curl_exec($curl);
|
|
||||||
|
|
||||||
if ($err_no = curl_errno($curl)) {
|
|
||||||
throw new \Exception(curl_error($curl));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($raw === false || strpos($raw, 'timeout') !== false) {
|
|
||||||
Log::warning('获取的资源无效!');
|
|
||||||
$ret_count--;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log::debug($raw);
|
|
||||||
curl_close($curl);
|
|
||||||
return $raw;
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
Log::warning("Curl请求出错, {$e->getMessage()}!");
|
|
||||||
$ret_count--;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exit('重试次数过多,请检查代码,退出!');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @use get
|
|
||||||
* @param $url
|
|
||||||
* @param null $payload
|
|
||||||
* @param null $headers
|
|
||||||
* @return bool|string
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public static function get($url, $payload = null, $headers = null)
|
|
||||||
{
|
|
||||||
if (!is_null($payload)) {
|
|
||||||
$url .= '?' . http_build_query($payload);
|
|
||||||
}
|
|
||||||
return self::post($url, null, $headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @use 单次请求
|
|
||||||
* @param $method
|
|
||||||
* @param $url
|
|
||||||
* @param array $payload
|
|
||||||
* @param array $headers
|
|
||||||
* @param int $timeout
|
|
||||||
* @return false|string
|
|
||||||
*/
|
|
||||||
public static function singleRequest($method, $url, $payload = [], $headers = [], $timeout = 10)
|
|
||||||
{
|
|
||||||
$url = self::http2https($url);
|
|
||||||
Log::debug($url);
|
|
||||||
$options = array(
|
|
||||||
'http' => array(
|
|
||||||
'method' => strtoupper($method),
|
|
||||||
'header' => self::arr2str($headers),
|
|
||||||
'content' => http_build_query($payload),
|
|
||||||
'timeout' => $timeout,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
$result = @file_get_contents($url, false, stream_context_create($options));
|
|
||||||
Log::debug($result);
|
|
||||||
return $result ? $result : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -353,31 +301,24 @@ class Curl
|
|||||||
return $tmp;
|
return $tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @use http(s)转换
|
* @use GET请求
|
||||||
* @param string $url
|
* @param $os
|
||||||
* @return string
|
* @param $url
|
||||||
|
* @param array $params
|
||||||
|
* @param array $headers
|
||||||
|
* @param int $timeout
|
||||||
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
private static function http2https(string $url): string
|
public static function headers($os, $url, $params = [], $headers = [], $timeout = 30)
|
||||||
{
|
{
|
||||||
switch (getenv('USE_HTTPS')) {
|
Log::debug('HEADERS: ' . $url);
|
||||||
case 'false':
|
$headers = self::getHeaders($os, $headers);
|
||||||
if (strpos($url, 'ttps://')) {
|
$payload['query'] = count($params) ? $params : [];
|
||||||
$url = str_replace('https://', 'http://', $url);
|
$payload['allow_redirects'] = false;
|
||||||
}
|
$options = self::getClientOpt($payload, $headers);
|
||||||
break;
|
$request = self::clientHandle($url, 'get', $options);
|
||||||
case 'true':
|
Log::debug("获取Headers");
|
||||||
if (strpos($url, 'ttp://')) {
|
return $request->getHeaders();
|
||||||
$url = str_replace('http://', 'https://', $url);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Log::warning('当前协议设置不正确,请检查配置文件!');
|
|
||||||
die();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $url;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -104,7 +104,7 @@ class Log
|
|||||||
$url = str_replace('{account}', self::prefix(), getenv('APP_CALLBACK'));
|
$url = str_replace('{account}', self::prefix(), getenv('APP_CALLBACK'));
|
||||||
$url = str_replace('{level}', $level, $url);
|
$url = str_replace('{level}', $level, $url);
|
||||||
$url = str_replace('{message}', urlencode($message), $url);
|
$url = str_replace('{message}', urlencode($message), $url);
|
||||||
Curl::get($url);
|
Curl::get('other', $url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,7 +170,7 @@ class AloneTcpClient
|
|||||||
Log::info("连接到 {$socket->getPeerName()} 推送服务器");
|
Log::info("连接到 {$socket->getPeerName()} 推送服务器");
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Log::error("连接到推送服务器失败, {$e->getMessage()}");
|
Log::error("连接到推送服务器失败, {$e->getMessage()}");
|
||||||
self::setLock( 60);
|
self::setLock(60);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -219,7 +219,7 @@ class AloneTcpClient
|
|||||||
switch ($data_type) {
|
switch ($data_type) {
|
||||||
case 'raffle':
|
case 'raffle':
|
||||||
// 抽奖推送
|
// 抽奖推送
|
||||||
// Log::notice($body);
|
Log::debug("(receive={$body})");
|
||||||
DataTreating::distribute($raw_data['data']);
|
DataTreating::distribute($raw_data['data']);
|
||||||
break;
|
break;
|
||||||
case 'entered':
|
case 'entered':
|
||||||
|
|||||||
@ -122,14 +122,14 @@ class AnchorRaffle extends BaseRaffle
|
|||||||
'visit_id' => ''
|
'visit_id' => ''
|
||||||
];
|
];
|
||||||
array_push($tasks, [
|
array_push($tasks, [
|
||||||
'payload' => Sign::api($payload),
|
'payload' => Sign::common($payload),
|
||||||
'source' => [
|
'source' => [
|
||||||
'room_id' => $raffle['room_id'],
|
'room_id' => $raffle['room_id'],
|
||||||
'raffle_id' => $raffle['raffle_id']
|
'raffle_id' => $raffle['raffle_id']
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
$results = Curl::asyncPost($url, $tasks);
|
$results = Curl::async('app', $url, $tasks);
|
||||||
# print_r($results);
|
# print_r($results);
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,11 +48,11 @@ class AwardRecord
|
|||||||
*/
|
*/
|
||||||
private static function anchorAward()
|
private static function anchorAward()
|
||||||
{
|
{
|
||||||
|
$url = 'https://api.live.bilibili.com/xlive/lottery-interface/v1/Anchor/AwardRecord';
|
||||||
$payload = [
|
$payload = [
|
||||||
'page' => '1',
|
'page' => '1',
|
||||||
];
|
];
|
||||||
$url = 'https://api.live.bilibili.com/xlive/lottery-interface/v1/Anchor/AwardRecord';
|
$raw = Curl::get('app', $url, Sign::common($payload));
|
||||||
$raw = Curl::get($url, Sign::api($payload));
|
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
// 防止异常
|
// 防止异常
|
||||||
if (!isset($de_raw['data']) || !isset($de_raw['data']['list'])) {
|
if (!isset($de_raw['data']) || !isset($de_raw['data']['list'])) {
|
||||||
@ -84,12 +84,12 @@ class AwardRecord
|
|||||||
*/
|
*/
|
||||||
private static function raffleAward()
|
private static function raffleAward()
|
||||||
{
|
{
|
||||||
|
$url = 'https://api.live.bilibili.com/lottery/v1/award/award_list';
|
||||||
$payload = [
|
$payload = [
|
||||||
'page' => '1',
|
'page' => '1',
|
||||||
'month' => '',
|
'month' => '',
|
||||||
];
|
];
|
||||||
$url = 'https://api.live.bilibili.com/lottery/v1/award/award_list';
|
$raw = Curl::get('app', $url, Sign::common($payload));
|
||||||
$raw = Curl::get($url, Sign::api($payload));
|
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
|
|
||||||
// 防止异常
|
// 防止异常
|
||||||
@ -122,14 +122,14 @@ class AwardRecord
|
|||||||
*/
|
*/
|
||||||
private static function giftAward()
|
private static function giftAward()
|
||||||
{
|
{
|
||||||
|
// Web V3 Notice
|
||||||
|
$url = 'https://api.live.bilibili.com/xlive/lottery-interface/v3/smalltv/Notice';
|
||||||
$payload = [
|
$payload = [
|
||||||
'type' => 'type',
|
'type' => 'type',
|
||||||
'raffleId' => 'raffle_id'
|
'raffleId' => 'raffle_id'
|
||||||
];
|
];
|
||||||
// Web V3 Notice
|
|
||||||
$url = 'https://api.live.bilibili.com/xlive/lottery-interface/v3/smalltv/Notice';
|
|
||||||
// 请求 && 解码
|
// 请求 && 解码
|
||||||
$raw = Curl::get($url, Sign::api($payload));
|
$raw = Curl::get('app', $url, Sign::common($payload));
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ class Barrage
|
|||||||
shuffle($apis);
|
shuffle($apis);
|
||||||
try {
|
try {
|
||||||
foreach ($apis as $url) {
|
foreach ($apis as $url) {
|
||||||
$data = Curl::singleRequest('get', $url);
|
$data = Curl::request('get', $url);
|
||||||
if (is_null($data)) continue;
|
if (is_null($data)) continue;
|
||||||
foreach ($punctuations as $punctuation) {
|
foreach ($punctuations as $punctuation) {
|
||||||
if (strpos($data, $punctuation)) {
|
if (strpos($data, $punctuation)) {
|
||||||
@ -96,21 +96,19 @@ class Barrage
|
|||||||
private static function sendMsg($info)
|
private static function sendMsg($info)
|
||||||
{
|
{
|
||||||
$user_info = User::parseCookies();
|
$user_info = User::parseCookies();
|
||||||
$raw = Curl::get('https://api.live.bilibili.com/room/v1/Room/room_init?id=' . $info['roomid']);
|
$url = 'https://api.live.bilibili.com/msg/send';
|
||||||
$de_raw = json_decode($raw, true);
|
$data = Live::getRoomInfo($info['roomid']);
|
||||||
|
|
||||||
$payload = [
|
$payload = [
|
||||||
'color' => '16777215',
|
'color' => '16777215',
|
||||||
'fontsize' => 25,
|
'fontsize' => 25,
|
||||||
'mode' => 1,
|
'mode' => 1,
|
||||||
'msg' => $info['content'],
|
'msg' => $info['content'],
|
||||||
'rnd' => 0,
|
'rnd' => 0,
|
||||||
'roomid' => $de_raw['data']['room_id'],
|
'roomid' => $data['data']['room_id'],
|
||||||
'csrf' => $user_info['token'],
|
'csrf' => $user_info['token'],
|
||||||
'csrf_token' => $user_info['token'],
|
'csrf_token' => $user_info['token'],
|
||||||
];
|
];
|
||||||
|
return Curl::post('app', $url, Sign::common($payload));
|
||||||
return Curl::post('https://api.live.bilibili.com/msg/send', Sign::api($payload));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -12,9 +12,7 @@
|
|||||||
namespace BiliHelper\Plugin;
|
namespace BiliHelper\Plugin;
|
||||||
|
|
||||||
use BiliHelper\Core\Log;
|
use BiliHelper\Core\Log;
|
||||||
use BiliHelper\Core\Curl;
|
use BiliHelper\Core\Curl;abstract class BaseRaffle
|
||||||
|
|
||||||
abstract class BaseRaffle
|
|
||||||
{
|
{
|
||||||
const ACTIVE_TITLE = '';
|
const ACTIVE_TITLE = '';
|
||||||
const ACTIVE_SWITCH = '';
|
const ACTIVE_SWITCH = '';
|
||||||
@ -82,11 +80,11 @@ abstract class BaseRaffle
|
|||||||
*/
|
*/
|
||||||
protected static function check(int $room_id): array
|
protected static function check(int $room_id): array
|
||||||
{
|
{
|
||||||
|
$url = 'https://api.live.bilibili.com/xlive/lottery-interface/v1/lottery/getLotteryInfo';
|
||||||
$payload = [
|
$payload = [
|
||||||
'roomid' => $room_id
|
'roomid' => $room_id
|
||||||
];
|
];
|
||||||
$url = 'https://api.live.bilibili.com/xlive/lottery-interface/v1/lottery/getLotteryInfo';
|
$raw = Curl::get('app', $url, Sign::common($payload));
|
||||||
$raw = Curl::get($url, Sign::api($payload));
|
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
if (!isset($de_raw['data']) || $de_raw['code']) {
|
if (!isset($de_raw['data']) || $de_raw['code']) {
|
||||||
Log::error("获取抽奖数据错误,{$de_raw['message']}");
|
Log::error("获取抽奖数据错误,{$de_raw['message']}");
|
||||||
|
|||||||
@ -24,7 +24,7 @@ class Daily
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self::dailyBag();
|
self::dailyBag();
|
||||||
self::setLock( 8 * 60 * 60);
|
self::setLock(8 * 60 * 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,8 +32,9 @@ class Daily
|
|||||||
*/
|
*/
|
||||||
private static function dailyBag()
|
private static function dailyBag()
|
||||||
{
|
{
|
||||||
|
$url = 'https://api.live.bilibili.com/gift/v2/live/receive_daily_bag';
|
||||||
$payload = [];
|
$payload = [];
|
||||||
$data = Curl::get('https://api.live.bilibili.com/gift/v2/live/receive_daily_bag', Sign::api($payload));
|
$data = Curl::get('app', $url, Sign::common($payload));
|
||||||
$data = json_decode($data, true);
|
$data = json_decode($data, true);
|
||||||
|
|
||||||
if (isset($data['code']) && $data['code']) {
|
if (isset($data['code']) && $data['code']) {
|
||||||
|
|||||||
@ -34,13 +34,15 @@ class GiftHeart
|
|||||||
/**
|
/**
|
||||||
* @use 礼物心跳
|
* @use 礼物心跳
|
||||||
* @return bool
|
* @return bool
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private static function giftHeart(): bool
|
private static function giftHeart(): bool
|
||||||
{
|
{
|
||||||
|
$url = 'https://api.live.bilibili.com/gift/v2/live/heart_gift_receive';
|
||||||
$payload = [
|
$payload = [
|
||||||
'roomid' => getenv('ROOM_ID'),
|
'roomid' => getenv('ROOM_ID'),
|
||||||
];
|
];
|
||||||
$raw = Curl::get('https://api.live.bilibili.com/gift/v2/live/heart_gift_receive', Sign::api($payload));
|
$raw = Curl::get('app', $url, Sign::common($payload));
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
|
|
||||||
if ($de_raw['code'] == -403) {
|
if ($de_raw['code'] == -403) {
|
||||||
@ -48,7 +50,8 @@ class GiftHeart
|
|||||||
$payload = [
|
$payload = [
|
||||||
'ruid' => 17561885,
|
'ruid' => 17561885,
|
||||||
];
|
];
|
||||||
Curl::get('https://api.live.bilibili.com/eventRoom/index', Sign::api($payload));
|
$url = 'https://api.live.bilibili.com/eventRoom/index';
|
||||||
|
Curl::get('app', $url, Sign::common($payload));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -88,14 +88,14 @@ class GiftRaffle extends BaseRaffle
|
|||||||
'visit_id' => ''
|
'visit_id' => ''
|
||||||
];
|
];
|
||||||
array_push($tasks, [
|
array_push($tasks, [
|
||||||
'payload' => Sign::api($payload),
|
'payload' => Sign::common($payload),
|
||||||
'source' => [
|
'source' => [
|
||||||
'room_id' => $raffle['room_id'],
|
'room_id' => $raffle['room_id'],
|
||||||
'raffle_id' => $raffle['raffle_id']
|
'raffle_id' => $raffle['raffle_id']
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
$results = Curl::asyncPost($url, $tasks);
|
$results = Curl::async('app', $url, $tasks);
|
||||||
# print_r($results);
|
# print_r($results);
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,8 +10,9 @@
|
|||||||
|
|
||||||
namespace BiliHelper\Plugin;
|
namespace BiliHelper\Plugin;
|
||||||
|
|
||||||
use BiliHelper\Core\Curl;
|
|
||||||
use BiliHelper\Core\Log;
|
use BiliHelper\Core\Log;
|
||||||
|
use BiliHelper\Core\Curl;
|
||||||
use BiliHelper\Util\TimeLock;
|
use BiliHelper\Util\TimeLock;
|
||||||
|
|
||||||
class GiftSend
|
class GiftSend
|
||||||
@ -124,7 +125,8 @@ class GiftSend
|
|||||||
{
|
{
|
||||||
$new_bag_list = [];
|
$new_bag_list = [];
|
||||||
$payload = [];
|
$payload = [];
|
||||||
$data = Curl::get('https://api.live.bilibili.com/gift/v2/gift/bag_list', Sign::api($payload));
|
$url = 'https://api.live.bilibili.com/gift/v2/gift/bag_list';
|
||||||
|
$data = Curl::get('app', $url, Sign::common($payload));
|
||||||
$data = json_decode($data, true);
|
$data = json_decode($data, true);
|
||||||
if (isset($data['code']) && $data['code']) {
|
if (isset($data['code']) && $data['code']) {
|
||||||
Log::warning('背包查看失败!', ['msg' => $data['message']]);
|
Log::warning('背包查看失败!', ['msg' => $data['message']]);
|
||||||
@ -170,9 +172,12 @@ class GiftSend
|
|||||||
protected static function getMedalList()
|
protected static function getMedalList()
|
||||||
{
|
{
|
||||||
self::$medal_list = [];
|
self::$medal_list = [];
|
||||||
Log::info('正在获取勋章列表...');
|
$url = 'https://api.live.bilibili.com/i/api/medal';
|
||||||
$payload = [];
|
$payload = [
|
||||||
$data = Curl::get('https://api.live.bilibili.com/i/api/medal?page=1&pageSize=25', Sign::api($payload));
|
'page' => 1,
|
||||||
|
'pageSize' => 25
|
||||||
|
];
|
||||||
|
$data = Curl::get('app', $url, Sign::common($payload));
|
||||||
$data = json_decode($data, true);
|
$data = json_decode($data, true);
|
||||||
if (isset($data['code']) && $data['code']) {
|
if (isset($data['code']) && $data['code']) {
|
||||||
Log::warning('获取勋章列表失败!', ['msg' => $data['message']]);
|
Log::warning('获取勋章列表失败!', ['msg' => $data['message']]);
|
||||||
@ -198,8 +203,9 @@ class GiftSend
|
|||||||
*/
|
*/
|
||||||
protected static function getUserInfo()
|
protected static function getUserInfo()
|
||||||
{
|
{
|
||||||
|
$url = 'https://api.live.bilibili.com/xlive/web-ucenter/user/get_user_info';
|
||||||
$payload = [];
|
$payload = [];
|
||||||
$data = Curl::get('https://api.live.bilibili.com/xlive/web-ucenter/user/get_user_info', Sign::api($payload));
|
$data = Curl::get('app', $url, Sign::common($payload));
|
||||||
$data = json_decode($data, true);
|
$data = json_decode($data, true);
|
||||||
if (isset($data['code']) && $data['code']) {
|
if (isset($data['code']) && $data['code']) {
|
||||||
Log::warning('获取帐号信息失败!', ['msg' => $data['message']]);
|
Log::warning('获取帐号信息失败!', ['msg' => $data['message']]);
|
||||||
@ -216,11 +222,8 @@ class GiftSend
|
|||||||
protected static function getRoomInfo()
|
protected static function getRoomInfo()
|
||||||
{
|
{
|
||||||
Log::info('正在生成直播间信息...');
|
Log::info('正在生成直播间信息...');
|
||||||
$payload = [
|
$room_id = empty(self::$tid) ? getenv('ROOM_ID') : self::$tid;
|
||||||
'id' => empty(self::$tid) ? getenv('ROOM_ID') : self::$tid,
|
$data = Live::getRoomInfo($room_id);
|
||||||
];
|
|
||||||
$data = Curl::get('https://api.live.bilibili.com/room/v1/Room/room_init', Sign::api($payload));
|
|
||||||
$data = json_decode($data, true);
|
|
||||||
if (isset($data['code']) && $data['code']) {
|
if (isset($data['code']) && $data['code']) {
|
||||||
Log::warning('获取主播房间号失败!', ['msg' => $data['message']]);
|
Log::warning('获取主播房间号失败!', ['msg' => $data['message']]);
|
||||||
Log::warning('清空礼物功能禁用!');
|
Log::warning('清空礼物功能禁用!');
|
||||||
@ -260,6 +263,7 @@ class GiftSend
|
|||||||
*/
|
*/
|
||||||
protected static function sendGift(array $value, int $amt)
|
protected static function sendGift(array $value, int $amt)
|
||||||
{
|
{
|
||||||
|
$url = 'https://api.live.bilibili.com/gift/v2/live/bag_send';
|
||||||
$payload = [
|
$payload = [
|
||||||
'coin_type' => 'silver',
|
'coin_type' => 'silver',
|
||||||
'gift_id' => $value['gift_id'],
|
'gift_id' => $value['gift_id'],
|
||||||
@ -271,7 +275,7 @@ class GiftSend
|
|||||||
'data_behavior_id' => '',
|
'data_behavior_id' => '',
|
||||||
'bag_id' => $value['bag_id']
|
'bag_id' => $value['bag_id']
|
||||||
];
|
];
|
||||||
$data = Curl::post('https://api.live.bilibili.com/gift/v2/live/bag_send', Sign::api($payload));
|
$data = Curl::post('app', $url, Sign::common($payload));
|
||||||
$data = json_decode($data, true);
|
$data = json_decode($data, true);
|
||||||
if (isset($data['code']) && $data['code']) {
|
if (isset($data['code']) && $data['code']) {
|
||||||
Log::warning('送礼失败!', ['msg' => $data['message']]);
|
Log::warning('送礼失败!', ['msg' => $data['message']]);
|
||||||
|
|||||||
@ -44,8 +44,9 @@ class GroupSignIn
|
|||||||
*/
|
*/
|
||||||
protected static function getGroupList(): array
|
protected static function getGroupList(): array
|
||||||
{
|
{
|
||||||
|
$url = 'https://api.vc.bilibili.com/link_group/v1/member/my_groups';
|
||||||
$payload = [];
|
$payload = [];
|
||||||
$raw = Curl::get('https://api.vc.bilibili.com/link_group/v1/member/my_groups', Sign::api($payload));
|
$raw = Curl::get('app', $url, Sign::common($payload));
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
|
|
||||||
if (empty($de_raw['data']['list'])) {
|
if (empty($de_raw['data']['list'])) {
|
||||||
@ -63,11 +64,12 @@ class GroupSignIn
|
|||||||
*/
|
*/
|
||||||
protected static function signInGroup(array $groupInfo): bool
|
protected static function signInGroup(array $groupInfo): bool
|
||||||
{
|
{
|
||||||
|
$url = 'https://api.vc.bilibili.com/link_setting/v1/link_setting/sign_in';
|
||||||
$payload = [
|
$payload = [
|
||||||
'group_id' => $groupInfo['group_id'],
|
'group_id' => $groupInfo['group_id'],
|
||||||
'owner_id' => $groupInfo['owner_uid'],
|
'owner_id' => $groupInfo['owner_uid'],
|
||||||
];
|
];
|
||||||
$raw = Curl::get('https://api.vc.bilibili.com/link_setting/v1/link_setting/sign_in', Sign::api($payload));
|
$raw = Curl::get('app', $url, Sign::common($payload));
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
|
|
||||||
if ($de_raw['code'] != '0') {
|
if ($de_raw['code'] != '0') {
|
||||||
|
|||||||
@ -103,14 +103,14 @@ class GuardRaffle extends BaseRaffle
|
|||||||
'visit_id' => ''
|
'visit_id' => ''
|
||||||
];
|
];
|
||||||
array_push($tasks, [
|
array_push($tasks, [
|
||||||
'payload' => Sign::api($payload),
|
'payload' => Sign::common($payload),
|
||||||
'source' => [
|
'source' => [
|
||||||
'room_id' => $raffle['room_id'],
|
'room_id' => $raffle['room_id'],
|
||||||
'raffle_id' => $raffle['raffle_id']
|
'raffle_id' => $raffle['raffle_id']
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
$results = Curl::asyncPost($url, $tasks);
|
$results = Curl::async('app', $url, $tasks);
|
||||||
# print_r($results);
|
# print_r($results);
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,10 +34,11 @@ class Heart
|
|||||||
protected static function webHeart()
|
protected static function webHeart()
|
||||||
{
|
{
|
||||||
User::webGetUserInfo();
|
User::webGetUserInfo();
|
||||||
|
$url = 'https://api.live.bilibili.com/relation/v1/Feed/heartBeat';
|
||||||
$payload = [
|
$payload = [
|
||||||
'room_id' => getenv('ROOM_ID'),
|
'room_id' => getenv('ROOM_ID'),
|
||||||
];
|
];
|
||||||
$data = Curl::post('https://api.live.bilibili.com/relation/v1/Feed/heartBeat', Sign::api($payload));
|
$data = Curl::post('app', $url, Sign::common($payload));
|
||||||
$data = json_decode($data, true);
|
$data = json_decode($data, true);
|
||||||
|
|
||||||
if (isset($data['code']) && $data['code']) {
|
if (isset($data['code']) && $data['code']) {
|
||||||
@ -53,10 +54,11 @@ class Heart
|
|||||||
protected static function appHeart()
|
protected static function appHeart()
|
||||||
{
|
{
|
||||||
User::appGetUserInfo();
|
User::appGetUserInfo();
|
||||||
|
$url = 'https://api.live.bilibili.com/mobile/userOnlineHeart';
|
||||||
$payload = [
|
$payload = [
|
||||||
'room_id' => getenv('ROOM_ID'),
|
'room_id' => getenv('ROOM_ID'),
|
||||||
];
|
];
|
||||||
$data = Curl::post('https://api.live.bilibili.com/mobile/userOnlineHeart', Sign::api($payload));
|
$data = Curl::post('app', $url, Sign::common($payload));
|
||||||
$data = json_decode($data, true);
|
$data = json_decode($data, true);
|
||||||
|
|
||||||
if (isset($data['code']) && $data['code']) {
|
if (isset($data['code']) && $data['code']) {
|
||||||
|
|||||||
300
src/plugin/Judge.php
Normal file
300
src/plugin/Judge.php
Normal file
@ -0,0 +1,300 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Website: https://mudew.com/
|
||||||
|
* Author: Lkeme
|
||||||
|
* License: The MIT License
|
||||||
|
* Email: Useri@live.cn
|
||||||
|
* Updated: 2020 ~ 2021
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BiliHelper\Plugin;
|
||||||
|
|
||||||
|
use BiliHelper\Core\Log;
|
||||||
|
use BiliHelper\Core\Curl;
|
||||||
|
use BiliHelper\Util\TimeLock;
|
||||||
|
|
||||||
|
class Judge
|
||||||
|
{
|
||||||
|
use TimeLock;
|
||||||
|
|
||||||
|
private static $retry_time = 0;
|
||||||
|
private static $wait_case_id = 0;
|
||||||
|
private static $wait_time = 0;
|
||||||
|
private static $min_ok_pct = 1;
|
||||||
|
private static $max_ok_pct = 0;
|
||||||
|
|
||||||
|
public static function run()
|
||||||
|
{
|
||||||
|
if (self::getLock() > time() || self::$retry_time > time() || getenv('USE_JUDGE') == 'false') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
# https://www.bilibili.com/judgement/index
|
||||||
|
$case_id = self::$wait_case_id ? self::$wait_case_id : self::caseObtain();
|
||||||
|
if (!self::judgeCase($case_id)) {
|
||||||
|
self::setLock(1 * 60 + 5);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// self::judgementIndex();
|
||||||
|
self::setLock(mt_rand(6, 10) * 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 判案
|
||||||
|
* @param $case_id
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private static function judgeCase($case_id)
|
||||||
|
{
|
||||||
|
if (is_null($case_id) || $case_id == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Log::info("尝试判定案件 {$case_id}");
|
||||||
|
$data = self::judgementVote($case_id);
|
||||||
|
$num_judged = $data['num_voted'];
|
||||||
|
$ok_pct = $data['ok_percent'];
|
||||||
|
$advice = self::judgeAdvice($num_judged, $ok_pct);
|
||||||
|
if ($num_judged >= 50) {
|
||||||
|
|
||||||
|
self::$min_ok_pct = min(self::$min_ok_pct, $ok_pct);
|
||||||
|
self::$max_ok_pct = max(self::$max_ok_pct, $ok_pct);
|
||||||
|
// user.info('更新统计投票波动情况')
|
||||||
|
}
|
||||||
|
// Log::info("案件 {$case_id} 已经等待" . self::$wait_time . "s,统计波动区间为" . self::$min_ok_pct . "-" . self::$max_ok_pct);
|
||||||
|
if (is_null($advice)) {
|
||||||
|
if (self::$wait_time >= 1200) {
|
||||||
|
// 如果case判定中,波动很小,则表示趋势基本一致
|
||||||
|
if ((self::$max_ok_pct - self::$min_ok_pct) >= 0 && (self::$max_ok_pct - self::$min_ok_pct) <= 0.1 && $num_judged > 200) {
|
||||||
|
$num_judged += 100;
|
||||||
|
$advice0 = self::judgeAdvice($num_judged, self::$max_ok_pct);
|
||||||
|
$advice1 = self::judgeAdvice($num_judged, self::$min_ok_pct);
|
||||||
|
$advice = ($advice0 == $advice1) ? $advice0 : null;
|
||||||
|
}
|
||||||
|
Log::info("判定结果 {$advice}");
|
||||||
|
} else {
|
||||||
|
$sleep_wait_time = ($num_judged < 300) ? 200 : 60;
|
||||||
|
Log::info("案件 {$case_id} 暂无法判定,{$sleep_wait_time}S 后重新尝试");
|
||||||
|
self::$wait_time += $sleep_wait_time;
|
||||||
|
self::$retry_time = $sleep_wait_time + time();
|
||||||
|
self::$wait_case_id = $case_id;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 如果还不行就放弃
|
||||||
|
$decision = !is_null($advice) ? $advice : 3;
|
||||||
|
$dicision_info = ($decision == 3) ? '作废票' : '有效票';
|
||||||
|
Log::info("案件 {$case_id} 的投票结果:{$dicision_info}({$decision})");
|
||||||
|
self::juryVote($case_id, $decision);
|
||||||
|
self::initParams();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 投票建议
|
||||||
|
* @param $num_judged
|
||||||
|
* @param $pct
|
||||||
|
* @return int|null
|
||||||
|
*/
|
||||||
|
private static function judgeAdvice($num_judged, $pct)
|
||||||
|
{
|
||||||
|
if ($num_judged >= 300) {
|
||||||
|
# 认为这里可能出现了较多分歧,抬一手
|
||||||
|
if ($pct >= 0.4) {
|
||||||
|
return 2;
|
||||||
|
} elseif ($pct <= 0.25) {
|
||||||
|
return 4;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} elseif ($num_judged >= 150) {
|
||||||
|
if ($pct >= 0.9) {
|
||||||
|
return 2;
|
||||||
|
} elseif ($pct <= 0.1) {
|
||||||
|
return 4;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} elseif ($num_judged >= 50) {
|
||||||
|
if ($pct >= 0.97) {
|
||||||
|
return 2;
|
||||||
|
} elseif ($pct <= 0.03) {
|
||||||
|
return 4;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# 抬一手
|
||||||
|
if ($num_judged >= 400) {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 投票
|
||||||
|
* @param $case_id
|
||||||
|
* @param $decision
|
||||||
|
*/
|
||||||
|
private static function juryVote($case_id, $decision)
|
||||||
|
{
|
||||||
|
$user_info = User::parseCookies();
|
||||||
|
$url = 'http://api.bilibili.com/x/credit/jury/vote';
|
||||||
|
$payload = [
|
||||||
|
"jsonp" => "jsonp",
|
||||||
|
"cid" => $case_id,
|
||||||
|
"vote" => $decision,
|
||||||
|
"content" => "",
|
||||||
|
"likes" => "",
|
||||||
|
"hates" => "",
|
||||||
|
"attr" => "1",
|
||||||
|
"csrf" => $user_info['token'],
|
||||||
|
];
|
||||||
|
$raw = Curl::post('pc', $url, $payload);
|
||||||
|
$de_raw = json_decode($raw, true);
|
||||||
|
if (isset($de_raw['code']) && $de_raw['code']) {
|
||||||
|
Log::warning("案件 {$case_id} 投票失败 {$raw}");
|
||||||
|
} else {
|
||||||
|
Log::notice("案件 {$case_id} 投票成功 {$raw}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 案件获取
|
||||||
|
* @return |null
|
||||||
|
*/
|
||||||
|
private static function caseObtain()
|
||||||
|
{
|
||||||
|
$user_info = User::parseCookies();
|
||||||
|
$url = 'http://api.bilibili.com/x/credit/jury/caseObtain';
|
||||||
|
$payload = [
|
||||||
|
"jsonp" => "jsonp",
|
||||||
|
"csrf" => $user_info['token']
|
||||||
|
];
|
||||||
|
$raw = Curl::post('pc', $url, $payload);
|
||||||
|
$de_raw = json_decode($raw, true);
|
||||||
|
if (isset($de_raw['code']) && $de_raw['code'] == 25005) {
|
||||||
|
// {"code":25005,"message":"请成为风纪委员后再试","ttl":1}
|
||||||
|
Log::warning($de_raw['message']);
|
||||||
|
self::setLock(24 * 60 * 60);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (isset($de_raw['code']) && $de_raw['code']) {
|
||||||
|
Log::info("没有获取到案件~ {$raw}");
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
$case_id = $de_raw['data']['id'];
|
||||||
|
Log::info("获取到案件 {$case_id} ~");
|
||||||
|
return $case_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 判断投票
|
||||||
|
* @param $case_id
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private static function judgementVote($case_id)
|
||||||
|
{
|
||||||
|
$url = 'https://api.bilibili.com/x/credit/jury/juryCase';
|
||||||
|
$headers = [
|
||||||
|
'Referer' => "https://www.bilibili.com/judgement/vote/{$case_id}"
|
||||||
|
];
|
||||||
|
$payload = [
|
||||||
|
'callback' => "jQuery1720" . self::randInt() . "_" . time(),
|
||||||
|
'cid' => $case_id,
|
||||||
|
'_' => time()
|
||||||
|
];
|
||||||
|
$raw = Curl::get('pc', $url, $payload, $headers);
|
||||||
|
$de_raw = json_decode($raw, true);
|
||||||
|
$data = $de_raw['data'];
|
||||||
|
# 3 放弃
|
||||||
|
# 2 否 vote_rule
|
||||||
|
# 4 删除 vote_delete
|
||||||
|
# 1 封杀 vote_break
|
||||||
|
$vote_break = $data['voteBreak'];
|
||||||
|
$vote_delete = $data['voteDelete'];
|
||||||
|
$vote_rule = $data['voteRule'];
|
||||||
|
$num_voted = $vote_break + $vote_delete + $vote_rule;
|
||||||
|
$ok_percent = $num_voted ? ($vote_rule / $num_voted) : 0;
|
||||||
|
// 言论合理比例 {$ok_percent}
|
||||||
|
Log::info("案件 {$case_id} 目前已投票 {$num_voted}");
|
||||||
|
return [
|
||||||
|
'num_voted' => $num_voted,
|
||||||
|
'ok_percent' => $ok_percent
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 获取案例数据|风纪检测
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private static function judgementIndex()
|
||||||
|
{
|
||||||
|
$url = 'https://api.bilibili.com/x/credit/jury/caseList';
|
||||||
|
$headers = [
|
||||||
|
'Referer' => "https://www.bilibili.com/judgement/index"
|
||||||
|
];
|
||||||
|
$payload = [
|
||||||
|
'callback' => "jQuery1720" . self::randInt() . "_" . time(),
|
||||||
|
'pn' => 1,
|
||||||
|
'ps' => 25,
|
||||||
|
'_' => time()
|
||||||
|
];
|
||||||
|
$raw = Curl::get('pc', $url, $payload, $headers);
|
||||||
|
$de_raw = json_decode($raw, true);
|
||||||
|
print_r($de_raw);
|
||||||
|
$data = $de_raw['data'];
|
||||||
|
if (!$data) {
|
||||||
|
Log::info('该用户非风纪委成员');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$today = date("Y-m-d");
|
||||||
|
$sum_cases = 0;
|
||||||
|
$valid_cases = 0;
|
||||||
|
$judging_cases = 0;
|
||||||
|
foreach ($data as $case) {
|
||||||
|
$ts = $case['voteTime'] / 1000;
|
||||||
|
$vote_day = date("Y-m-d", $ts);
|
||||||
|
if ($vote_day == $today) {
|
||||||
|
$sum_cases += 1;
|
||||||
|
$vote = $case['vote'];
|
||||||
|
if ($vote) {
|
||||||
|
$valid_cases += 1;
|
||||||
|
} else {
|
||||||
|
$judging_cases += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log::info("今日投票{$sum_cases}({$valid_cases}票有效(非弃权),{$judging_cases}票还在进行中)");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 随机整数
|
||||||
|
* @param int $max
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private static function randInt(int $max = 17): string
|
||||||
|
{
|
||||||
|
$temp = [];
|
||||||
|
foreach (range(1, $max) as $index) {
|
||||||
|
array_push($temp, mt_rand(0, 9));
|
||||||
|
}
|
||||||
|
return implode("", $temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 初始化参数
|
||||||
|
*/
|
||||||
|
private static function initParams()
|
||||||
|
{
|
||||||
|
self::$retry_time = 0;
|
||||||
|
self::$wait_case_id = 0;
|
||||||
|
self::$wait_time = 0;
|
||||||
|
self::$min_ok_pct = 1;
|
||||||
|
self::$max_ok_pct = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -27,7 +27,8 @@ class Live
|
|||||||
{
|
{
|
||||||
$areas = [];
|
$areas = [];
|
||||||
$url = "http://api.live.bilibili.com/room/v1/Area/getList";
|
$url = "http://api.live.bilibili.com/room/v1/Area/getList";
|
||||||
$raw = Curl::get($url);
|
$payload = [];
|
||||||
|
$raw = Curl::get('other', $url, $payload);
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
// 防止异常
|
// 防止异常
|
||||||
if (!isset($de_raw['data']) || $de_raw['code']) {
|
if (!isset($de_raw['data']) || $de_raw['code']) {
|
||||||
@ -50,8 +51,17 @@ class Live
|
|||||||
*/
|
*/
|
||||||
public static function areaToRid($area_id): array
|
public static function areaToRid($area_id): array
|
||||||
{
|
{
|
||||||
$url = "https://api.live.bilibili.com/room/v1/area/getRoomList?platform=web&parent_area_id={$area_id}&cate_id=0&area_id=0&sort_type=online&page=1&page_size=30";
|
$url = "https://api.live.bilibili.com/room/v1/area/getRoomList";
|
||||||
$raw = Curl::get($url);
|
$payload = [
|
||||||
|
'platform' => 'web',
|
||||||
|
'parent_area_id' => $area_id,
|
||||||
|
'cate_id' => 0,
|
||||||
|
'area_id' => 0,
|
||||||
|
'sort_type' => 'online',
|
||||||
|
'page' => 1,
|
||||||
|
'page_size' => 30
|
||||||
|
];
|
||||||
|
$raw = Curl::get('other', $url, $payload);
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
// 防止异常
|
// 防止异常
|
||||||
if (!isset($de_raw['data']) || $de_raw['code']) {
|
if (!isset($de_raw['data']) || $de_raw['code']) {
|
||||||
@ -77,7 +87,14 @@ class Live
|
|||||||
*/
|
*/
|
||||||
public static function getUserRecommend()
|
public static function getUserRecommend()
|
||||||
{
|
{
|
||||||
$raw = Curl::get('https://api.live.bilibili.com/room/v1/Area/getListByAreaID?areaId=0&sort=online&pageSize=30&page=1');
|
$url = 'https://api.live.bilibili.com/room/v1/Area/getListByAreaID';
|
||||||
|
$payload = [
|
||||||
|
'areaId' => 0,
|
||||||
|
'sort' => 'online',
|
||||||
|
'pageSize' => 30,
|
||||||
|
'page' => 1
|
||||||
|
];
|
||||||
|
$raw = Curl::get('other', $url, $payload);
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
if ($de_raw['code'] != '0') {
|
if ($de_raw['code'] != '0') {
|
||||||
return 23058;
|
return 23058;
|
||||||
@ -94,23 +111,36 @@ class Live
|
|||||||
*/
|
*/
|
||||||
public static function getRealRoomID($room_id)
|
public static function getRealRoomID($room_id)
|
||||||
{
|
{
|
||||||
$raw = Curl::get('https://api.live.bilibili.com/room/v1/Room/room_init?id=' . $room_id);
|
$data = self::getRoomInfo($room_id);
|
||||||
$de_raw = json_decode($raw, true);
|
if ($data['code']) {
|
||||||
if ($de_raw['code']) {
|
Log::warning($room_id . ' : ' . $data['msg']);
|
||||||
Log::warning($room_id . ' : ' . $de_raw['msg']);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($de_raw['data']['is_hidden']) {
|
if ($data['data']['is_hidden']) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($de_raw['data']['is_locked']) {
|
if ($data['data']['is_locked']) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($de_raw['data']['encrypted']) {
|
if ($data['data']['encrypted']) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return $de_raw['data']['room_id'];
|
return $data['data']['room_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 获取直播间信息
|
||||||
|
* @param $room_id
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getRoomInfo($room_id): array
|
||||||
|
{
|
||||||
|
$url = 'https://api.live.bilibili.com/room/v1/Room/room_init';
|
||||||
|
$payload = [
|
||||||
|
'id' => $room_id
|
||||||
|
];
|
||||||
|
$raw = Curl::get('other', $url, $payload);
|
||||||
|
return json_decode($raw, true);;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -118,6 +148,7 @@ class Live
|
|||||||
* @use 钓鱼检测
|
* @use 钓鱼检测
|
||||||
* @param $room_id
|
* @param $room_id
|
||||||
* @return bool
|
* @return bool
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function fishingDetection($room_id): bool
|
public static function fishingDetection($room_id): bool
|
||||||
{
|
{
|
||||||
@ -136,11 +167,12 @@ class Live
|
|||||||
*/
|
*/
|
||||||
public static function goToRoom($room_id): bool
|
public static function goToRoom($room_id): bool
|
||||||
{
|
{
|
||||||
|
$url = 'https://api.live.bilibili.com/room/v1/Room/room_entry_action';
|
||||||
$payload = [
|
$payload = [
|
||||||
'room_id' => $room_id,
|
'room_id' => $room_id,
|
||||||
];
|
];
|
||||||
// Log::info('进入直播间[' . $room_id . ']抽奖!');
|
// Log::info('进入直播间[' . $room_id . ']抽奖!');
|
||||||
Curl::post('https://api.live.bilibili.com/room/v1/Room/room_entry_action', Sign::api($payload));
|
Curl::post('app', $url, Sign::common($payload));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,8 +11,8 @@ namespace BiliHelper\Plugin;
|
|||||||
|
|
||||||
use BiliHelper\Core\Log;
|
use BiliHelper\Core\Log;
|
||||||
use BiliHelper\Core\Curl;
|
use BiliHelper\Core\Curl;
|
||||||
use BiliHelper\Util\TimeLock;
|
|
||||||
use BiliHelper\Core\Config;
|
use BiliHelper\Core\Config;
|
||||||
|
use BiliHelper\Util\TimeLock;
|
||||||
|
|
||||||
|
|
||||||
class Login
|
class Login
|
||||||
@ -71,11 +71,11 @@ class Login
|
|||||||
*/
|
*/
|
||||||
protected static function info()
|
protected static function info()
|
||||||
{
|
{
|
||||||
$access_token = getenv('ACCESS_TOKEN');
|
$url = 'https://passport.bilibili.com/api/v2/oauth2/info';
|
||||||
$payload = [
|
$payload = [
|
||||||
'access_token' => $access_token,
|
'access_token' => getenv('ACCESS_TOKEN'),
|
||||||
];
|
];
|
||||||
$data = Curl::get('https://passport.bilibili.com/api/v2/oauth2/info', Sign::api($payload));
|
$data = Curl::get('app', $url, Sign::common($payload));
|
||||||
$data = json_decode($data, true);
|
$data = json_decode($data, true);
|
||||||
if (isset($data['code']) && $data['code']) {
|
if (isset($data['code']) && $data['code']) {
|
||||||
Log::error('检查令牌失败', ['msg' => $data['message']]);
|
Log::error('检查令牌失败', ['msg' => $data['message']]);
|
||||||
@ -91,13 +91,12 @@ class Login
|
|||||||
*/
|
*/
|
||||||
public static function refresh()
|
public static function refresh()
|
||||||
{
|
{
|
||||||
$access_token = getenv('ACCESS_TOKEN');
|
$url = 'https://passport.bilibili.com/api/oauth2/refreshToken';
|
||||||
$refresh_token = getenv('REFRESH_TOKEN');
|
|
||||||
$payload = [
|
$payload = [
|
||||||
'access_token' => $access_token,
|
'access_token' => getenv('ACCESS_TOKEN'),
|
||||||
'refresh_token' => $refresh_token,
|
'refresh_token' => getenv('REFRESH_TOKEN'),
|
||||||
];
|
];
|
||||||
$data = Curl::post('https://passport.bilibili.com/api/oauth2/refreshToken', Sign::api($payload));
|
$data = Curl::post('app', $url, Sign::common($payload));
|
||||||
$data = json_decode($data, true);
|
$data = json_decode($data, true);
|
||||||
if (isset($data['code']) && $data['code']) {
|
if (isset($data['code']) && $data['code']) {
|
||||||
Log::error('重新生成令牌失败', ['msg' => $data['message']]);
|
Log::error('重新生成令牌失败', ['msg' => $data['message']]);
|
||||||
@ -106,13 +105,18 @@ class Login
|
|||||||
Log::info('令牌生成完毕!');
|
Log::info('令牌生成完毕!');
|
||||||
$access_token = $data['data']['access_token'];
|
$access_token = $data['data']['access_token'];
|
||||||
Config::put('ACCESS_TOKEN', $access_token);
|
Config::put('ACCESS_TOKEN', $access_token);
|
||||||
Log::info(' > access token: ' . $access_token);
|
Log::info(" > access token: {$access_token}");
|
||||||
$refresh_token = $data['data']['refresh_token'];
|
$refresh_token = $data['data']['refresh_token'];
|
||||||
Config::put('REFRESH_TOKEN', $refresh_token);
|
Config::put('REFRESH_TOKEN', $refresh_token);
|
||||||
Log::info(' > refresh token: ' . $refresh_token);
|
Log::info(" > refresh token: {$refresh_token}");
|
||||||
|
if (!self::saveCookie()) {
|
||||||
|
self::clearAccount();
|
||||||
|
die();
|
||||||
|
};
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @use 普通登陆
|
* @use 普通登陆
|
||||||
* @param string $captcha
|
* @param string $captcha
|
||||||
@ -126,11 +130,12 @@ class Login
|
|||||||
Log::error('空白的帐号和口令!');
|
Log::error('空白的帐号和口令!');
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
self::clearAccount();
|
||||||
// get PublicKey
|
// get PublicKey
|
||||||
Log::info('正在载入安全模块...');
|
Log::info('正在载入安全模块...');
|
||||||
|
$url = 'https://passport.snm0516.aisee.tv/api/oauth2/getKey';
|
||||||
$payload = [];
|
$payload = [];
|
||||||
$data = Curl::post('https://passport.bilibili.com/api/oauth2/getKey', Sign::api($payload));
|
$data = Curl::post('app', $url, Sign::login($payload));
|
||||||
$data = json_decode($data, true);
|
$data = json_decode($data, true);
|
||||||
if (isset($data['code']) && $data['code']) {
|
if (isset($data['code']) && $data['code']) {
|
||||||
Log::error('公钥获取失败', ['msg' => $data['message']]);
|
Log::error('公钥获取失败', ['msg' => $data['message']]);
|
||||||
@ -144,14 +149,16 @@ class Login
|
|||||||
for ($i = 0; $i < 30; $i++) {
|
for ($i = 0; $i < 30; $i++) {
|
||||||
// login
|
// login
|
||||||
Log::info('正在获取令牌...');
|
Log::info('正在获取令牌...');
|
||||||
|
$url = 'https://passport.snm0516.aisee.tv/api/tv/login';
|
||||||
$payload = [
|
$payload = [
|
||||||
'subid' => 1,
|
'channel' => 'master',
|
||||||
'permission' => 'ALL',
|
'token' => '5598158bcd8511e2',
|
||||||
|
'guid' => 'XYEBAA3E54D502E37BD606F0589A356902FCF',
|
||||||
'username' => $user,
|
'username' => $user,
|
||||||
'password' => base64_encode($crypt),
|
'password' => base64_encode($crypt),
|
||||||
'captcha' => $captcha,
|
'captcha' => $captcha,
|
||||||
];
|
];
|
||||||
$data = Curl::post('https://passport.bilibili.com/api/v2/oauth2/login', Sign::api($payload), $headers);
|
$data = Curl::post('app', $url, Sign::login($payload), $headers);
|
||||||
$data = json_decode($data, true);
|
$data = json_decode($data, true);
|
||||||
if (isset($data['code']) && $data['code'] == -105) {
|
if (isset($data['code']) && $data['code'] == -105) {
|
||||||
$captcha_data = self::loginWithCaptcha();
|
$captcha_data = self::loginWithCaptcha();
|
||||||
@ -160,7 +167,7 @@ class Login
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// https://passport.bilibili.com/mobile/verifytel_h5.html
|
// https://passport.bilibili.com/mobile/verifytel_h5.html
|
||||||
if (!$data['code'] && $data['data']['status']) {
|
if ($data['code'] == -2100) {
|
||||||
Log::error('登录失败', ['msg' => '登录异常, 账号启用了设备锁或异地登录需验证手机!']);
|
Log::error('登录失败', ['msg' => '登录异常, 账号启用了设备锁或异地登录需验证手机!']);
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
@ -170,15 +177,17 @@ class Login
|
|||||||
Log::error('登录失败', ['msg' => $data['message']]);
|
Log::error('登录失败', ['msg' => $data['message']]);
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
self::saveCookie($data);
|
|
||||||
Log::info('令牌获取成功!');
|
Log::info('令牌获取成功!');
|
||||||
$access_token = $data['data']['token_info']['access_token'];
|
$access_token = $data['data']['token_info']['access_token'];
|
||||||
Config::put('ACCESS_TOKEN', $access_token);
|
Config::put('ACCESS_TOKEN', $access_token);
|
||||||
Log::info(' > access token: ' . $access_token);
|
Log::info(" > access token: {$access_token}");
|
||||||
$refresh_token = $data['data']['token_info']['refresh_token'];
|
$refresh_token = $data['data']['token_info']['refresh_token'];
|
||||||
Config::put('REFRESH_TOKEN', $refresh_token);
|
Config::put('REFRESH_TOKEN', $refresh_token);
|
||||||
Log::info(' > refresh token: ' . $refresh_token);
|
Log::info(" > refresh token: {$refresh_token}");
|
||||||
|
if (!self::saveCookie()) {
|
||||||
|
self::clearAccount();
|
||||||
|
die();
|
||||||
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,13 +199,16 @@ class Login
|
|||||||
protected static function loginWithCaptcha()
|
protected static function loginWithCaptcha()
|
||||||
{
|
{
|
||||||
Log::info('登录需要验证, 启动验证码登录!');
|
Log::info('登录需要验证, 启动验证码登录!');
|
||||||
|
$url = 'https://passport.snm0516.aisee.tv/api/captcha';
|
||||||
|
$payload = [
|
||||||
|
'token' => '5598158bcd8511e2'
|
||||||
|
];
|
||||||
$headers = [
|
$headers = [
|
||||||
'Accept' => 'application/json, text/plain, */*',
|
'Accept' => 'application/json, text/plain, */*',
|
||||||
'User-Agent' => 'bili-universal/8470 CFNetwork/978.0.7 Darwin/18.5.0',
|
'Host' => 'passport.snm0516.aisee.tv',
|
||||||
'Host' => 'passport.bilibili.com',
|
|
||||||
'Cookie' => 'sid=blhelper'
|
'Cookie' => 'sid=blhelper'
|
||||||
];
|
];
|
||||||
$data = Curl::request('https://passport.bilibili.com/captcha', null, $headers);
|
$data = Curl::get('other', $url, $payload, $headers);
|
||||||
$data = base64_encode($data);
|
$data = base64_encode($data);
|
||||||
$captcha = self::ocrCaptcha($data);
|
$captcha = self::ocrCaptcha($data);
|
||||||
return [
|
return [
|
||||||
@ -213,35 +225,66 @@ class Login
|
|||||||
*/
|
*/
|
||||||
private static function ocrCaptcha($captcha_img)
|
private static function ocrCaptcha($captcha_img)
|
||||||
{
|
{
|
||||||
|
$url = 'http://47.102.120.84:19951/';
|
||||||
$payload = [
|
$payload = [
|
||||||
'image' => (string)$captcha_img
|
'image' => (string)$captcha_img
|
||||||
];
|
];
|
||||||
$headers = [
|
$headers = [
|
||||||
'Content-Type' => 'application/json',
|
'Content-Type' => 'application/json',
|
||||||
];
|
];
|
||||||
$data = Curl::request('http://47.102.120.84:19951/', json_encode($payload), $headers);
|
$data = Curl::put('other', $url, $payload, $headers);
|
||||||
$de_raw = json_decode($data, true);
|
$de_raw = json_decode($data, true);
|
||||||
Log::info("验证码识别结果 {$de_raw['message']}");
|
Log::info("验证码识别结果 {$de_raw['message']}");
|
||||||
|
|
||||||
return $de_raw['message'];
|
return $de_raw['message'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @use 保存cookie
|
* @use token转cookie
|
||||||
* @param $data
|
* @return string
|
||||||
*/
|
*/
|
||||||
private static function saveCookie($data)
|
private static function token2cookie(): string
|
||||||
{
|
{
|
||||||
Log::info('COOKIE获取成功!');
|
$url = 'https://passport.bilibili.com/api/login/sso';
|
||||||
//临时保存cookie
|
$payload = [
|
||||||
$temp = '';
|
'gourl' => 'https%3A%2F%2Faccount.bilibili.com%2Faccount%2Fhome'
|
||||||
$cookies = $data['data']['cookie_info']['cookies'];
|
];
|
||||||
foreach ($cookies as $cookie) {
|
$response = Curl::headers('app', $url, Sign::common($payload));
|
||||||
$temp .= $cookie['name'] . '=' . $cookie['value'] . ';';
|
$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 保存cookie
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private static function saveCookie(): bool
|
||||||
|
{
|
||||||
|
$cookies = self::token2cookie();
|
||||||
|
if ($cookies == '') {
|
||||||
|
Log::error("COOKIE获取失败 {$cookies}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Log::info("COOKIE获取成功 !");
|
||||||
|
Log::info(" > cookie: {$cookies}");
|
||||||
|
Config::put('COOKIE', $cookies);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 清除已有
|
||||||
|
*/
|
||||||
|
private static function clearAccount()
|
||||||
|
{
|
||||||
|
$accounts = ['ACCESS_TOKEN', 'REFRESH_TOKEN', 'COOKIE'];
|
||||||
|
foreach ($accounts as $account) {
|
||||||
|
Config::put($account, '');
|
||||||
}
|
}
|
||||||
Config::put('COOKIE', $temp);
|
|
||||||
Log::info(' > auth cookie: ' . $temp);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -34,11 +34,12 @@ class ManGa
|
|||||||
private static function sign(): bool
|
private static function sign(): bool
|
||||||
{
|
{
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
$url = 'https://manga.bilibili.com/twirp/activity.v1.Activity/ClockIn';
|
||||||
$payload = [
|
$payload = [
|
||||||
'access_key' => getenv('ACCESS_TOKEN'),
|
'access_key' => getenv('ACCESS_TOKEN'),
|
||||||
'ts' => time()
|
'ts' => time()
|
||||||
];
|
];
|
||||||
$raw = Curl::post('https://manga.bilibili.com/twirp/activity.v1.Activity/ClockIn', Sign::api($payload));
|
$raw = Curl::post('app', $url, Sign::common($payload));
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
# {"code":0,"msg":"","data":{}}
|
# {"code":0,"msg":"","data":{}}
|
||||||
# {"code":"invalid_argument","msg":"clockin clockin is duplicate","meta":{"argument":"clockin"}}
|
# {"code":"invalid_argument","msg":"clockin clockin is duplicate","meta":{"argument":"clockin"}}
|
||||||
@ -56,8 +57,7 @@ class ManGa
|
|||||||
sleep(1);
|
sleep(1);
|
||||||
$payload = [];
|
$payload = [];
|
||||||
$url = "https://manga.bilibili.com/twirp/activity.v1.Activity/ShareComic";
|
$url = "https://manga.bilibili.com/twirp/activity.v1.Activity/ShareComic";
|
||||||
|
$raw = Curl::post('app', $url, Sign::common($payload));
|
||||||
$raw = Curl::post($url, Sign::api($payload));
|
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
# {"code":0,"msg":"","data":{"point":5}}
|
# {"code":0,"msg":"","data":{"point":5}}
|
||||||
# {"code":1,"msg":"","data":{"point":0}}
|
# {"code":1,"msg":"","data":{"point":0}}
|
||||||
|
|||||||
@ -52,7 +52,7 @@ class MasterSite
|
|||||||
'Referer' => "https://www.bilibili.com/video/av{$aid}",
|
'Referer' => "https://www.bilibili.com/video/av{$aid}",
|
||||||
'User-Agent' => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36",
|
'User-Agent' => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36",
|
||||||
];
|
];
|
||||||
$raw = Curl::post($url, Sign::api($payload), $headers);
|
$raw = Curl::post('app', $url, Sign::common($payload), $headers);
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
if ($de_raw['code'] == 0) {
|
if ($de_raw['code'] == 0) {
|
||||||
Log::notice("主站任务: av{$aid}投币成功!");
|
Log::notice("主站任务: av{$aid}投币成功!");
|
||||||
@ -72,7 +72,7 @@ class MasterSite
|
|||||||
{
|
{
|
||||||
$url = "https://api.bilibili.com/x/member/web/coin/log";
|
$url = "https://api.bilibili.com/x/member/web/coin/log";
|
||||||
$payload = [];
|
$payload = [];
|
||||||
$raw = Curl::get($url, Sign::api($payload));
|
$raw = Curl::get('pc', $url, $payload);
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
|
|
||||||
$logs = $de_raw['data']['list'];
|
$logs = $de_raw['data']['list'];
|
||||||
@ -150,10 +150,12 @@ class MasterSite
|
|||||||
private static function getRandomAid(): string
|
private static function getRandomAid(): string
|
||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
$page = random_int(1, 1000);
|
$url = "https://api.bilibili.com/x/web-interface/newlist";
|
||||||
$payload = [];
|
$payload = [
|
||||||
$url = "https://api.bilibili.com/x/web-interface/newlist?&pn={$page}&ps=1";
|
'pn' => random_int(1, 1000),
|
||||||
$raw = Curl::get($url, Sign::api($payload));
|
'ps' => 1,
|
||||||
|
];
|
||||||
|
$raw = Curl::get('other', $url, $payload);
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
// echo "getRandomAid " . count($de_raw['data']['archives']) . PHP_EOL;
|
// echo "getRandomAid " . count($de_raw['data']['archives']) . PHP_EOL;
|
||||||
// $aid = array_rand($de_raw['data']['archives'])['aid'];
|
// $aid = array_rand($de_raw['data']['archives'])['aid'];
|
||||||
@ -172,11 +174,16 @@ class MasterSite
|
|||||||
private static function getDayRankingAids($num): array
|
private static function getDayRankingAids($num): array
|
||||||
{
|
{
|
||||||
// day: 日榜1 三榜3 周榜7 月榜30
|
// day: 日榜1 三榜3 周榜7 月榜30
|
||||||
$payload = [];
|
|
||||||
$aids = [];
|
$aids = [];
|
||||||
$rand_nums = [];
|
$rand_nums = [];
|
||||||
$url = "https://api.bilibili.com/x/web-interface/ranking?rid=0&day=1&type=1&arc_type=0";
|
$url = "https://api.bilibili.com/x/web-interface/ranking";
|
||||||
$raw = Curl::get($url, Sign::api($payload));
|
$payload = [
|
||||||
|
'rid' => 0,
|
||||||
|
'day' => 1,
|
||||||
|
'type' => 1,
|
||||||
|
'arc_type' => 0
|
||||||
|
];
|
||||||
|
$raw = Curl::get('other', $url, $payload);
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
for ($i = 0; $i < $num; $i++) {
|
for ($i = 0; $i < $num; $i++) {
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -218,7 +225,7 @@ class MasterSite
|
|||||||
'Referer' => "https://www.bilibili.com/video/av{$av_info['aid']}",
|
'Referer' => "https://www.bilibili.com/video/av{$av_info['aid']}",
|
||||||
'User-Agent' => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36",
|
'User-Agent' => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36",
|
||||||
];
|
];
|
||||||
$raw = Curl::post($url, Sign::api($payload), $headers);
|
$raw = Curl::post('pc', $url, $payload, $headers);
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
if ($de_raw['code'] == 0) {
|
if ($de_raw['code'] == 0) {
|
||||||
Log::notice("主站任务: av{$av_info['aid']}分享成功!");
|
Log::notice("主站任务: av{$av_info['aid']}分享成功!");
|
||||||
@ -259,8 +266,7 @@ class MasterSite
|
|||||||
'Referer' => "https://www.bilibili.com/video/av{$av_info['aid']}",
|
'Referer' => "https://www.bilibili.com/video/av{$av_info['aid']}",
|
||||||
'User-Agent' => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36",
|
'User-Agent' => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36",
|
||||||
];
|
];
|
||||||
|
$raw = Curl::post('pc', $url, $payload, $headers);
|
||||||
$raw = Curl::post($url, Sign::api($payload), $headers);
|
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
|
|
||||||
if ($de_raw['code'] == 0) {
|
if ($de_raw['code'] == 0) {
|
||||||
@ -278,7 +284,7 @@ class MasterSite
|
|||||||
"play_type" => "1",
|
"play_type" => "1",
|
||||||
'start_ts' => time()
|
'start_ts' => time()
|
||||||
];
|
];
|
||||||
$raw = Curl::post($url, Sign::api($payload), $headers);
|
$raw = Curl::post('pc', $url, $payload, $headers);
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
|
|
||||||
if ($de_raw['code'] == 0) {
|
if ($de_raw['code'] == 0) {
|
||||||
@ -286,7 +292,7 @@ class MasterSite
|
|||||||
$payload['played_time'] = $av_info['duration'] - 1;
|
$payload['played_time'] = $av_info['duration'] - 1;
|
||||||
$payload['play_type'] = 0;
|
$payload['play_type'] = 0;
|
||||||
$payload['start_ts'] = time();
|
$payload['start_ts'] = time();
|
||||||
$raw = Curl::post($url, Sign::api($payload), $headers);
|
$raw = Curl::post('pc', $url, $payload, $headers);
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
if ($de_raw['code'] == 0) {
|
if ($de_raw['code'] == 0) {
|
||||||
Log::notice("主站任务: av{$av_info['aid']}观看成功!");
|
Log::notice("主站任务: av{$av_info['aid']}观看成功!");
|
||||||
@ -308,8 +314,11 @@ class MasterSite
|
|||||||
{
|
{
|
||||||
while (true) {
|
while (true) {
|
||||||
$aid = self::getRandomAid();
|
$aid = self::getRandomAid();
|
||||||
$url = "https://api.bilibili.com/x/web-interface/view?aid={$aid}";
|
$url = "https://api.bilibili.com/x/web-interface/view";
|
||||||
$raw = Curl::get($url);
|
$payload = [
|
||||||
|
'aid' => $aid
|
||||||
|
];
|
||||||
|
$raw = Curl::get('other', $url, $payload);
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
if ($de_raw['code'] != 0) {
|
if ($de_raw['code'] != 0) {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@ -66,10 +66,11 @@ class MaterialObject
|
|||||||
*/
|
*/
|
||||||
private static function boxStatus(int $aid, $reply = 'bool')
|
private static function boxStatus(int $aid, $reply = 'bool')
|
||||||
{
|
{
|
||||||
|
$url = 'https://api.live.bilibili.com/lottery/v1/box/getStatus';
|
||||||
$payload = [
|
$payload = [
|
||||||
'aid' => $aid,
|
'aid' => $aid,
|
||||||
];
|
];
|
||||||
$raw = Curl::get('https://api.live.bilibili.com/lottery/v1/box/getStatus', Sign::api($payload));
|
$raw = Curl::get('pc', $url, $payload);
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
switch ($reply) {
|
switch ($reply) {
|
||||||
// 等于0是有抽奖返回false
|
// 等于0是有抽奖返回false
|
||||||
@ -96,7 +97,7 @@ class MaterialObject
|
|||||||
private static function fetchLottery(): array
|
private static function fetchLottery(): array
|
||||||
{
|
{
|
||||||
$lottery_list = [];
|
$lottery_list = [];
|
||||||
$max_probe = 5;
|
$max_probe = 10;
|
||||||
$probes = range(self::$start_aid, self::$end_aid);
|
$probes = range(self::$start_aid, self::$end_aid);
|
||||||
foreach ($probes as $probe_aid) {
|
foreach ($probes as $probe_aid) {
|
||||||
// 最大试探
|
// 最大试探
|
||||||
@ -173,11 +174,12 @@ class MaterialObject
|
|||||||
$aid = $lottery['aid'];
|
$aid = $lottery['aid'];
|
||||||
$num = $lottery['num'];
|
$num = $lottery['num'];
|
||||||
Log::notice("实物抽奖 {$aid} 轮次 {$num} 可参与抽奖~");
|
Log::notice("实物抽奖 {$aid} 轮次 {$num} 可参与抽奖~");
|
||||||
|
$url = 'https://api.live.bilibili.com/lottery/v1/Box/draw';
|
||||||
$payload = [
|
$payload = [
|
||||||
'aid' => $aid,
|
'aid' => $aid,
|
||||||
'number' => $num,
|
'number' => $num,
|
||||||
];
|
];
|
||||||
$raw = Curl::get('https://api.live.bilibili.com/lottery/v1/Box/draw', Sign::api($payload));
|
$raw = Curl::get('pc', $url, $payload);
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
if ($de_raw['code'] == 0) {
|
if ($de_raw['code'] == 0) {
|
||||||
Log::notice("实物抽奖 {$aid} 轮次 {$num} 参与抽奖成功~");
|
Log::notice("实物抽奖 {$aid} 轮次 {$num} 参与抽奖成功~");
|
||||||
|
|||||||
@ -130,7 +130,7 @@ class Notice
|
|||||||
private static function scSend(array $info)
|
private static function scSend(array $info)
|
||||||
{
|
{
|
||||||
$url = "https://sc.ftqq.com/" . self::$sckey . ".send?text=" . urlencode($info['title']) . "&desp=" . urlencode($info['content']);
|
$url = "https://sc.ftqq.com/" . self::$sckey . ".send?text=" . urlencode($info['title']) . "&desp=" . urlencode($info['content']);
|
||||||
$data = Curl::singleRequest('get', $url);
|
$data = Curl::request('get', $url);
|
||||||
if (is_null($data)) {
|
if (is_null($data)) {
|
||||||
Log::warning('Server酱推送信息失败,请检查!');
|
Log::warning('Server酱推送信息失败,请检查!');
|
||||||
};
|
};
|
||||||
|
|||||||
@ -86,14 +86,14 @@ class PkRaffle extends BaseRaffle
|
|||||||
"csrf" => $user_info['token'],
|
"csrf" => $user_info['token'],
|
||||||
];
|
];
|
||||||
array_push($tasks, [
|
array_push($tasks, [
|
||||||
'payload' => Sign::api($payload),
|
'payload' => Sign::common($payload),
|
||||||
'source' => [
|
'source' => [
|
||||||
'room_id' => $raffle['room_id'],
|
'room_id' => $raffle['room_id'],
|
||||||
'raffle_id' => $raffle['raffle_id']
|
'raffle_id' => $raffle['raffle_id']
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
$results = Curl::asyncPost($url, $tasks);
|
$results = Curl::async('app', $url, $tasks);
|
||||||
# print_r($results);
|
# print_r($results);
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,46 +11,78 @@
|
|||||||
namespace BiliHelper\Plugin;
|
namespace BiliHelper\Plugin;
|
||||||
|
|
||||||
use BiliHelper\Core\Log;
|
use BiliHelper\Core\Log;
|
||||||
use BiliHelper\Core\Curl;
|
|
||||||
use BiliHelper\Util\TimeLock;
|
|
||||||
|
|
||||||
class Sign
|
class Sign
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @use 计算sign
|
* @use 登录
|
||||||
* @param $payload
|
* @param $payload
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function api($payload)
|
public static function login($payload)
|
||||||
{
|
{
|
||||||
# iOS 6680
|
|
||||||
$appkey = '27eb53fc9058f8c3';
|
|
||||||
$appsecret = 'c2ed53a74eeefe3cf99fbd01d8c9c375';
|
|
||||||
# Android
|
|
||||||
// $appkey = '1d8b6e7d45233436';
|
|
||||||
// $appsecret = '560c52ccd288fed045859ed18bffd973';
|
|
||||||
# 云视听 TV
|
# 云视听 TV
|
||||||
// $appkey = '4409e2ce8ffd12b8';
|
$appkey = '4409e2ce8ffd12b8';
|
||||||
// $appsecret = '59b43e04ad6965f34319062b478f83dd';
|
$appsecret = '59b43e04ad6965f34319062b478f83dd';
|
||||||
|
|
||||||
$default = [
|
$default = [
|
||||||
'access_key' => getenv('ACCESS_TOKEN'),
|
'access_key' => getenv('ACCESS_TOKEN'),
|
||||||
'actionKey' => 'appkey',
|
'actionKey' => 'appkey',
|
||||||
'appkey' => $appkey,
|
'appkey' => $appkey,
|
||||||
'build' => '8230',
|
'build' => 101800,
|
||||||
'device' => 'phone',
|
'device' => 'android',
|
||||||
'mobi_app' => 'iphone',
|
'mobi_app' => 'android_tv_yst',
|
||||||
'platform' => 'ios',
|
'platform' => 'android',
|
||||||
'ts' => time(),
|
'ts' => time(),
|
||||||
];
|
];
|
||||||
|
|
||||||
$payload = array_merge($payload, $default);
|
$payload = array_merge($payload, $default);
|
||||||
|
return self::encryption($payload, $appsecret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 通用
|
||||||
|
* @param $payload
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function common($payload)
|
||||||
|
{
|
||||||
|
# iOS 6680
|
||||||
|
// $appkey = '27eb53fc9058f8c3';
|
||||||
|
// $appsecret = 'c2ed53a74eeefe3cf99fbd01d8c9c375';
|
||||||
|
# Android
|
||||||
|
$appkey = '1d8b6e7d45233436';
|
||||||
|
$appsecret = '560c52ccd288fed045859ed18bffd973';
|
||||||
|
|
||||||
|
$default = [
|
||||||
|
'access_key' => getenv('ACCESS_TOKEN'),
|
||||||
|
'actionKey' => 'appkey',
|
||||||
|
'appkey' => $appkey,
|
||||||
|
'build' => 5511400,
|
||||||
|
'device' => 'android',
|
||||||
|
'mobi_app' => 'android',
|
||||||
|
'platform' => 'android',
|
||||||
|
'ts' => time(),
|
||||||
|
];
|
||||||
|
$payload = array_merge($payload, $default);
|
||||||
|
return self::encryption($payload, $appsecret);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 加密
|
||||||
|
* @param array $payload
|
||||||
|
* @param string $app_secret
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private static function encryption(array $payload, string $app_secret): array
|
||||||
|
{
|
||||||
if (isset($payload['sign'])) {
|
if (isset($payload['sign'])) {
|
||||||
unset($payload['sign']);
|
unset($payload['sign']);
|
||||||
}
|
}
|
||||||
ksort($payload);
|
ksort($payload);
|
||||||
$data = http_build_query($payload);
|
$data = http_build_query($payload);
|
||||||
$payload['sign'] = md5($data . $appsecret);
|
$payload['sign'] = md5($data . $app_secret);
|
||||||
return $payload;
|
return $payload;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -37,13 +37,14 @@ class Silver
|
|||||||
*/
|
*/
|
||||||
private static function getSilverBox()
|
private static function getSilverBox()
|
||||||
{
|
{
|
||||||
|
$url = 'https://api.live.bilibili.com/lottery/v1/SilverBox/getCurrentTask';
|
||||||
$payload = [];
|
$payload = [];
|
||||||
$data = Curl::get('https://api.live.bilibili.com/lottery/v1/SilverBox/getCurrentTask', Sign::api($payload));
|
$data = Curl::get('app', $url, Sign::common($payload));
|
||||||
$data = json_decode($data, true);
|
$data = json_decode($data, true);
|
||||||
|
|
||||||
if (isset($data['code']) && $data['code'] == -10017) {
|
if (isset($data['code']) && $data['code'] == -10017) {
|
||||||
Log::notice($data['message']);
|
Log::notice($data['message']);
|
||||||
self::setLock( 24 * 60 * 60);
|
self::setLock(24 * 60 * 60);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +60,7 @@ class Silver
|
|||||||
'time_start' => $data['data']['time_start'],
|
'time_start' => $data['data']['time_start'],
|
||||||
'time_end' => $data['data']['time_end'],
|
'time_end' => $data['data']['time_end'],
|
||||||
];
|
];
|
||||||
self::setLock( $data['data']['minute'] * 60 + 5);
|
self::setLock($data['data']['minute'] * 60 + 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -68,15 +69,16 @@ class Silver
|
|||||||
*/
|
*/
|
||||||
private static function openSilverBox()
|
private static function openSilverBox()
|
||||||
{
|
{
|
||||||
|
$url = 'https://api.live.bilibili.com/mobile/freeSilverAward';
|
||||||
$payload = [
|
$payload = [
|
||||||
'time_end' => self::$task['time_end'],
|
'time_end' => self::$task['time_end'],
|
||||||
'time_start' => self::$task['time_start']
|
'time_start' => self::$task['time_start']
|
||||||
];
|
];
|
||||||
$data = Curl::get('https://api.live.bilibili.com/mobile/freeSilverAward', Sign::api($payload));
|
$data = Curl::get('app',$url, Sign::common($payload));
|
||||||
$data = json_decode($data, true);
|
$data = json_decode($data, true);
|
||||||
|
|
||||||
if ($data['code'] == -800) {
|
if ($data['code'] == -800) {
|
||||||
self::setLock( 12 * 60 * 60);
|
self::setLock(12 * 60 * 60);
|
||||||
Log::warning("领取宝箱失败,{$data['message']}!");
|
Log::warning("领取宝箱失败,{$data['message']}!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -84,19 +86,19 @@ class Silver
|
|||||||
if ($data['code'] == -903) {
|
if ($data['code'] == -903) {
|
||||||
Log::warning("领取宝箱失败,{$data['message']}!");
|
Log::warning("领取宝箱失败,{$data['message']}!");
|
||||||
self::$task = [];
|
self::$task = [];
|
||||||
self::setLock( 60);
|
self::setLock(60);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($data['code']) && $data['code']) {
|
if (isset($data['code']) && $data['code']) {
|
||||||
Log::warning("领取宝箱失败,{$data['message']}!");
|
Log::warning("领取宝箱失败,{$data['message']}!");
|
||||||
self::setLock( 60);
|
self::setLock(60);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::notice("领取宝箱成功,Silver: {$data['data']['silver']}(+{$data['data']['awardSilver']})");
|
Log::notice("领取宝箱成功,Silver: {$data['data']['silver']}(+{$data['data']['awardSilver']})");
|
||||||
|
|
||||||
self::$task = [];
|
self::$task = [];
|
||||||
self::setLock( 10);
|
self::setLock(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,8 +38,9 @@ class Silver2Coin
|
|||||||
protected static function appSilver2coin(): bool
|
protected static function appSilver2coin(): bool
|
||||||
{
|
{
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
$url = 'https://api.live.bilibili.com/AppExchange/silver2coin';
|
||||||
$payload = [];
|
$payload = [];
|
||||||
$raw = Curl::get('https://api.live.bilibili.com/AppExchange/silver2coin', Sign::api($payload));
|
$raw = Curl::get('app', $url, Sign::common($payload));
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
|
|
||||||
if (!$de_raw['code'] && $de_raw['msg'] == '兑换成功') {
|
if (!$de_raw['code'] && $de_raw['msg'] == '兑换成功') {
|
||||||
@ -64,8 +65,8 @@ class Silver2Coin
|
|||||||
$payload = [];
|
$payload = [];
|
||||||
$url = "https://api.live.bilibili.com/exchange/silver2coin";
|
$url = "https://api.live.bilibili.com/exchange/silver2coin";
|
||||||
$url = "https://api.live.bilibili.com/pay/v1/Exchange/silver2coin";
|
$url = "https://api.live.bilibili.com/pay/v1/Exchange/silver2coin";
|
||||||
|
|
||||||
$raw = Curl::get($url, Sign::api($payload));
|
$raw = Curl::get('pc', $url, $payload);
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
if ($de_raw['code'] == -403) {
|
if ($de_raw['code'] == -403) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -21,7 +21,7 @@ class Sleep
|
|||||||
// TODO 黑白名单|考虑添加到每个插件内部自动添加|优化RUN逻辑代码
|
// TODO 黑白名单|考虑添加到每个插件内部自动添加|优化RUN逻辑代码
|
||||||
private static $unlock_hour = 24;
|
private static $unlock_hour = 24;
|
||||||
private static $unlock_time = 0;
|
private static $unlock_time = 0;
|
||||||
private static $fillable = ['Login', 'Sleep', 'Daily', 'MasterSite', 'GiftSend', 'Task', 'Silver2Coin', 'GroupSignIn', 'AwardRecord', 'Statistics'];
|
private static $fillable = ['Login', 'Sleep', 'Daily', 'Judge', 'MasterSite', 'GiftSend', 'Task', 'Silver2Coin', 'GroupSignIn', 'AwardRecord', 'Statistics'];
|
||||||
private static $guarded = ['Barrage', 'GiftHeart', 'Heart', 'Silver', 'MaterialObject', 'AloneTcpClient', 'ZoneTcpClient', 'StormRaffle', 'GuardRaffle', 'PkRaffle', 'GiftRaffle', 'AnchorRaffle'];
|
private static $guarded = ['Barrage', 'GiftHeart', 'Heart', 'Silver', 'MaterialObject', 'AloneTcpClient', 'ZoneTcpClient', 'StormRaffle', 'GuardRaffle', 'PkRaffle', 'GiftRaffle', 'AnchorRaffle'];
|
||||||
private static $sleep_section = [];
|
private static $sleep_section = [];
|
||||||
|
|
||||||
@ -75,8 +75,9 @@ class Sleep
|
|||||||
*/
|
*/
|
||||||
private static function isRefuse(): bool
|
private static function isRefuse(): bool
|
||||||
{
|
{
|
||||||
|
$url = 'https://api.live.bilibili.com/mobile/freeSilverAward';
|
||||||
$payload = [];
|
$payload = [];
|
||||||
$raw = Curl::get('https://api.live.bilibili.com/mobile/freeSilverAward', Sign::api($payload));
|
$raw = Curl::get('app', $url, Sign::common($payload));
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
if ($de_raw['msg'] == '访问被拒绝') {
|
if ($de_raw['msg'] == '访问被拒绝') {
|
||||||
$unlock_time = strtotime(date("Y-m-d", strtotime("+1 day", time()))) - time();
|
$unlock_time = strtotime(date("Y-m-d", strtotime("+1 day", time()))) - time();
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
namespace BiliHelper\Plugin;
|
namespace BiliHelper\Plugin;
|
||||||
|
|
||||||
use BiliHelper\Core\Log;
|
use BiliHelper\Core\Log;
|
||||||
|
use BiliHelper\Core\Curl;
|
||||||
use BiliHelper\Util\TimeLock;
|
use BiliHelper\Util\TimeLock;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -108,7 +108,7 @@ class StormRaffle extends BaseRaffle
|
|||||||
"visit_id" => ""
|
"visit_id" => ""
|
||||||
];
|
];
|
||||||
for ($i = 1; $i < $num; $i++) {
|
for ($i = 1; $i < $num; $i++) {
|
||||||
$raw = Curl::post($url, Sign::api($payload));
|
$raw = Curl::post('app', $url, Sign::common($payload));
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
if ($de_raw['code'] == 429 || $de_raw['code'] == -429) {
|
if ($de_raw['code'] == 429 || $de_raw['code'] == -429) {
|
||||||
Log::notice(self::formatInfo($raffle['raffle_id'], $num, '节奏风暴未实名或异常验证码'));
|
Log::notice(self::formatInfo($raffle['raffle_id'], $num, '节奏风暴未实名或异常验证码'));
|
||||||
|
|||||||
@ -41,8 +41,9 @@ class Task
|
|||||||
*/
|
*/
|
||||||
private static function check()
|
private static function check()
|
||||||
{
|
{
|
||||||
|
$url = 'https://api.live.bilibili.com/i/api/taskInfo';
|
||||||
$payload = [];
|
$payload = [];
|
||||||
$data = Curl::get('https://api.live.bilibili.com/i/api/taskInfo', Sign::api($payload));
|
$data = Curl::get('app',$url, Sign::common($payload));
|
||||||
$data = json_decode($data, true);
|
$data = json_decode($data, true);
|
||||||
Log::info('正在检查每日任务...');
|
Log::info('正在检查每日任务...');
|
||||||
if (isset($data['code']) && $data['code']) {
|
if (isset($data['code']) && $data['code']) {
|
||||||
@ -64,9 +65,9 @@ class Task
|
|||||||
Log::notice('该任务已完成');
|
Log::notice('该任务已完成');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$url = 'https://api.live.bilibili.com/sign/doSign';
|
||||||
$payload = [];
|
$payload = [];
|
||||||
$data = Curl::get('https://api.live.bilibili.com/sign/doSign', Sign::api($payload));
|
$data = Curl::get('app',$url, Sign::common($payload));
|
||||||
$data = json_decode($data, true);
|
$data = json_decode($data, true);
|
||||||
|
|
||||||
if (isset($data['code']) && $data['code']) {
|
if (isset($data['code']) && $data['code']) {
|
||||||
@ -94,10 +95,11 @@ class Task
|
|||||||
Log::notice('任务未完成,请等待');
|
Log::notice('任务未完成,请等待');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$url = 'https://api.live.bilibili.com/activity/v1/task/receive_award';
|
||||||
$payload = [
|
$payload = [
|
||||||
'task_id' => 'double_watch_task',
|
'task_id' => 'double_watch_task',
|
||||||
];
|
];
|
||||||
$data = Curl::post('https://api.live.bilibili.com/activity/v1/task/receive_award', Sign::api($payload));
|
$data = Curl::post('app',$url, Sign::common($payload));
|
||||||
$data = json_decode($data, true);
|
$data = json_decode($data, true);
|
||||||
|
|
||||||
if (isset($data['code']) && $data['code']) {
|
if (isset($data['code']) && $data['code']) {
|
||||||
|
|||||||
@ -18,8 +18,6 @@ use BiliHelper\Core\Config;
|
|||||||
|
|
||||||
class User
|
class User
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @use 实名检测
|
* @use 实名检测
|
||||||
* @return bool
|
* @return bool
|
||||||
@ -27,8 +25,9 @@ class User
|
|||||||
*/
|
*/
|
||||||
public static function realNameCheck(): bool
|
public static function realNameCheck(): bool
|
||||||
{
|
{
|
||||||
|
$url = 'https://account.bilibili.com/identify/index';
|
||||||
$payload = [];
|
$payload = [];
|
||||||
$raw = Curl::get('https://account.bilibili.com/identify/index', Sign::api($payload));
|
$raw = Curl::get('pc', $url, $payload);
|
||||||
$de_raw = json_decode($raw, true);
|
$de_raw = json_decode($raw, true);
|
||||||
//检查有没有名字,没有则没实名
|
//检查有没有名字,没有则没实名
|
||||||
if (!$de_raw['data']['memberPerson']['realname']) {
|
if (!$de_raw['data']['memberPerson']['realname']) {
|
||||||
@ -45,13 +44,9 @@ class User
|
|||||||
*/
|
*/
|
||||||
public static function isMaster(): bool
|
public static function isMaster(): bool
|
||||||
{
|
{
|
||||||
$payload = [
|
$data = self::getUserInfo();
|
||||||
'ts' => Live::getMillisecond(),
|
if ($data['msg'] == 'ok') {
|
||||||
];
|
if ($data['data']['vip'] || $data['data']['svip']) {
|
||||||
$raw = Curl::get('https://api.live.bilibili.com/User/getUserInfo', Sign::api($payload));
|
|
||||||
$de_raw = json_decode($raw, true);
|
|
||||||
if ($de_raw['msg'] == 'ok') {
|
|
||||||
if ($de_raw['data']['vip'] || $de_raw['data']['svip']) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,29 +55,70 @@ class User
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @use 用户名写入
|
* @use 写入用户名
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function userInfo(): bool
|
public static function userInfo(): bool
|
||||||
{
|
{
|
||||||
$payload = [
|
$data = self::getUserInfo();
|
||||||
'ts' => Live::getMillisecond(),
|
|
||||||
];
|
|
||||||
$raw = Curl::get('https://api.live.bilibili.com/User/getUserInfo', Sign::api($payload));
|
|
||||||
$de_raw = json_decode($raw, true);
|
|
||||||
|
|
||||||
if (getenv('APP_UNAME') != "") {
|
if (getenv('APP_UNAME') != "") {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ($de_raw['msg'] == 'ok') {
|
if ($data['msg'] == 'ok') {
|
||||||
Config::put('APP_UNAME', $de_raw['data']['uname']);
|
Config::put('APP_UNAME', $data['data']['uname']);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use UserInfo
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getUserInfo(): array
|
||||||
|
{
|
||||||
|
$url = 'https://api.live.bilibili.com/User/getUserInfo';
|
||||||
|
$payload = [
|
||||||
|
'ts' => Live::getMillisecond(),
|
||||||
|
];
|
||||||
|
$raw = Curl::get('app', $url, Sign::common($payload));
|
||||||
|
return json_decode($raw, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use Web User
|
||||||
|
* @param null $room_id
|
||||||
|
* @return mixed
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public static function webGetUserInfo($room_id = null)
|
||||||
|
{
|
||||||
|
$url = 'https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByUser';
|
||||||
|
$payload = [
|
||||||
|
'room_id' => $room_id ?? getenv('ROOM_ID')
|
||||||
|
];
|
||||||
|
$raw = Curl::get('pc', $url, $payload);
|
||||||
|
return json_decode($raw, true);;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use App User
|
||||||
|
* @param null $room_id
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function appGetUserInfo($room_id = null)
|
||||||
|
{
|
||||||
|
$url = 'https://api.live.bilibili.com/xlive/app-room/v1/index/getInfoByUser';
|
||||||
|
$payload = [
|
||||||
|
'room_id' => $room_id ?? getenv('ROOM_ID')
|
||||||
|
];
|
||||||
|
$raw = Curl::get('app', $url, Sign::common($payload));
|
||||||
|
return json_decode($raw, true);;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @use 转换信息
|
* @use 转换信息
|
||||||
* @return array
|
* @return array
|
||||||
@ -102,36 +138,4 @@ class User
|
|||||||
'sid' => $sid,
|
'sid' => $sid,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @use Web User
|
|
||||||
* @param null $room_id
|
|
||||||
* @return mixed
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public static function webGetUserInfo($room_id = null)
|
|
||||||
{
|
|
||||||
$url = 'https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByUser';
|
|
||||||
$payload = [
|
|
||||||
'room_id' => $room_id ?? getenv('ROOM_ID')
|
|
||||||
];
|
|
||||||
$raw = Curl::get($url, Sign::api($payload));
|
|
||||||
return json_decode($raw, true);;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @use App User
|
|
||||||
* @return mixed
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public static function appGetUserInfo()
|
|
||||||
{
|
|
||||||
$url = 'https://api.live.bilibili.com/xlive/app-room/v1/index/getInfoByUser';
|
|
||||||
$payload = [
|
|
||||||
'room_id' => $room_id ?? getenv('ROOM_ID')
|
|
||||||
];
|
|
||||||
$raw = Curl::get($url, Sign::api($payload));
|
|
||||||
return json_decode($raw, true);;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -11,6 +11,7 @@
|
|||||||
namespace BiliHelper\Plugin;
|
namespace BiliHelper\Plugin;
|
||||||
|
|
||||||
use BiliHelper\Core\Log;
|
use BiliHelper\Core\Log;
|
||||||
|
use BiliHelper\Core\Curl;
|
||||||
use BiliHelper\Util\TimeLock;
|
use BiliHelper\Util\TimeLock;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|||||||
@ -4,8 +4,7 @@
|
|||||||
namespace BiliHelper\Tool;
|
namespace BiliHelper\Tool;
|
||||||
|
|
||||||
use BiliHelper\Core\Log;
|
use BiliHelper\Core\Log;
|
||||||
|
use BiliHelper\Core\Curl;class DumpMemory
|
||||||
class DumpMemory
|
|
||||||
{
|
{
|
||||||
public static function dd($title)
|
public static function dd($title)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user