[add] anchor

This commit is contained in:
Lkeme 2019-12-23 14:24:37 +08:00
parent 17e105e5b0
commit ade3acb6d8
38 changed files with 229 additions and 99 deletions

View File

@ -1,6 +1,18 @@
# Release Notes # Release Notes
# 本项目Log # 本项目Log
## v0.0.1.191223 alpha (2019-12-23)
### Added
- anchor(beta)
-
### Changed
-
### Fixed
-
## v0.0.1.191030 alpha (2019-10-30) ## v0.0.1.191030 alpha (2019-10-30)
### Added ### Added

35
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.0.1.190713 alpha-green.svg?longCache=true&style=for-the-badge"> <img src="https://img.shields.io/badge/version-0.0.1.191213 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>
@ -17,22 +17,23 @@ B 站直播实用脚本
|plugin |version |description | |plugin |version |description |
|--------------------|--------------------|--------------------| |--------------------|--------------------|--------------------|
|Daily |19.07.13 |每日背包奖励 | |Daily |19.12.23 |每日背包奖励 |
|GiftSend |19.07.13 |自动清空过期礼物 | |GiftSend |19.12.23 |自动清空过期礼物 |
|Heart |19.07.13 |双端直播间心跳 | |Heart |19.12.23 |双端直播间心跳 |
|Login |19.07.13 |帐号登录组件 | |Login |19.12.23 |帐号登录组件 |
|Silver |19.07.13 |自动领宝箱 | |Silver |19.12.23 |自动领宝箱 |
|Task |19.07.13 |每日任务 | |Task |19.12.23 |每日任务 |
|GiftHeart |19.07.13 |心跳礼物 | |GiftHeart |19.12.23 |心跳礼物 |
|Silver2Coin |19.07.13 |银瓜子换硬币 | |Silver2Coin |19.12.23 |银瓜子换硬币 |
|MaterialObject |19.07.13 |实物抽奖 | |MaterialObject |19.12.23 |实物抽奖 |
|GroupSignIn |19.07.13 |应援团签到 | |GroupSignIn |19.12.23 |应援团签到 |
|Storm |19.07.13 |节奏风暴 | |Storm |19.12.23 |节奏风暴 |
|Notice |19.07.13 |Server酱 | |Notice |19.12.23 |Server酱 |
|UnifyRaffle |19.07.23 |统一活动抽奖 | |UnifyRaffle |19.12.23 |统一活动抽奖 |
|MasterSite |19.07.13 |主站(观看、分享、投币)| |MasterSite |19.12.23 |主站(观看、分享、投币)|
|Guard |19.07.23 |舰长上船亲密度 | |Guard |19.12.23 |舰长上船亲密度 |
|PkRaffle |19.07.23 |大乱斗 | |PkRaffle |19.12.23 |大乱斗 |
|Anchor |19.12.23 |天选时刻 |
## 打赏赞助 ## 打赏赞助

View File

@ -7,7 +7,7 @@ Group: [55308141](https://jq.qq.com/?_wv=1027&k=5AIDaJg)
## 公告 ## 公告
Currently for Personal Edition **0.0.1.190822 alpha** Currently for Personal Edition **0.0.1.191213 alpha**
## 文档 ## 文档

View File

@ -13,7 +13,7 @@
"vlucas/phpdotenv": "^2.4", "vlucas/phpdotenv": "^2.4",
"monolog/monolog": "^1.23", "monolog/monolog": "^1.23",
"bramus/monolog-colored-line-formatter": "^2.0", "bramus/monolog-colored-line-formatter": "^2.0",
"clue/socket-raw": "1.4" "clue/socket-raw": "^1.4.1"
}, },
"license": "MIT", "license": "MIT",
"authors": [ "authors": [

68
composer.lock generated
View File

@ -4,20 +4,20 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "6fca2d61232110e041d8cb569c30d02f", "content-hash": "d09e06835f7ff6a06fcb74285e6617c5",
"packages": [ "packages": [
{ {
"name": "bramus/ansi-php", "name": "bramus/ansi-php",
"version": "3.0.2", "version": "3.0.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/bramus/ansi-php.git", "url": "https://github.com/bramus/ansi-php.git",
"reference": "79d30c30651b0c6f23cf85503c779c72ac74ab8a" "reference": "fb0be33f36053af7454d462e3ddc0a2ac0b2f311"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/bramus/ansi-php/zipball/79d30c30651b0c6f23cf85503c779c72ac74ab8a", "url": "https://api.github.com/repos/bramus/ansi-php/zipball/fb0be33f36053af7454d462e3ddc0a2ac0b2f311",
"reference": "79d30c30651b0c6f23cf85503c779c72ac74ab8a", "reference": "fb0be33f36053af7454d462e3ddc0a2ac0b2f311",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -50,7 +50,7 @@
} }
], ],
"description": "ANSI Control Functions and ANSI Control Sequences (Colors, Erasing, etc.) for PHP CLI Apps", "description": "ANSI Control Functions and ANSI Control Sequences (Colors, Erasing, etc.) for PHP CLI Apps",
"time": "2019-02-12T15:05:30+00:00" "time": "2019-12-03T09:04:38+00:00"
}, },
{ {
"name": "bramus/monolog-colored-line-formatter", "name": "bramus/monolog-colored-line-formatter",
@ -102,16 +102,16 @@
}, },
{ {
"name": "clue/socket-raw", "name": "clue/socket-raw",
"version": "v1.4.0", "version": "v1.4.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/clue/php-socket-raw.git", "url": "https://github.com/clue/php-socket-raw.git",
"reference": "2f6654445233407900c9a804490cecd8e4f2ae86" "reference": "00ab102d061f6cdb895e79dd4d69140c7bda31cc"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/clue/php-socket-raw/zipball/2f6654445233407900c9a804490cecd8e4f2ae86", "url": "https://api.github.com/repos/clue/php-socket-raw/zipball/00ab102d061f6cdb895e79dd4d69140c7bda31cc",
"reference": "2f6654445233407900c9a804490cecd8e4f2ae86", "reference": "00ab102d061f6cdb895e79dd4d69140c7bda31cc",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -140,10 +140,10 @@
"authors": [ "authors": [
{ {
"name": "Christian Lück", "name": "Christian Lück",
"email": "christian@lueck.tv" "email": "christian@clue.engineering"
} }
], ],
"description": "Simple and lightweight OOP wrapper for PHP's low level sockets extension (ext-sockets)", "description": "Simple and lightweight OOP wrapper for PHP's low-level sockets extension (ext-sockets)",
"homepage": "https://github.com/clue/php-socket-raw", "homepage": "https://github.com/clue/php-socket-raw",
"keywords": [ "keywords": [
"Socket", "Socket",
@ -159,20 +159,20 @@
"udp", "udp",
"unix" "unix"
], ],
"time": "2019-01-22T11:08:01+00:00" "time": "2019-10-28T12:32:07+00:00"
}, },
{ {
"name": "monolog/monolog", "name": "monolog/monolog",
"version": "1.24.0", "version": "1.25.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/Seldaek/monolog.git", "url": "https://github.com/Seldaek/monolog.git",
"reference": "bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266" "reference": "fa82921994db851a8becaf3787a9e73c5976b6f1"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266", "url": "https://api.github.com/repos/Seldaek/monolog/zipball/fa82921994db851a8becaf3787a9e73c5976b6f1",
"reference": "bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266", "reference": "fa82921994db851a8becaf3787a9e73c5976b6f1",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -243,20 +243,20 @@
"logging", "logging",
"psr-3" "psr-3"
], ],
"time": "2018-11-05T09:00:11+00:00" "time": "2019-12-20T14:15:16+00:00"
}, },
{ {
"name": "psr/log", "name": "psr/log",
"version": "1.1.0", "version": "1.1.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/php-fig/log.git", "url": "https://github.com/php-fig/log.git",
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd" "reference": "446d54b4cb6bf489fc9d75f55843658e6f25d801"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", "url": "https://api.github.com/repos/php-fig/log/zipball/446d54b4cb6bf489fc9d75f55843658e6f25d801",
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", "reference": "446d54b4cb6bf489fc9d75f55843658e6f25d801",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -271,7 +271,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.0.x-dev" "dev-master": "1.1.x-dev"
} }
}, },
"autoload": { "autoload": {
@ -296,20 +296,20 @@
"psr", "psr",
"psr-3" "psr-3"
], ],
"time": "2018-11-20T15:27:04+00:00" "time": "2019-11-01T11:05:21+00:00"
}, },
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
"version": "v1.11.0", "version": "v1.13.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git", "url": "https://github.com/symfony/polyfill-ctype.git",
"reference": "82ebae02209c21113908c229e9883c419720738a" "reference": "f8f0b461be3385e56d6de3dbb5a0df24c0c275e3"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/82ebae02209c21113908c229e9883c419720738a", "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/f8f0b461be3385e56d6de3dbb5a0df24c0c275e3",
"reference": "82ebae02209c21113908c229e9883c419720738a", "reference": "f8f0b461be3385e56d6de3dbb5a0df24c0c275e3",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -327,7 +327,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.11-dev" "dev-master": "1.13-dev"
} }
}, },
"autoload": { "autoload": {
@ -343,13 +343,13 @@
"MIT" "MIT"
], ],
"authors": [ "authors": [
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
},
{ {
"name": "Gert de Pagter", "name": "Gert de Pagter",
"email": "BackEndTea@gmail.com" "email": "BackEndTea@gmail.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
} }
], ],
"description": "Symfony polyfill for ctype functions", "description": "Symfony polyfill for ctype functions",
@ -360,7 +360,7 @@
"polyfill", "polyfill",
"portable" "portable"
], ],
"time": "2019-02-06T07:57:58+00:00" "time": "2019-11-27T13:56:44+00:00"
}, },
{ {
"name": "vlucas/phpdotenv", "name": "vlucas/phpdotenv",

View File

@ -44,15 +44,19 @@ SOCKET_ROOM_ID=9522051
# 主站助手 # 主站助手
USE_MASTER_SITE=true USE_MASTER_SITE=true
# 舰长总督
USE_GUARD=true
# 统一活动 # 统一活动
USE_ACTIVE=true USE_ACTIVE=true
# 舰长总督
USE_GUARD=true
# 大乱斗 # 大乱斗
USE_PK=true USE_PK=true
# 天选时刻|抽取类型(0: 无限制; 1: 关注主播; 2: 粉丝勋章; 3大航海 4用户等级5主站等级)|逗号分隔
USE_ANCHOR=false
ANCHOR_TYPE=0,1
# 实物抽奖 # 实物抽奖
USE_MO=true USE_MO=true
@ -93,7 +97,7 @@ APP_UNAME=
# 多账号区别输出 # 多账号区别输出
APP_MULTIPLE=false APP_MULTIPLE=false
# 账号别名,如果为空则默认使用登账号作为标示 # 账号别名,如果为空则默认使用登账号作为标示
APP_USER_IDENTITY= APP_USER_IDENTITY=
# 日志回调地址 # 日志回调地址

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;
@ -54,8 +54,9 @@ class Index
PkRaffle::run(); PkRaffle::run();
UnifyRaffle::run(); UnifyRaffle::run();
Guard::run(); Guard::run();
Anchor::run();
Statistics::run(); Statistics::run();
usleep(0.1 * 1000000); usleep(0.2 * 1000000);
} }
} }

95
src/Anchor.php Normal file
View File

@ -0,0 +1,95 @@
<?php
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2019 ~ 2020
*/
namespace lkeme\BiliHelper;
class Anchor extends BaseRaffle
{
const ACTIVE_TITLE = '天选时刻';
const ACTIVE_SWITCH = 'USE_ANCHOR';
public static $lock = 0;
public static $rw_lock = 0;
protected static $wait_list = [];
protected static $finish_list = [];
protected static $all_list = [];
private static $filter_type = [];
/**
* 检查抽奖列表
* @param $rid
* @return bool
*/
protected static function check($rid): bool
{
$payload = [
'roomid' => $rid
];
$url = 'https://api.live.bilibili.com/xlive/lottery-interface/v1/Anchor/Check';
$raw = Curl::get($url, Sign::api($payload));
$de_raw = json_decode($raw, true);
// 防止异常情况
if (!isset($de_raw['data']) || $de_raw['data']['join_type'] || $de_raw['data']['lot_status']) {
return false;
}
// TODO
self::$filter_type = empty(self::$filter_type) ? explode(',', getenv('ANCHOR_TYPE')) : self::$filter_type;
if (!in_array((string)$de_raw['data']['require_type'], self::$filter_type)) {
return false;
}
$data = [
'room_id' => $de_raw['data']['room_id'],
'raffle_id' => $de_raw['data']['id'],
'prize' => $de_raw['data']['award_name'],
'wait' => strtotime(date("Y-m-d H:i:s"))
];
if (static::toRepeatLid($data['raffle_id'])) {
return false;
}
Statistics::addPushList(static::ACTIVE_TITLE);
array_push(static::$wait_list, $data);
return true;
}
/**
* @use 请求抽奖
* @param array $data
* @return bool
*/
protected static function lottery(array $data): bool
{
$user_info = User::parseCookies();
$payload = [
'id' => $data['raffle_id'],
'roomid' => $data['room_id'],
'platform' => 'pc',
'csrf_token' => $user_info['token'],
'csrf' => $user_info['token'],
'visit_id' => '',
];
$url = 'https://api.live.bilibili.com/xlive/lottery-interface/v1/Anchor/Join';
$raw = Curl::post($url, Sign::api($payload));
$de_raw = json_decode($raw, true);
if (isset($de_raw['code']) && $de_raw['code'] == 0) {
print_r($de_raw);
Statistics::addSuccessList(static::ACTIVE_TITLE);
Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . static::ACTIVE_TITLE . ": {$data['prize']}");
} else {
Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . static::ACTIVE_TITLE . ": {$de_raw['message']}");
}
return true;
}
}

View File

@ -6,7 +6,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;
@ -46,6 +46,10 @@ class DataTreating
// 乱斗 // 乱斗
PkRaffle::pushToQueue($info); PkRaffle::pushToQueue($info);
break; break;
case 'anchor':
// 天选时刻
Anchor::pushToQueue($info);
break;
default: default:
break; break;
} }

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -4,7 +4,7 @@
* Website: https://mudew.com/ * Website: https://mudew.com/
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;
@ -134,6 +134,11 @@ class Login
$headers = $captcha_data['headers']; $headers = $captcha_data['headers'];
continue; continue;
} }
// https://passport.bilibili.com/mobile/verifytel_h5.html
if (!$data['code'] && $data['data']['status']) {
Log::error('登录失败', ['msg' => '登录异常, 账号启用了设备锁或异地登录需验证手机!']);
die();
}
break; break;
} }
if (isset($data['code']) && $data['code']) { if (isset($data['code']) && $data['code']) {
@ -155,10 +160,10 @@ class Login
protected static function loginWithCaptcha() protected static function loginWithCaptcha()
{ {
Log::info('登陆需要验证 ,启动验证码登陆!'); Log::info('登录需要验证, 启动验证码登录!');
$headers = [ $headers = [
'Accept' => 'application/json, text/plain, */*', 'Accept' => 'application/json, text/plain, */*',
'User-Agent' => 'bili-universal/8230 CFNetwork/975.0.3 Darwin/18.2.0', 'User-Agent' => 'bili-universal/8470 CFNetwork/978.0.7 Darwin/18.5.0',
'Host' => 'passport.bilibili.com', 'Host' => 'passport.bilibili.com',
'Cookie' => 'sid=blhelper' 'Cookie' => 'sid=blhelper'
]; ];

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;
@ -65,7 +65,7 @@ class Task
} else { } else {
Log::info('签到成功'); Log::info('签到成功');
// 推送签到信息 // 推送签到信息
Notice::run('todaySign', $data['msg']); Notice::run('todaySign', $data['message']);
} }
} }

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;
@ -20,6 +20,7 @@ class TcpClient
private static $client = null; private static $client = null;
private static $server_addr = null; private static $server_addr = null;
private static $server_key = null; private static $server_key = null;
private static $socket_timeout = 0;
/** /**
* @desc 入口 * @desc 入口
@ -102,7 +103,7 @@ class TcpClient
if (self::$heart_lock <= time()) { if (self::$heart_lock <= time()) {
if (self::writer("")) { if (self::writer("")) {
// 心跳默认35s 调整数据错开错误 // 心跳默认35s 调整数据错开错误
self::$heart_lock = time() + 20; self::$heart_lock = time() + 25;
} }
} }
} }
@ -116,11 +117,14 @@ class TcpClient
{ {
$data = false; $data = false;
try { try {
$data = self::$client->read($length); while (self::$client->selectRead(self::$socket_timeout)) {
if (!$data) { $data = self::$client->read($length);
throw new Exception("Connection failure"); if (!$data) {
throw new Exception("Connection failure");
}
if ($length == 4) $data = self::unPackMsg($data);
break;
} }
if ($length == 4) $data = self::unPackMsg($data);
} catch (Exception $exception) { } catch (Exception $exception) {
self::reConnect(); self::reConnect();
} }
@ -136,8 +140,11 @@ class TcpClient
{ {
$status = false; $status = false;
try { try {
$data = self::packMsg($data); while (self::$client->selectWrite(self::$socket_timeout)) {
$status = self::$client->write($data); $data = self::packMsg($data);
$status = self::$client->write($data);
break;
}
} catch (Exception $exception) { } catch (Exception $exception) {
self::reConnect(); self::reConnect();
} }
@ -153,6 +160,7 @@ class TcpClient
if (!self::$client) { if (!self::$client) {
try { try {
$socket = (new Factory())->createClient(self::$server_addr, 40); $socket = (new Factory())->createClient(self::$server_addr, 40);
$socket->setBlocking(false);
self::$client = $socket; self::$client = $socket;
self::handShake(); self::handShake();
Log::info("连接到 {$socket->getPeerName()} 推送服务器"); Log::info("连接到 {$socket->getPeerName()} 推送服务器");

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;

View File

@ -5,7 +5,7 @@
* Author: Lkeme * Author: Lkeme
* License: The MIT License * License: The MIT License
* Email: Useri@live.cn * Email: Useri@live.cn
* Updated: 2019 * Updated: 2019 ~ 2020
*/ */
namespace lkeme\BiliHelper; namespace lkeme\BiliHelper;