Skip to content

Commit

Permalink
[fix] Curl fixes lkeme#21
Browse files Browse the repository at this point in the history
  • Loading branch information
lkeme committed Mar 18, 2020
1 parent 418ea70 commit 63c67be
Show file tree
Hide file tree
Showing 25 changed files with 114 additions and 93 deletions.
23 changes: 22 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
- 添加异常处理(通知)
Expand Down
50 changes: 25 additions & 25 deletions DOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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 |数据统计 |

## 打赏赞助

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

## 打赏

Expand Down
4 changes: 2 additions & 2 deletions src/core/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function newTask(string $taskName)
} 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);
}
Expand All @@ -73,7 +73,7 @@ public function start()
{
$plugins = [
'Login',
'Sleep',
'Schedule',
'MasterSite',
'Daily',
'ManGa',
Expand Down
19 changes: 11 additions & 8 deletions src/core/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,28 +168,31 @@ private static function countedAndCheckEnded()
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('网络异常,超出最大尝试次数,退出程序~');
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static function callback($levelId, $level, $message)
$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);
}
}
}
2 changes: 1 addition & 1 deletion src/plugin/AnchorRaffle.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected static function parseLotteryInfo(int $room_id, array $data): bool
'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);
Expand Down
7 changes: 2 additions & 5 deletions src/plugin/Barrage.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function run()
];

if (self::privateSendMsg($info)) {
self::setLock(3600);
self::setLock(mt_rand(15, 30) * 60);
return;
}

Expand All @@ -42,7 +42,7 @@ public static function run()

/**
* @use 获取随机弹幕
* @return \Exception|false|mixed|string
* @return \Exception|false|mixed|string|null
*/
private static function getMsgInfo()
{
Expand All @@ -53,15 +53,12 @@ private static function getMsgInfo()
*/
$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',
Expand Down
1 change: 0 additions & 1 deletion src/plugin/GiftHeart.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public static function run()
/**
* @use 礼物心跳
* @return bool
* @throws \Exception
*/
private static function giftHeart(): bool
{
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/GroupSignIn.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static function run()

$groups = self::getGroupList();
if (empty($groups)) {
self::setLock(24 * 60 * 60);
self::setLock(self::timing(10));
return;
}

Expand Down
3 changes: 1 addition & 2 deletions src/plugin/GuardRaffle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -73,7 +72,7 @@ protected static function parseLotteryInfo(int $room_id, array $data): bool
'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);
Expand Down
11 changes: 9 additions & 2 deletions src/plugin/Heart.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ public static function run()
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']) {
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/Judge.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private static function caseObtain()
// {"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']) {
Expand Down
8 changes: 1 addition & 7 deletions src/plugin/Live.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class Live
/**
* @use 获取分区列表
* @return array
* @throws \Exception
*/
public static function fetchLiveAreas(): array
{
Expand All @@ -47,7 +46,6 @@ public static function fetchLiveAreas(): array
* @use AREA_ID转ROOM_ID
* @param $area_id
* @return array
* @throws \Exception
*/
public static function areaToRid($area_id): array
{
Expand Down Expand Up @@ -83,7 +81,6 @@ public static function areaToRid($area_id): array
/**
* @use 获取随机直播房间号
* @return int
* @throws \Exception
*/
public static function getUserRecommend()
{
Expand All @@ -99,15 +96,14 @@ public static function getUserRecommend()
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'];
}


/**
* @use 获取直播房间号
* @param $room_id
* @return bool
* @throws \Exception
*/
public static function getRealRoomID($room_id)
{
Expand Down Expand Up @@ -151,7 +147,6 @@ public static function getRoomInfo($room_id): array
* @use 钓鱼检测
* @param $room_id
* @return bool
* @throws \Exception
*/
public static function fishingDetection($room_id): bool
{
Expand All @@ -166,7 +161,6 @@ public static function fishingDetection($room_id): bool
* @use 访问直播间
* @param $room_id
* @return bool
* @throws \Exception
*/
public static function goToRoom($room_id): bool
{
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/ManGa.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static function run()
return;
}
if (self::sign() && self::share()) {
self::setLock(24 * 60 * 60);
self::setLock(self::timing(10));
return;
}
self::setLock(3600);
Expand Down
Loading

0 comments on commit 63c67be

Please sign in to comment.