[fix] Curl fixes #21

This commit is contained in:
lkeme 2020-03-18 14:32:06 +08:00
parent 418ea70e98
commit 63c67be31a
25 changed files with 114 additions and 93 deletions

View File

@ -1,7 +1,28 @@
# Release Notes
# 本项目Log
## v0.3.0.200316 alpha (2020-03-169)
## v0.3.0.200318 alpha (2020-03-18)
### Added
- 添加日常任务定时执行(AM10:00)
-
### Changed
- Sleep->Schedule
- 优化异常通知
- 优化异常重试数
- 优化弹幕获取
- 优化银瓜子宝箱
-
### Fixed
- 修复日志回调
- 修复response为null
- 修复PC端心跳
- 修复部分已知
-
## v0.3.0.200316 alpha (2020-03-16)
### Added
- 添加异常处理(通知)

50
DOC.md
View File

@ -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 src="https://img.shields.io/badge/version-0.3.0.200316 alpha-green.svg?longCache=true&style=for-the-badge">
<img src="https://img.shields.io/badge/version-0.3.0.200318 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">
</p>
@ -15,30 +15,30 @@ B 站直播实用脚本
|plugin |version |description |
|--------------------|--------------------|--------------------|
|Login |20.03.16 |账号登录 |
|Sleep |20.03.16 |休眠控制 |
|MasterSite |20.03.16 |主站助手 |
|Daily |20.03.16 |每日礼包 |
|Heart |20.03.16 |双端心跳 |
|Task |20.03.16 |每日任务 |
|Silver |20.03.16 |银瓜子宝箱 |
|Barrage |20.03.16 |活跃弹幕 |
|Silver2Coin |20.03.16 |银瓜子换硬币 |
|GiftSend |20.03.16 |礼物赠送 |
|Judge |20.03.16 |风纪 |
|GroupSignIn |20.03.16 |友爱社签到 |
|ManGa |20.03.16 |漫画签到分享 |
|GiftHeart |20.03.16 |心跳礼物 |
|MaterialObject |20.03.16 |实物抽奖 |
|AloneTcpClient |20.03.16 |独立监控 |
|ZoneTcpClient |20.03.16 |分区监控 |
|StormRaffle |20.03.16 |节奏风暴 |
|GiftRaffle |20.03.16 |活动礼物 |
|PkRaffle |20.03.16 |大乱斗 |
|GuardRaffle |20.03.16 |舰长总督 |
|AnchorRaffle |20.03.16 |天选时刻 |
|AwardRecord |20.03.16 |获奖通知 |
|Statistics |20.03.16 |数据统计 |
|Login |20.03.18 |账号登录 |
|Schedule |20.03.18 |休眠控制 |
|MasterSite |20.03.18 |主站助手 |
|Daily |20.03.18 |每日礼包 |
|Heart |20.03.18 |双端心跳 |
|Task |20.03.18 |每日任务 |
|Silver |20.03.18 |银瓜子宝箱 |
|Barrage |20.03.18 |活跃弹幕 |
|Silver2Coin |20.03.18 |银瓜子换硬币 |
|GiftSend |20.03.18 |礼物赠送 |
|Judge |20.03.18 |风纪 |
|GroupSignIn |20.03.18 |友爱社签到 |
|ManGa |20.03.18 |漫画签到分享 |
|GiftHeart |20.03.18 |心跳礼物 |
|MaterialObject |20.03.18 |实物抽奖 |
|AloneTcpClient |20.03.18 |独立监控 |
|ZoneTcpClient |20.03.18 |分区监控 |
|StormRaffle |20.03.18 |节奏风暴 |
|GiftRaffle |20.03.18 |活动礼物 |
|PkRaffle |20.03.18 |大乱斗 |
|GuardRaffle |20.03.18 |舰长总督 |
|AnchorRaffle |20.03.18 |天选时刻 |
|AwardRecord |20.03.18 |获奖通知 |
|Statistics |20.03.18 |数据统计 |
## 打赏赞助

View File

@ -3,16 +3,18 @@ B 站直播实用脚本
## 交流
Group: [55308141](https://jq.qq.com/?_wv=1027&k=5AIDaJg)
Group: [55308141](https://jq.qq.com/?_wv=1027&k=5AIDaJg) | **仅用于BUG提交反馈**
## 公告
Currently for Personal Edition **0.3.0.200316 alpha**
Currently for Personal Edition **0.3.0.200318 alpha**
## 文档
* [使用文档 / DOC.md](./DOC.md)
* [更新日志 / CHANGELOG.md](./CHANGELOG.md)
* [配置文档 / WIKI.md](https://github.com/lkeme/BiliHelper-personal/wiki/%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E8%AF%A6%E8%A7%A3)
* [常见问题 / WIKI.md](https://github.com/lkeme/BiliHelper-personal/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98)
## 打赏

View File

@ -59,7 +59,7 @@ class App
} catch (\Throwable $e) {
$error_msg = "MSG: {$e->getMessage()} CODE: {$e->getCode()} FILE: {$e->getFile()} LINE: {$e->getLine()}";
Log::error($error_msg);
Notice::push('error', $error_msg);
// Notice::push('error', $error_msg);
}
yield new Delayed(1000);
}
@ -73,7 +73,7 @@ class App
{
$plugins = [
'Login',
'Sleep',
'Schedule',
'MasterSite',
'Daily',
'ManGa',

View File

@ -168,28 +168,31 @@ class Curl
self::$async_opt = [];
}
/**
* @use 请求中心异常处理
* @param string $url
* @param string $method
* @param array $options
* @return mixed
* @throws \Exception
*/
private static function clientHandle(string $url, string $method, array $options)
{
$max_retry = range(0, 30);
$max_retry = range(1, 40);
foreach ($max_retry as $retry) {
try {
return call_user_func_array([self::$client, $method], [$url, $options]);
$response = call_user_func_array([self::$client, $method], [$url, $options]);
if (is_null($response) or empty($response)) throw new \Exception("Value IsEmpty");
return $response;
} 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);
if ($e->hasResponse()) var_dump($e->getResponse());
} catch (\Exception $e) {
// var_dump($e);
}
Log::warning("CURl -> RETRY: {$retry} ERROR: {$e->getMessage()} ERRNO: {$e->getCode()} STATUS: Waiting for recovery!");
sleep(15);
}
exit('网络异常,超出最大尝试次数,退出程序~');
}

View File

@ -104,7 +104,7 @@ class Log
$url = str_replace('{account}', self::prefix(), getenv('APP_CALLBACK'));
$url = str_replace('{level}', $level, $url);
$url = str_replace('{message}', urlencode($message), $url);
Curl::get('other', $url);
Curl::request('get', $url);
}
}
}

View File

@ -93,7 +93,7 @@ class AnchorRaffle extends BaseRaffle
'room_id' => $room_id,
'raffle_id' => $de_raw['id'],
'raffle_name' => $de_raw['award_name'],
'wait' => time() + random_int(5, 25)
'wait' => time() + mt_rand(5, 25)
];
Statistics::addPushList(self::ACTIVE_TITLE);
array_push(self::$wait_list, $data);

View File

@ -32,7 +32,7 @@ class Barrage
];
if (self::privateSendMsg($info)) {
self::setLock(3600);
self::setLock(mt_rand(15, 30) * 60);
return;
}
@ -42,7 +42,7 @@ class Barrage
/**
* @use 获取随机弹幕
* @return \Exception|false|mixed|string
* @return \Exception|false|mixed|string|null
*/
private static function getMsgInfo()
{
@ -53,15 +53,12 @@ class Barrage
*/
$punctuations = ['', ',', '。', '!', '.', ';', '——'];
$apis = [
'https://api.lwl12.com/hitokoto/v1?encode=realjso',
'https://api.ly522.com/yan.php?format=text',
'https://v1.hitokoto.cn/?encode=text',
'https://api.jysafe.cn/yy/',
'https://m.mom1.cn/api/yan/api.php',
'https://api.ooopn.com/yan/api.php?type=text',
'https://api.imjad.cn/hitokoto/',
'https://www.ly522.com/hitokoto/',
'https://www.tddiao.online/word/',
'https://api.guoch.xyz/',
'http://www.ooomg.cn/dutang/',
'https://api.gushi.ci/rensheng.txt',

View File

@ -34,7 +34,6 @@ class GiftHeart
/**
* @use 礼物心跳
* @return bool
* @throws \Exception
*/
private static function giftHeart(): bool
{

View File

@ -26,7 +26,7 @@ class GroupSignIn
$groups = self::getGroupList();
if (empty($groups)) {
self::setLock(24 * 60 * 60);
self::setLock(self::timing(10));
return;
}

View File

@ -31,7 +31,6 @@ class GuardRaffle extends BaseRaffle
* @param int $room_id
* @param array $data
* @return bool
* @throws \Exception
*/
protected static function parseLotteryInfo(int $room_id, array $data): bool
{
@ -73,7 +72,7 @@ class GuardRaffle extends BaseRaffle
'room_id' => $room_id,
'raffle_id' => $guard['id'],
'raffle_name' => $raffle_name,
'wait' => time() + random_int(5, 25)
'wait' => time() + mt_rand(5, 25)
];
Statistics::addPushList(self::ACTIVE_TITLE);
array_push(self::$wait_list, $data);

View File

@ -34,11 +34,18 @@ class Heart
protected static function webHeart()
{
User::webGetUserInfo();
$url = 'https://api.live.bilibili.com/relation/v1/Feed/heartBeat';
$url = 'https://api.live.bilibili.com/User/userOnlineHeart';
$user_info = User::parseCookies();
$payload = [
'csrf' => $user_info['token'],
'csrf_token' => $user_info['token'],
'room_id' => getenv('ROOM_ID'),
'_' => time() * 1000,
];
$data = Curl::post('app', $url, Sign::common($payload));
$headers = [
'Referer' => 'https://live.bilibili.com/' . getenv('ROOM_ID')
];
$data = Curl::post('app', $url, $payload, $headers);
$data = json_decode($data, true);
if (isset($data['code']) && $data['code']) {

View File

@ -178,7 +178,7 @@ class Judge
// {"code":25005,"message":"请成为风纪委员后再试","ttl":1}
if (isset($de_raw['code']) && $de_raw['code'] == 25005) {
Log::warning($de_raw['message']);
self::setLock(24 * 60 * 60);
self::setLock(self::timing(10));
return null;
}
if (isset($de_raw['code']) && $de_raw['code']) {

View File

@ -21,7 +21,6 @@ class Live
/**
* @use 获取分区列表
* @return array
* @throws \Exception
*/
public static function fetchLiveAreas(): array
{
@ -47,7 +46,6 @@ class Live
* @use AREA_ID转ROOM_ID
* @param $area_id
* @return array
* @throws \Exception
*/
public static function areaToRid($area_id): array
{
@ -83,7 +81,6 @@ class Live
/**
* @use 获取随机直播房间号
* @return int
* @throws \Exception
*/
public static function getUserRecommend()
{
@ -99,7 +96,7 @@ class Live
if ($de_raw['code'] != '0') {
return 23058;
}
return $de_raw['data'][random_int(1, 29)]['roomid'];
return $de_raw['data'][mt_rand(1, 29)]['roomid'];
}
@ -107,7 +104,6 @@ class Live
* @use 获取直播房间号
* @param $room_id
* @return bool
* @throws \Exception
*/
public static function getRealRoomID($room_id)
{
@ -151,7 +147,6 @@ class Live
* @use 钓鱼检测
* @param $room_id
* @return bool
* @throws \Exception
*/
public static function fishingDetection($room_id): bool
{
@ -166,7 +161,6 @@ class Live
* @use 访问直播间
* @param $room_id
* @return bool
* @throws \Exception
*/
public static function goToRoom($room_id): bool
{

View File

@ -24,7 +24,7 @@ class ManGa
return;
}
if (self::sign() && self::share()) {
self::setLock(24 * 60 * 60);
self::setLock(self::timing(10));
return;
}
self::setLock(3600);

View File

@ -24,7 +24,7 @@ class MasterSite
return;
}
if (self::watchAid() && self::shareAid() && self::coinAdd()) {
self::setLock(24 * 60 * 60);
self::setLock(self::timing(10));
return;
}
self::setLock(3600);
@ -103,7 +103,6 @@ class MasterSite
/**
* @use 视频投币 TODO : 处理视频投币硬币少于需要投币数
* @return bool
* @throws \Exception
*/
protected static function coinAdd(): bool
{
@ -144,14 +143,13 @@ class MasterSite
/**
* @use 获取随机AID
* @return string
* @throws \Exception
*/
private static function getRandomAid(): string
{
do {
$url = "https://api.bilibili.com/x/web-interface/newlist";
$payload = [
'pn' => random_int(1, 1000),
'pn' => mt_rand(1, 1000),
'ps' => 1,
];
$raw = Curl::get('other', $url, $payload);
@ -168,7 +166,6 @@ class MasterSite
* @use 获取日榜AID
* @param $num
* @return array
* @throws \Exception
*/
private static function getDayRankingAids($num): array
{
@ -186,7 +183,7 @@ class MasterSite
$de_raw = json_decode($raw, true);
for ($i = 0; $i < $num; $i++) {
while (true) {
$rand_num = random_int(1, 100);
$rand_num = mt_rand(1, 100);
if (in_array($rand_num, $rand_nums)) {
continue;
} else {
@ -205,7 +202,6 @@ class MasterSite
/**
* @use 分享视频
* @return bool
* @throws \Exception
*/
private static function shareAid(): bool
{
@ -239,7 +235,6 @@ class MasterSite
/**
* @use 观看视频
* @return bool
* @throws \Exception
*/
private static function watchAid(): bool
{
@ -307,7 +302,6 @@ class MasterSite
/**
* @use 解析AID到CID
* @return array
* @throws \Exception
*/
private static function parseAid(): array
{

View File

@ -34,7 +34,7 @@ class MaterialObject
self::calcAid(470, 770);
$lottery_list = self::fetchLottery();
self::drawLottery($lottery_list);
self::setLock(random_int(5, 10) * 60);
self::setLock(mt_rand(6, 10) * 60);
}
@ -196,7 +196,6 @@ class MaterialObject
* @param $min
* @param $max
* @return bool
* @throws \Exception
*/
private static function calcAid($min, $max): bool
{
@ -206,7 +205,7 @@ class MaterialObject
while (true) {
$middle = round(($min + $max) / 2);
if (self::boxStatus($middle)) {
if (self::boxStatus($middle + random_int(0, 3))) {
if (self::boxStatus($middle + mt_rand(0, 3))) {
$max = $middle;
} else {
$min = $middle;
@ -218,8 +217,8 @@ class MaterialObject
break;
}
}
self::$start_aid = $min - random_int(15, 30);
self::$end_aid = $min + random_int(15, 30);
self::$start_aid = $min - mt_rand(15, 30);
self::$end_aid = $min + mt_rand(15, 30);
Log::info("实物抽奖起始值[" . self::$start_aid . "],结束值[" . self::$end_aid . "]");
return true;
}

View File

@ -58,7 +58,7 @@ class PkRaffle extends BaseRaffle
'room_id' => $room_id,
'raffle_id' => $pk['id'],
'raffle_name' => '大乱斗',
'wait' => time() + random_int(5, 25)
'wait' => time() + mt_rand(5, 25)
];
Statistics::addPushList(self::ACTIVE_TITLE);
array_push(self::$wait_list, $data);

View File

@ -15,13 +15,13 @@ use BiliHelper\Core\Curl;
use BiliHelper\Util\TimeLock;
class Sleep
class Schedule
{
use TimeLock;
// TODO 黑白名单|考虑添加到每个插件内部自动添加|优化RUN逻辑代码
private static $unlock_hour = 24;
private static $unlock_time = 0;
private static $fillable = ['Login', 'Sleep', 'Daily', 'Judge', 'MasterSite', 'GiftSend', 'Task', 'Silver2Coin', 'GroupSignIn', 'AwardRecord', 'Statistics'];
private static $fillable = ['Login', 'Schedule', '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 $sleep_section = [];

View File

@ -44,7 +44,11 @@ class Silver
if (isset($data['code']) && $data['code'] == -10017) {
Log::notice($data['message']);
self::setLock(24 * 60 * 60);
if (User::isMaster()) {
self::setLock(self::timing(6));
} else {
self::setLock(self::timing(10));
}
return;
}
@ -74,7 +78,7 @@ class Silver
'time_end' => self::$task['time_end'],
'time_start' => self::$task['time_start']
];
$data = Curl::get('app',$url, Sign::common($payload));
$data = Curl::get('app', $url, Sign::common($payload));
$data = json_decode($data, true);
if ($data['code'] == -800) {

View File

@ -24,7 +24,7 @@ class Silver2Coin
return;
}
if (self::appSilver2coin() && self::pcSilver2coin()) {
self::setLock(24 * 60 * 60);
self::setLock(self::timing(10));
return;
}
self::setLock(3600);

View File

@ -51,7 +51,7 @@ class StormRaffle extends BaseRaffle
}
// 过滤抽奖范围
self::$drop_rate = getenv('STORM_DROPRATE') !== "" ? (int)getenv('STORM_DROPRATE') : 0;
if (random_int(1, 100) <= (int)self::$drop_rate) {
if (mt_rand(1, 100) <= (int)self::$drop_rate) {
return false;
}
// 去重
@ -88,7 +88,6 @@ class StormRaffle extends BaseRaffle
* @use 创建抽奖任务
* @param array $raffles
* @return array
* @throws \Exception
*/
protected static function createLottery(array $raffles): array
{
@ -96,7 +95,7 @@ class StormRaffle extends BaseRaffle
$user_info = User::parseCookies();
foreach ($raffles as $raffle) {
self::$attempt = getenv('STORM_ATTEMPT') !== "" ? explode(',', getenv('STORM_ATTEMPT')) : [30, 50];
$num = random_int((int)self::$attempt[0], (int)self::$attempt[1]);
$num = mt_rand((int)self::$attempt[0], (int)self::$attempt[1]);
$payload = [
'id' => $raffle['raffle_id'],
'roomid' => $raffle['room_id'],

View File

@ -10,18 +10,14 @@
namespace BiliHelper\Plugin;
use BiliHelper\Core\Log;
use BiliHelper\Core\Curl;
use BiliHelper\Util\TimeLock;
use BiliHelper\Core\Config;
class User
{
/**
* @use 实名检测
* @return bool
* @throws \Exception
*/
public static function realNameCheck(): bool
{
@ -40,7 +36,6 @@ class User
/**
* @use 老爷检测
* @return bool
* @throws \Exception
*/
public static function isMaster(): bool
{
@ -57,7 +52,6 @@ class User
/**
* @use 写入用户名
* @return bool
* @throws \Exception
*/
public static function userInfo(): bool
{
@ -87,11 +81,11 @@ class User
return json_decode($raw, true);
}
/**
* @use Web User
* @param null $room_id
* @return mixed
* @throws \Exception
*/
public static function webGetUserInfo($room_id = null)
{

View File

@ -310,7 +310,7 @@ class ZoneTcpClient
private static function genHandshakePkg($room_id): string
{
return self::packMsg(json_encode([
'uid' => random_int(1000000, 2999999),
'uid' => mt_rand(1000000, 2999999),
'roomid' => intval($room_id),
]), 0x0007);
}

View File

@ -15,7 +15,6 @@ trait TimeLock
{
public static $lock = 0;
/**
* @use 设置时间
* @param int $lock
@ -25,7 +24,6 @@ trait TimeLock
static::$lock = time() + $lock;
}
/**
* @use 获取时间
* @return int
@ -35,4 +33,15 @@ trait TimeLock
return static::$lock;
}
/**
* @use 定时
* @param int $hour
* @return int
*/
public static function timing(int $hour): int
{
// now today tomorrow yesterday
return strtotime('tomorrow') + ($hour * 60 * 60) - time();
}
}