[fix] Curl fixes #21

This commit is contained in:
Lkeme 2020-03-18 14:32:06 +08:00
parent 5b0ef903a7
commit aef330a8f3
25 changed files with 114 additions and 93 deletions

View File

@ -1,7 +1,28 @@
# Release Notes # Release Notes
# 本项目Log # 本项目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 ### 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 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.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"> <img src="https://img.shields.io/badge/license-mit-blue.svg?longCache=true&style=for-the-badge">
</p> </p>
@ -15,30 +15,30 @@ B 站直播实用脚本
|plugin |version |description | |plugin |version |description |
|--------------------|--------------------|--------------------| |--------------------|--------------------|--------------------|
|Login |20.03.16 |账号登录 | |Login |20.03.18 |账号登录 |
|Sleep |20.03.16 |休眠控制 | |Schedule |20.03.18 |休眠控制 |
|MasterSite |20.03.16 |主站助手 | |MasterSite |20.03.18 |主站助手 |
|Daily |20.03.16 |每日礼包 | |Daily |20.03.18 |每日礼包 |
|Heart |20.03.16 |双端心跳 | |Heart |20.03.18 |双端心跳 |
|Task |20.03.16 |每日任务 | |Task |20.03.18 |每日任务 |
|Silver |20.03.16 |银瓜子宝箱 | |Silver |20.03.18 |银瓜子宝箱 |
|Barrage |20.03.16 |活跃弹幕 | |Barrage |20.03.18 |活跃弹幕 |
|Silver2Coin |20.03.16 |银瓜子换硬币 | |Silver2Coin |20.03.18 |银瓜子换硬币 |
|GiftSend |20.03.16 |礼物赠送 | |GiftSend |20.03.18 |礼物赠送 |
|Judge |20.03.16 |风纪 | |Judge |20.03.18 |风纪 |
|GroupSignIn |20.03.16 |友爱社签到 | |GroupSignIn |20.03.18 |友爱社签到 |
|ManGa |20.03.16 |漫画签到分享 | |ManGa |20.03.18 |漫画签到分享 |
|GiftHeart |20.03.16 |心跳礼物 | |GiftHeart |20.03.18 |心跳礼物 |
|MaterialObject |20.03.16 |实物抽奖 | |MaterialObject |20.03.18 |实物抽奖 |
|AloneTcpClient |20.03.16 |独立监控 | |AloneTcpClient |20.03.18 |独立监控 |
|ZoneTcpClient |20.03.16 |分区监控 | |ZoneTcpClient |20.03.18 |分区监控 |
|StormRaffle |20.03.16 |节奏风暴 | |StormRaffle |20.03.18 |节奏风暴 |
|GiftRaffle |20.03.16 |活动礼物 | |GiftRaffle |20.03.18 |活动礼物 |
|PkRaffle |20.03.16 |大乱斗 | |PkRaffle |20.03.18 |大乱斗 |
|GuardRaffle |20.03.16 |舰长总督 | |GuardRaffle |20.03.18 |舰长总督 |
|AnchorRaffle |20.03.16 |天选时刻 | |AnchorRaffle |20.03.18 |天选时刻 |
|AwardRecord |20.03.16 |获奖通知 | |AwardRecord |20.03.18 |获奖通知 |
|Statistics |20.03.16 |数据统计 | |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) * [使用文档 / DOC.md](./DOC.md)
* [更新日志 / CHANGELOG.md](./CHANGELOG.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) { } catch (\Throwable $e) {
$error_msg = "MSG: {$e->getMessage()} CODE: {$e->getCode()} FILE: {$e->getFile()} LINE: {$e->getLine()}"; $error_msg = "MSG: {$e->getMessage()} CODE: {$e->getCode()} FILE: {$e->getFile()} LINE: {$e->getLine()}";
Log::error($error_msg); Log::error($error_msg);
Notice::push('error', $error_msg); // Notice::push('error', $error_msg);
} }
yield new Delayed(1000); yield new Delayed(1000);
} }
@ -73,7 +73,7 @@ class App
{ {
$plugins = [ $plugins = [
'Login', 'Login',
'Sleep', 'Schedule',
'MasterSite', 'MasterSite',
'Daily', 'Daily',
'ManGa', 'ManGa',

View File

@ -168,28 +168,31 @@ class Curl
self::$async_opt = []; self::$async_opt = [];
} }
/** /**
* @use 请求中心异常处理 * @use 请求中心异常处理
* @param string $url * @param string $url
* @param string $method * @param string $method
* @param array $options * @param array $options
* @return mixed * @return mixed
* @throws \Exception
*/ */
private static function clientHandle(string $url, string $method, array $options) 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) { foreach ($max_retry as $retry) {
try { 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) { } catch (\GuzzleHttp\Exception\RequestException $e) {
Log::warning("CURl -> RETRY: {$retry} ERROR: {$e->getMessage()} ERRNO: {$e->getCode()}");
// var_dump($e->getRequest()); // var_dump($e->getRequest());
if ($e->hasResponse()) { if ($e->hasResponse()) var_dump($e->getResponse());
var_dump($e->getResponse()); } catch (\Exception $e) {
} // var_dump($e);
Log::warning("尝试重试第 {$retry} 次,等待网络恢复...");
sleep(10);
} }
Log::warning("CURl -> RETRY: {$retry} ERROR: {$e->getMessage()} ERRNO: {$e->getCode()} STATUS: Waiting for recovery!");
sleep(15);
} }
exit('网络异常,超出最大尝试次数,退出程序~'); exit('网络异常,超出最大尝试次数,退出程序~');
} }

View File

@ -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('other', $url); Curl::request('get', $url);
} }
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -34,11 +34,18 @@ class Heart
protected static function webHeart() protected static function webHeart()
{ {
User::webGetUserInfo(); 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 = [ $payload = [
'csrf' => $user_info['token'],
'csrf_token' => $user_info['token'],
'room_id' => getenv('ROOM_ID'), '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); $data = json_decode($data, true);
if (isset($data['code']) && $data['code']) { if (isset($data['code']) && $data['code']) {

View File

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

View File

@ -21,7 +21,6 @@ class Live
/** /**
* @use 获取分区列表 * @use 获取分区列表
* @return array * @return array
* @throws \Exception
*/ */
public static function fetchLiveAreas(): array public static function fetchLiveAreas(): array
{ {
@ -47,7 +46,6 @@ class Live
* @use AREA_ID转ROOM_ID * @use AREA_ID转ROOM_ID
* @param $area_id * @param $area_id
* @return array * @return array
* @throws \Exception
*/ */
public static function areaToRid($area_id): array public static function areaToRid($area_id): array
{ {
@ -83,7 +81,6 @@ class Live
/** /**
* @use 获取随机直播房间号 * @use 获取随机直播房间号
* @return int * @return int
* @throws \Exception
*/ */
public static function getUserRecommend() public static function getUserRecommend()
{ {
@ -99,7 +96,7 @@ class Live
if ($de_raw['code'] != '0') { if ($de_raw['code'] != '0') {
return 23058; 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 获取直播房间号 * @use 获取直播房间号
* @param $room_id * @param $room_id
* @return bool * @return bool
* @throws \Exception
*/ */
public static function getRealRoomID($room_id) public static function getRealRoomID($room_id)
{ {
@ -151,7 +147,6 @@ 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
{ {
@ -166,7 +161,6 @@ class Live
* @use 访问直播间 * @use 访问直播间
* @param $room_id * @param $room_id
* @return bool * @return bool
* @throws \Exception
*/ */
public static function goToRoom($room_id): bool public static function goToRoom($room_id): bool
{ {

View File

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

View File

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

View File

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

View File

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

View File

@ -15,13 +15,13 @@ use BiliHelper\Core\Curl;
use BiliHelper\Util\TimeLock; use BiliHelper\Util\TimeLock;
class Sleep class Schedule
{ {
use TimeLock; use TimeLock;
// 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', '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 $guarded = ['Barrage', 'GiftHeart', 'Heart', 'Silver', 'MaterialObject', 'AloneTcpClient', 'ZoneTcpClient', 'StormRaffle', 'GuardRaffle', 'PkRaffle', 'GiftRaffle', 'AnchorRaffle'];
private static $sleep_section = []; private static $sleep_section = [];

View File

@ -44,7 +44,11 @@ class Silver
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); if (User::isMaster()) {
self::setLock(self::timing(6));
} else {
self::setLock(self::timing(10));
}
return; return;
} }
@ -74,7 +78,7 @@ class Silver
'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('app',$url, Sign::common($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) {

View File

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

View File

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

View File

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

View File

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

View File

@ -15,7 +15,6 @@ trait TimeLock
{ {
public static $lock = 0; public static $lock = 0;
/** /**
* @use 设置时间 * @use 设置时间
* @param int $lock * @param int $lock
@ -25,7 +24,6 @@ trait TimeLock
static::$lock = time() + $lock; static::$lock = time() + $lock;
} }
/** /**
* @use 获取时间 * @use 获取时间
* @return int * @return int
@ -35,4 +33,15 @@ trait TimeLock
return static::$lock; 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();
}
} }