From e37434e3c8c0c245297b8d313d2158da4112b418 Mon Sep 17 00:00:00 2001 From: Lkeme <19500576+lkeme@users.noreply.github.com> Date: Sun, 7 Aug 2022 15:59:02 +0800 Subject: [PATCH] [feat] Common --- .github/FUNDING.yml | 12 + .github/ISSUE_TEMPLATE/ISSUE_TEMPLATE_CN.md | 47 ++++ .github/ISSUE_TEMPLATE/ISSUE_TEMPLATE_EN.md | 47 ++++ .github/workflows/build_image_bhp.yml | 22 ++ plugin/BpConsumption/BpConsumption.php | 8 +- plugin/CheckUpdate/CheckUpdate.php | 30 +- plugin/GameForecast/GameForecast.php | 10 +- plugin/Judge/Judge.php | 24 +- plugin/LiveGoldBox/LiveGoldBox.php | 14 +- plugin/LiveReservation/LiveReservation.php | 8 +- plugin/LiveSignIn/LiveSignIn.php | 2 +- plugin/Login/Login.php | 138 +++++---- plugin/LoveClub/LoveClub.php | 6 +- plugin/MainSite/MainSite.php | 29 +- plugin/Manga/Manga.php | 8 +- plugin/PluginTemplate/PluginTemplate.php | 2 +- plugin/Silver2Coin/Silver2Coin.php | 6 +- plugin/VipPrivilege/VipPrivilege.php | 8 +- profile/example/config/user.ini | 2 +- profile/example/device/device.yaml | 4 +- src/Api/Credit/ApiJury.php | 14 +- src/Api/Custom/ApiCalcSign.php | 66 +++++ src/Api/DynamicSvr/ApiDynamicSvr.php | 2 +- src/Api/Esports/ApiGuess.php | 4 +- src/Api/LinkGroup/ApiLoveClub.php | 2 +- src/Api/Manga/ApiManga.php | 6 +- src/Api/Passport/ApiCaptcha.php | 4 +- src/Api/Passport/ApiLogin.php | 8 +- src/Api/Passport/ApiOauth2.php | 39 ++- src/Api/PassportTv/ApiQrcode.php | 8 +- src/Api/Pay/ApiPay.php | 4 +- src/Api/Pay/ApiWallet.php | 2 +- src/Api/Space/ApiReservation.php | 4 +- src/Api/Video/ApiCoin.php | 6 +- src/Api/Video/ApiShare.php | 2 +- src/Api/Video/ApiVideo.php | 4 +- src/Api/Video/ApiWatch.php | 4 +- src/Api/Vip/ApiPrivilege.php | 4 +- src/Api/Vip/ApiUser.php | 2 +- src/Api/XLive/ApiRevenueWallet.php | 8 +- src/Api/XLive/ApiXLiveSign.php | 4 +- src/Api/XLive/AppUcenter/V1/ApiFansMedal.php | 44 +++ .../V1/HeartBeat/ApiHeartBeat.php | 96 +++++++ src/Api/XLive/LotteryInterface/V2/ApiBox.php | 4 +- src/Api/XLive/WebRoom/V1/Index/ApiIndex.php | 38 +++ src/Bootstrap/Bootstrap.php | 8 +- src/Cache/Cache.php | 14 +- src/Config/Config.php | 2 +- src/Console/Console.php | 2 +- src/Device/Device.php | 6 +- src/Env/Env.php | 8 +- src/FilterWords/FilterWords.php | 2 +- src/Helpers.php | 24 +- src/Log/Log.php | 22 +- src/Notice/Notice.php | 30 +- src/Plugin/BasePluginInfo.php | 14 +- src/Plugin/Plugin.php | 23 +- src/Request/Request.php | 47 ++-- src/Schedule/Schedule.php | 109 ++++++++ src/Sign/Sign.php | 25 +- src/TaskQueue/TaskQueue.php | 120 ++++++++ src/TimeLock/TimeLock.php | 34 ++- src/User/User.php | 4 +- src/Util/ArrayR/ArrayR.php | 2 +- src/Util/AsciiTable/AsciiTable.php | 2 +- src/Util/Common/Common.php | 43 ++- src/Util/DesignPattern/SingleTon.php | 8 +- src/Util/Fake/Fake.php | 10 +- src/Util/Fake/Faker.php | 2 +- src/Util/Os/File.php | 263 ++++++++++++++++++ src/Util/Os/Path.php | 4 +- src/Util/Qrcode/Lib/QrRawCode.php | 24 +- src/Util/Qrcode/Lib/QrTools.php | 2 +- src/Util/Qrcode/Qrcode.php | 4 +- src/Util/Resource/BaseResource.php | 22 +- src/Util/Resource/BaseResourcePoly.php | 22 +- src/Util/Resource/Resource.php | 6 +- src/core/Core.php | 6 +- 78 files changed, 1345 insertions(+), 375 deletions(-) create mode 100644 .github/FUNDING.yml create mode 100644 .github/ISSUE_TEMPLATE/ISSUE_TEMPLATE_CN.md create mode 100644 .github/ISSUE_TEMPLATE/ISSUE_TEMPLATE_EN.md create mode 100644 .github/workflows/build_image_bhp.yml create mode 100644 src/Api/Custom/ApiCalcSign.php create mode 100644 src/Api/XLive/AppUcenter/V1/ApiFansMedal.php create mode 100644 src/Api/XLive/DataInterface/V1/HeartBeat/ApiHeartBeat.php create mode 100644 src/Api/XLive/WebRoom/V1/Index/ApiIndex.php create mode 100644 src/Schedule/Schedule.php create mode 100644 src/TaskQueue/TaskQueue.php create mode 100644 src/Util/Os/File.php diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..acbcfd4 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: [ 'https://i.loli.net/2019/07/13/5d2963e5cc1eb22973.png' ] \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE_CN.md b/.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE_CN.md new file mode 100644 index 0000000..ce2e41c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE_CN.md @@ -0,0 +1,47 @@ +# Issue: BiliHepler 程序问题 + + + +### 版本、安装方式、系统 + +1. 你在使用什么版本的 BiliHelper + + +2. 你通过什么方式安装 BiliHepler + + +3. 你所使用的操作系统 + +--- + +### 描述问题 + + + + +--- + +### 复现问题的步骤 + + + + +--- + +### BiliHelper 运行日志: + + + +```shell +# 此处贴入运行日志 + + + +``` + +--- + +### 截图 + + + diff --git a/.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE_EN.md b/.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE_EN.md new file mode 100644 index 0000000..081305c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE_EN.md @@ -0,0 +1,47 @@ +# Issue: Bug Report + + + +### Version, approach of installation, operating system + +1. What version of BiliHelper are you using? + + +2. What approach of installation do you install BiliHelper? + + +3. What is your operating system? + +--- + +### Description + + + + +--- + +### Steps to reproduce + + + + +--- + +### BiliHelper Logs: + + + +```shell +# Paste running logs here + + + +``` + +--- + +### Screenshot + + + diff --git a/.github/workflows/build_image_bhp.yml b/.github/workflows/build_image_bhp.yml new file mode 100644 index 0000000..1bf3977 --- /dev/null +++ b/.github/workflows/build_image_bhp.yml @@ -0,0 +1,22 @@ +name: "BiliHelper-personal Docker Image Buildx Stable Github" +on: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + name: Build BiliHelper-personal Docker Image Build Stable Github + steps: + - name: Checkout master + uses: actions/checkout@master + - name: Build and publish image + uses: ilteoood/docker_buildx@master + with: + publish: true + imageName: lkeme/bilihelper-personal + dockerFile: docker/Dockerfile + platform: linux/amd64,linux/arm64,linux/arm/v7 + # platform: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v8 + tag: latest + dockerUser: ${{ secrets.DOCKER_USERNAME }} + dockerPassword: ${{ secrets.DOCKER_PASSWORD }} \ No newline at end of file diff --git a/plugin/BpConsumption/BpConsumption.php b/plugin/BpConsumption/BpConsumption.php index 556d610..a5af312 100644 --- a/plugin/BpConsumption/BpConsumption.php +++ b/plugin/BpConsumption/BpConsumption.php @@ -51,7 +51,7 @@ class BpConsumption extends BasePlugin } /** - * @use 执行 + * 执行 * @return void */ public function execute(): void @@ -64,7 +64,7 @@ class BpConsumption extends BasePlugin } /** - * @use 消费 + * 消费 * @return void */ protected function consumptionTask(): void @@ -108,7 +108,7 @@ class BpConsumption extends BasePlugin } /** - * @use B币充电 + * B币充电 * @param int $uid * @param int $num */ @@ -131,7 +131,7 @@ class BpConsumption extends BasePlugin } /** - * @use 获取钱包B币券余额 + * 获取钱包B币券余额 * @return int */ protected function getUserWallet(): int diff --git a/plugin/CheckUpdate/CheckUpdate.php b/plugin/CheckUpdate/CheckUpdate.php index ac309d2..8d689de 100644 --- a/plugin/CheckUpdate/CheckUpdate.php +++ b/plugin/CheckUpdate/CheckUpdate.php @@ -54,22 +54,24 @@ class CheckUpdate extends BasePluginRW } /** - * @use 执行 + * 执行 * @return void */ public function execute(): void { if (TimeLock::getTimes() > time()) return; // - $this->_checkUpdate(); - // - TimeLock::setTimes(24 * 60 * 60); + if ($this->_checkUpdate()) { + TimeLock::setTimes(24 * 60 * 60); + } else { + TimeLock::setTimes(1 * 60 * 60); + } } /** - * @return void + * @return bool */ - protected function _checkUpdate(): void + protected function _checkUpdate(): bool { // Log::info('开始检查项目更新'); @@ -79,6 +81,11 @@ class CheckUpdate extends BasePluginRW Log::info('拉取线上最新配置'); // object $online = $this->fetchOnlineVersion(); + // 网络错误 + if ($online->code != 200) { + Log::warning('检查更新: 拉取线上失败,网络错误!'); + return false; + } // 比较版本 if ($this->compareVersion($offline->get('version'), $online->version)) { // TODO 完善消息 支持markdown @@ -91,11 +98,12 @@ class CheckUpdate extends BasePluginRW } else { Log::info('程序已是最新版本'); } + return true; } /** - * @use 拉取本地版本 - * @return void + * 拉取本地版本 + * @return Resource */ protected function fetchOfflineVersion(): Resource { @@ -104,7 +112,7 @@ class CheckUpdate extends BasePluginRW } /** - * @use 拉取线上版本 + * 拉取线上版本 * @return object */ protected function fetchOnlineVersion(): object @@ -115,7 +123,7 @@ class CheckUpdate extends BasePluginRW } /** - * @use 比较版本号 + * 比较版本号 * @param string $off * @param string $on * @return bool @@ -127,7 +135,7 @@ class CheckUpdate extends BasePluginRW } /** - * @use 重写系统路径 + * 重写系统路径 * @param string $filename * @return string */ diff --git a/plugin/GameForecast/GameForecast.php b/plugin/GameForecast/GameForecast.php index d574152..33fc08c 100644 --- a/plugin/GameForecast/GameForecast.php +++ b/plugin/GameForecast/GameForecast.php @@ -49,7 +49,7 @@ class GameForecast extends BasePlugin } /** - * @use 执行 + * 执行 * @return void */ public function execute(): void @@ -62,7 +62,7 @@ class GameForecast extends BasePlugin } /** - * @use 获取预测赛事列表 + * 获取预测赛事列表 * @param int $pm * @return array */ @@ -97,7 +97,7 @@ class GameForecast extends BasePlugin } /** - * @use 预计猜测结果 + * 预计猜测结果 * @param array $question * @return array */ @@ -139,7 +139,7 @@ class GameForecast extends BasePlugin } /** - * @use 开始破产 + * 开始破产 */ protected function startStake(): void { @@ -163,7 +163,7 @@ class GameForecast extends BasePlugin } /** - * @use 添加竞猜 + * 添加竞猜 * @param array $guess */ protected function addGuess(array $guess): void diff --git a/plugin/Judge/Judge.php b/plugin/Judge/Judge.php index 79db501..4ec7ce0 100644 --- a/plugin/Judge/Judge.php +++ b/plugin/Judge/Judge.php @@ -71,7 +71,7 @@ class Judge extends BasePlugin } /** - * @use 执行 + * 执行 * @return void */ public function execute(): void @@ -91,7 +91,7 @@ class Judge extends BasePlugin } /** - * @use 審判任務 + * 審判任務 * @return void */ protected function judgementTask(): void @@ -108,7 +108,7 @@ class Judge extends BasePlugin } /** - * @use 案件核查 + * 案件核查 * @param string $case_id * @return bool */ @@ -138,7 +138,7 @@ class Judge extends BasePlugin } /** - * @use 投票 + * 投票 * @param string $case_id * @param int $vote */ @@ -156,7 +156,7 @@ class Judge extends BasePlugin } /** - * @use 隨機整數 + * 隨機整數 * @param int $max * @return string */ @@ -170,7 +170,7 @@ class Judge extends BasePlugin } /** - * @use 概率 + * 概率 * @return int */ protected function probability(): int @@ -191,7 +191,7 @@ class Judge extends BasePlugin } /** - * @use 获取衆議觀點 + * 获取衆議觀點 * @param string $case_id * @return array */ @@ -208,7 +208,7 @@ class Judge extends BasePlugin } /** - * @use 获取案例详情 + * 获取案例详情 * @param string $case_id * @return mixed */ @@ -225,7 +225,7 @@ class Judge extends BasePlugin } /** - * @use 获取案件任务 + * 获取案件任务 * @return string */ protected function caseObtain(): string @@ -267,7 +267,7 @@ class Judge extends BasePlugin /** - * @use 陪審團信息 + * 陪審團信息 * @return bool */ protected function juryInfo(): bool @@ -300,7 +300,7 @@ class Judge extends BasePlugin } /** - * @use 申請連任資格 + * 申請連任資格 * @return void */ protected function juryApply(): void @@ -316,7 +316,7 @@ class Judge extends BasePlugin } /** - * @use 获取案例數據 + * 获取案例數據 * @return bool */ private static function judgementIndex(): bool diff --git a/plugin/LiveGoldBox/LiveGoldBox.php b/plugin/LiveGoldBox/LiveGoldBox.php index c1284cb..9a1cbe7 100644 --- a/plugin/LiveGoldBox/LiveGoldBox.php +++ b/plugin/LiveGoldBox/LiveGoldBox.php @@ -68,7 +68,7 @@ class LiveGoldBox extends BasePlugin } /** - * @use 执行 + * 执行 * @return void */ public function execute(): void @@ -85,7 +85,7 @@ class LiveGoldBox extends BasePlugin } /** - * @use 过滤轮次 + * 过滤轮次 * @param array $rounds * @return int */ @@ -108,7 +108,7 @@ class LiveGoldBox extends BasePlugin } /** - * @use 过滤抽奖Title + * 过滤抽奖Title * @param string $title * @return bool */ @@ -125,7 +125,7 @@ class LiveGoldBox extends BasePlugin } /** - * @use 抽奖 + * 抽奖 * @param array $lottery_list * @return bool */ @@ -143,7 +143,7 @@ class LiveGoldBox extends BasePlugin } /** - * @use 获取抽奖 + * 获取抽奖 * @return array */ protected function fetchLotteryList(): array @@ -200,7 +200,7 @@ class LiveGoldBox extends BasePlugin } /** - * @use 抽奖盒子信息 + * 抽奖盒子信息 * @param int $aid * @return array */ @@ -223,7 +223,7 @@ class LiveGoldBox extends BasePlugin } /** - * @use 计算范围 + * 计算范围 * @param int $min * @param int $max * @return void diff --git a/plugin/LiveReservation/LiveReservation.php b/plugin/LiveReservation/LiveReservation.php index 06718ba..574f9c1 100644 --- a/plugin/LiveReservation/LiveReservation.php +++ b/plugin/LiveReservation/LiveReservation.php @@ -49,7 +49,7 @@ class LiveReservation extends BasePlugin } /** - * @use 执行 + * 执行 * @return void */ public function execute(): void @@ -78,7 +78,7 @@ class LiveReservation extends BasePlugin } /** - * @use 获取预约列表 + * 获取预约列表 * @param string $vmid * @return array */ @@ -107,7 +107,7 @@ class LiveReservation extends BasePlugin } /** - * @use 检测有效抽奖 + * 检测有效抽奖 * @param array $data * @return bool|array */ @@ -135,7 +135,7 @@ class LiveReservation extends BasePlugin } /** - * @use 尝试预约并抽奖 + * 尝试预约并抽奖 * @param array $data */ protected function reserve(array $data): void diff --git a/plugin/LiveSignIn/LiveSignIn.php b/plugin/LiveSignIn/LiveSignIn.php index 564c426..4ad1aff 100644 --- a/plugin/LiveSignIn/LiveSignIn.php +++ b/plugin/LiveSignIn/LiveSignIn.php @@ -49,7 +49,7 @@ class LiveSignIn extends BasePlugin } /** - * @use 执行 + * 执行 * @return void */ public function execute(): void diff --git a/plugin/Login/Login.php b/plugin/Login/Login.php index c22e7e0..81049f7 100644 --- a/plugin/Login/Login.php +++ b/plugin/Login/Login.php @@ -16,6 +16,7 @@ */ use Bhp\Api\Passport\ApiCaptcha; +use Bhp\Api\Passport\ApiLogin; use Bhp\Api\Passport\ApiOauth2; use Bhp\Api\PassportTv\ApiQrcode; use Bhp\Cache\Cache; @@ -38,8 +39,8 @@ class Login extends BasePlugin 'hook' => __CLASS__, // hook 'name' => 'Login', // 插件名称 'version' => '0.0.1', // 插件版本 - 'desc' => '登录模块', // 插件描述 - 'author' => 'Lkeme',// 作者 + 'desc' => '登录', // 插件描述 + 'author' => 'Lkeme', // 作者 'priority' => 1001, // 插件优先级 'cycle' => '2(小时)', // 运行周期 ]; @@ -84,7 +85,7 @@ class Login extends BasePlugin } /** - * @use 初始化登录 + * 初始化登录 * @return void */ protected function initLogin(): void @@ -99,26 +100,18 @@ class Login extends BasePlugin $this->login(); } // Token存在\校验有效性\否则调用登录 - Log::info('检查登录令牌有效性'); - if (!$this->validateToken($token)) { - Log::warning('登录令牌失效或即将过期'); - Log::info('申请更换登录令牌中'); - if (!$this->refreshToken($token, $r_token)) { - Log::warning('无效的登录令牌,尝试重新申请'); - $this->login(); - } - } + $this->keepAlive($token, $r_token); } /** - * @use 登录控制中心 + * 登录控制中心 * @return void */ protected function login(): void { $this->checkLogin(); // - switch (getConf('login_mode.mode')) { + switch ((int)getConf('login_mode.mode')) { case 1: // 账密模式 $this->accountLogin(); @@ -141,54 +134,69 @@ class Login extends BasePlugin } /** - * @use 保持认证 - * @return bool + * 保持认证 */ - protected function keepLogin(): bool + protected function keepLogin(): void { // $token = getU('access_token'); $r_token = getU('refresh_token'); - // - if ($this->validateToken($token)) { - return true; - } - Log::warning('令牌即将过期'); - Log::info('申请更换令牌中...'); - if (!$this->refreshToken($token, $r_token)) { - Log::warning('无效令牌,正在重新申请...'); - self::accountLogin(); - } - return false; + // Token存在\校验有效性\否则调用登录 + $this->keepAlive($token, $r_token); } /** - * @use 校验令牌信息 + * 保活处理 + * @param string $token + * @param string $r_token + * @return bool + */ + protected function keepAlive(string $token, string $r_token): bool + { + Log::info('检查登录令牌有效性'); + if (!$this->validateToken($token)) { + Log::warning('登录令牌失效过期或需要保活'); + Log::info('申请更换登录令牌中...'); + if (!$this->refreshToken($token, $r_token)) { + Log::warning('无效的登录令牌,尝试重新申请...'); + $this->login(); + } + } + // + $token = getU('access_token'); + $this->myInfo($token); + + return true; + } + + /** + * 校验令牌信息 * @param string $token * @return bool */ protected function validateToken(string $token): bool { - // {"ts":1234,"code":0,"data":{"mid":1234,"access_token":"1234","expires_in":7759292}} - $response = ApiOauth2::tokenInfo($token); + // {"code":0,"message":"0","ttl":1,"data":{"mid":"","access_token":"","expires_in":9787360,"refresh":true}} + $response = ApiOauth2::tokenInfoNew($token); // if (isset($response['code']) && $response['code']) { Log::error('检查令牌失败', ['msg' => $response['message']]); return false; } - Log::notice('令牌有效期: ' . date('Y-m-d H:i:s', $response['ts'] + $response['data']['expires_in'])); - return $response['data']['expires_in'] > 14400; + Log::notice('令牌有效期: ' . date('Y-m-d H:i:s', time() + $response['data']['expires_in'])); + // 保活 + return !$response['data']['refresh'] && $response['data']['expires_in'] > 14400; } /** - * @use 刷新token + * 刷新token * @param string $token * @param string $r_token * @return bool */ protected function refreshToken(string $token, string $r_token): bool { - $response = ApiOauth2::tokenRefresh($token, $r_token); + $response = ApiOauth2::tokenRefreshNew($token, $r_token); // {"message":"user not login","ts":1593111694,"code":-101} if (isset($response['code']) && $response['code']) { Log::error('重新生成令牌失败', ['msg' => $response['message']]); @@ -201,7 +209,23 @@ class Login extends BasePlugin } /** - * @use 更新登录信息 + * 登录信息 + * @param string $token + * @return bool + */ + protected function myInfo(string $token): bool + { + $response = ApiOauth2::myInfo($token); + if (isset($response['code']) && $response['code']) { + Log::error('获取登录信息失败', ['msg' => $response['message']]); + return false; + } + Log::info('获取登录信息成功'); + return true; + } + + /** + * 更新登录信息 * @param array $data */ protected function updateLoginInfo(array $data): void @@ -226,7 +250,7 @@ class Login extends BasePlugin } /** - * @use 更新Tv登录信息 + * 更新Tv登录信息 * @param array $data */ protected function updateTvLoginInfo(array $data): void @@ -252,7 +276,7 @@ class Login extends BasePlugin } /** - * @use 更新信息 + * 更新信息 * @param string $key * @param mixed $value * @param bool $print @@ -268,7 +292,7 @@ class Login extends BasePlugin } /** - * @use 格式化Cookie + * 格式化Cookie * @param array $cookies * @return string */ @@ -282,7 +306,7 @@ class Login extends BasePlugin } /** - * @use 账密登录 + * 账密登录 * @param string $validate * @param string $challenge * @param string $mode @@ -296,13 +320,13 @@ class Login extends BasePlugin // {"ts":1593082432,"code":0,"data":{"status":0,"token_info":{"mid":123456,"access_token":"123123","refresh_token":"123123","expires_in":2592000},"cookie_info":{"cookies":[{"name":"bili_jct","value":"123123","http_only":0,"expires":1595674432},{"name":"DedeUserID","value":"123456","http_only":0,"expires":1595674432},{"name":"DedeUserID__ckMd5","value":"123123","http_only":0,"expires":1595674432},{"name":"sid","value":"bd6aagp7","http_only":0,"expires":1595674432},{"name":"SESSDATA","value":"6d74d850%123%2Cf0e36b61","http_only":1,"expires":1595674432}],"domains":[".bilibili.com",".biligame.com",".bigfunapp.cn"]},"sso":["https://passport.bilibili.com/api/v2/sso","https://passport.biligame.com/api/v2/sso","https://passport.bigfunapp.cn/api/v2/sso"]}} // {"ts":1610254019,"code":0,"data":{"status":2,"url":"https://passport.bilibili.com/account/mobile/security/managephone/phone/verify?tmp_token=2bc5dd260df7158xx860565fxx0d5311&requestId=dffcfxx052fe11xxa9c8e2667739c15c&source=risk","message":"您的账号存在高危异常行为,为了您的账号安全,请验证手机号后登录帐号"}} // https://passport.bilibili.com/mobile/verifytel_h5.html - $response = ApiQrcode::passwordLogin($this->username, $this->password, $validate, $challenge); + $response = ApiLogin::passwordLogin($this->username, $this->password, $validate, $challenge); // $this->loginAfter($mode, $response['code'], $response); } /** - * @use 短信登录 + * 短信登录 * @param string $mode * @return void */ @@ -318,13 +342,13 @@ class Login extends BasePlugin // $captcha = $this->sendSms($this->username, getConf('login_country.code')); $code = $this->cliInput('请输入收到的短信验证码: '); - $response = ApiQrcode::smsLogin($captcha, $code); + $response = ApiLogin::smsLogin($captcha, $code); // $this->loginAfter($mode, $response['code'], $response); } /** - * @use 扫码登录 + * 扫码登录 * @param string $mode * @return void */ @@ -349,7 +373,7 @@ class Login extends BasePlugin } /** - * @use 获取AuthCode + * 获取AuthCode * @return array */ protected function fetchQrAuthCode(): array @@ -365,7 +389,7 @@ class Login extends BasePlugin } /** - * @use 验证AuthCode + * 验证AuthCode * @param string $auth_code * @return bool */ @@ -402,7 +426,7 @@ class Login extends BasePlugin } /** - * @use 登录后处理 + * 登录后处理 * @param string $mode * @param int $code * @param array $data @@ -451,7 +475,7 @@ class Login extends BasePlugin } /** - * @use 登录成功处理 + * 登录成功处理 * @param string $mode * @param array $data * @return void @@ -464,7 +488,7 @@ class Login extends BasePlugin } /** - * @use 登录失败处理 + * 登录失败处理 * @param string $mode * @param string $data * @return void @@ -476,7 +500,7 @@ class Login extends BasePlugin } /** - * @use 检查登录 + * 检查登录 */ protected function checkLogin(): void { @@ -490,7 +514,7 @@ class Login extends BasePlugin } /** - * @use 公钥加密 + * 公钥加密 * @param string $plaintext * @return string */ @@ -513,7 +537,7 @@ class Login extends BasePlugin } /** - * @use 发送短信验证码 + * 发送短信验证码 * @param string $phone * @param string $cid * @return array @@ -522,7 +546,7 @@ class Login extends BasePlugin { // {"code":0,"message":"0","ttl":1,"data":{"is_new":false,"captcha_key":"4e292933816755442c1568e2043b8e41","recaptcha_url":""}} // {"code":0,"message":"0","ttl":1,"data":{"is_new":false,"captcha_key":"","recaptcha_url":"https://www.bilibili.com/h5/project-msg-auth/verify?ct=geetest\u0026recaptcha_token=ad520c3a4a3c46e29b1974d85efd2c4b\u0026gee_gt=1c0ea7c7d47d8126dda19ee3431a5f38\u0026gee_challenge=c772673050dce482b9f63ff45b681ceb\u0026hash=ea2850a43cc6b4f1f7b925d601098e5e"}} - $raw = ApiQrcode::sendSms($phone, $cid); + $raw = ApiLogin::sendSms($phone, $cid); $response = json_decode($raw, true); // if ($response['code'] == 0 && isset($response['data']['captcha_key']) && $response['data']['recaptcha_url'] == '') { @@ -534,7 +558,7 @@ class Login extends BasePlugin } /** - * @use 输入短信验证码 + * 输入短信验证码 * @param string $msg * @param int $max_char * @return string @@ -549,7 +573,7 @@ class Login extends BasePlugin } /** - * @use 获取验证码 + * 获取验证码 * @return array */ protected function getCaptcha(): array @@ -571,7 +595,7 @@ class Login extends BasePlugin } /** - * @use 验证码模式 + * 验证码模式 * @param string $mode * @return void */ @@ -583,7 +607,7 @@ class Login extends BasePlugin } /** - * @use 转换Cookie + * 转换Cookie * @param string $token * @return string */ diff --git a/plugin/LoveClub/LoveClub.php b/plugin/LoveClub/LoveClub.php index b22aa8e..2b4a89f 100644 --- a/plugin/LoveClub/LoveClub.php +++ b/plugin/LoveClub/LoveClub.php @@ -49,7 +49,7 @@ class LoveClub extends BasePlugin } /** - * @use 执行 + * 执行 * @return void */ public function execute(): void @@ -66,7 +66,7 @@ class LoveClub extends BasePlugin } /** - * @use 获取友爱社列表 + * 获取友爱社列表 * @return array */ protected function getGroupList(): array @@ -87,7 +87,7 @@ class LoveClub extends BasePlugin } /** - * @use 签到 + * 签到 * @param array $groupInfo * @return bool */ diff --git a/plugin/MainSite/MainSite.php b/plugin/MainSite/MainSite.php index fde43fb..cf1952b 100644 --- a/plugin/MainSite/MainSite.php +++ b/plugin/MainSite/MainSite.php @@ -53,7 +53,7 @@ class MainSite extends BasePlugin } /** - * @use 执行 + * 执行 * @return void */ public function execute(): void @@ -68,7 +68,7 @@ class MainSite extends BasePlugin } /** - * @use 投币任务 + * 投币任务 * @return bool */ protected function coinTask(): bool @@ -106,7 +106,7 @@ class MainSite extends BasePlugin } /** - * @use 投币 + * 投币 * @param string $aid * @return void */ @@ -122,7 +122,7 @@ class MainSite extends BasePlugin } /** - * @use 首页推荐 + * 首页推荐 * @param int $num * @param int $ps * @return array @@ -149,7 +149,7 @@ class MainSite extends BasePlugin } /** - * @use 获取榜单稿件列表 + * 获取榜单稿件列表 * @param int $num * @return array */ @@ -178,7 +178,7 @@ class MainSite extends BasePlugin } /** - * @use 获取关注UP稿件列表 + * 获取关注UP稿件列表 * @param int $num * @return array */ @@ -207,7 +207,7 @@ class MainSite extends BasePlugin } /** - * @use 已投币数量 + * 已投币数量 * @return int */ protected function getCoinAlready(): int @@ -246,24 +246,25 @@ class MainSite extends BasePlugin } /** - * @use 获取硬币库存 + * 获取硬币库存 * @return int */ protected function getCoinStock(): int { // {"code":0,"status":true,"data":{"money":1707.9}} + // {"code":0,"status":true,"data":{"money":null} $response = ApiCoin::getCoin(); // if ($response['code'] || !isset($response['data']['money'])) { - Log::warning("主站任务: 获取硬币库存失败 " . json_encode($response, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); + Log::warning("主站任务: 获取硬币库存失败或者硬币为null " . json_encode($response, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); return 0; } // - return intval($response['data']['money']); + return (int)$response['data']['money']; } /** - * @use 分享任务 + * 分享任务 * @return bool */ protected function shareTask(): bool @@ -284,7 +285,7 @@ class MainSite extends BasePlugin } /** - * @use 观看任务 + * 观看任务 * @return bool */ protected function watchTask(): bool @@ -308,7 +309,7 @@ class MainSite extends BasePlugin Log::warning("主站任务: $aid 观看失败 {$response['code']} -> {$response['message']}"); return false; } - sleep(5); + sleep(5); // $data = []; $data['played_time'] = $duration - 1; @@ -326,7 +327,7 @@ class MainSite extends BasePlugin } /** - * @use 获取随机 + * 获取随机 * @return array */ protected function fetchRandomAvInfos(): array diff --git a/plugin/Manga/Manga.php b/plugin/Manga/Manga.php index 284a16b..5d7243e 100644 --- a/plugin/Manga/Manga.php +++ b/plugin/Manga/Manga.php @@ -49,7 +49,7 @@ class Manga extends BasePlugin } /** - * @use 执行 + * 执行 * @return void */ public function execute(): void @@ -64,7 +64,7 @@ class Manga extends BasePlugin } /** - * @use 签到任务 + * 签到任务 * @return bool */ protected function signInTask(): bool @@ -89,7 +89,7 @@ class Manga extends BasePlugin } /** - * @use 分享任务 + * 分享任务 * @return bool */ protected function shareTask(): bool @@ -121,7 +121,7 @@ class Manga extends BasePlugin } /** - * @use 签到信息 + * 签到信息 * @return void */ protected function signInInfo(): void diff --git a/plugin/PluginTemplate/PluginTemplate.php b/plugin/PluginTemplate/PluginTemplate.php index 8fe20f5..76ebbdc 100644 --- a/plugin/PluginTemplate/PluginTemplate.php +++ b/plugin/PluginTemplate/PluginTemplate.php @@ -49,7 +49,7 @@ class PluginTemplate extends BasePlugin } /** - * @use 执行 + * 执行 * @return void */ public function execute(): void diff --git a/plugin/Silver2Coin/Silver2Coin.php b/plugin/Silver2Coin/Silver2Coin.php index 0405789..8cededf 100644 --- a/plugin/Silver2Coin/Silver2Coin.php +++ b/plugin/Silver2Coin/Silver2Coin.php @@ -49,7 +49,7 @@ class Silver2Coin extends BasePlugin } /** - * @use 执行 + * 执行 * @return void */ public function execute(): void @@ -101,7 +101,7 @@ class Silver2Coin extends BasePlugin } /** - * @use 兑换任务 + * 兑换任务 * @return bool */ protected function exchangeTask(): bool @@ -117,7 +117,7 @@ class Silver2Coin extends BasePlugin } /** - * @use 处理结果 + * 处理结果 * @param string $type * @param array $data * @return bool diff --git a/plugin/VipPrivilege/VipPrivilege.php b/plugin/VipPrivilege/VipPrivilege.php index 2604531..ec64d60 100644 --- a/plugin/VipPrivilege/VipPrivilege.php +++ b/plugin/VipPrivilege/VipPrivilege.php @@ -59,7 +59,7 @@ class VipPrivilege extends BasePlugin } /** - * @use 执行 + * 执行 * @return void */ public function execute(): void @@ -73,7 +73,7 @@ class VipPrivilege extends BasePlugin } /** - * @use 领取 + * 领取 * @return void */ protected function receiveTask(): void @@ -94,7 +94,7 @@ class VipPrivilege extends BasePlugin } /** - * @use 获取我的大会员权益列表 + * 获取我的大会员权益列表 * @return array */ protected function myVipPrivilege(): array @@ -112,7 +112,7 @@ class VipPrivilege extends BasePlugin } /** - * @use 领取我的大会员权益 + * 领取我的大会员权益 * @param int $type */ protected function myVipPrivilegeReceive(int $type): void diff --git a/profile/example/config/user.ini b/profile/example/config/user.ini index ec80986..3f9465f 100644 --- a/profile/example/config/user.ini +++ b/profile/example/config/user.ini @@ -47,7 +47,7 @@ enable = true ; 直播签到 [live_sign_in] -enable =true +enable = true ; 游戏赛事竞猜预测(破产机)/每日竞猜次数/每次竞猜硬币(1-10)/下注(1.压大,2.压小,3.随机) [game_forecast] diff --git a/profile/example/device/device.yaml b/profile/example/device/device.yaml index dc51bd6..6f65da8 100644 --- a/profile/example/device/device.yaml +++ b/profile/example/device/device.yaml @@ -3,8 +3,8 @@ device_version: 0.0.1 app: bili_a: # Android package: "tv.danmaku.bili" - version: "6.72.0" - build: "6720300" + version: "6.83.0" + build: "6830300" channel: "bili" device: "phone" mobi_app: "android" diff --git a/src/Api/Credit/ApiJury.php b/src/Api/Credit/ApiJury.php index e367a5c..cb77fc5 100644 --- a/src/Api/Credit/ApiJury.php +++ b/src/Api/Credit/ApiJury.php @@ -24,7 +24,7 @@ class ApiJury { /** - * @use 风纪委员状态 + * 风纪委员状态 * @return array */ public static function jury(): array @@ -41,7 +41,7 @@ class ApiJury } /** - * @use 申請連任 + * 申請連任 * @return array */ public static function juryApply(): array @@ -61,7 +61,7 @@ class ApiJury } /** - * @use 獲取案件任務 + * 獲取案件任務 * @return array */ public static function caseNext(): array @@ -81,7 +81,7 @@ class ApiJury } /** - * @use 案件信息 + * 案件信息 * @param string $case_id * @return array */ @@ -100,7 +100,7 @@ class ApiJury } /** - * @use 衆議觀點 + * 衆議觀點 * @param string $case_id * @param int $pn * @param int $ps @@ -123,7 +123,7 @@ class ApiJury } /** - * @use 投票 + * 投票 * @param string $case_id * @param int $vote * @param string $content @@ -154,7 +154,7 @@ class ApiJury } /** - * @use 案件列表 + * 案件列表 * @param int $pn * @param int $ps * @return array diff --git a/src/Api/Custom/ApiCalcSign.php b/src/Api/Custom/ApiCalcSign.php new file mode 100644 index 0000000..dafd809 --- /dev/null +++ b/src/Api/Custom/ApiCalcSign.php @@ -0,0 +1,66 @@ + $t['id'], +// 'device' => $t['device'], +// 'ets' => $t['ets'], +// 'benchmark' => $t['benchmark'], +// 'time' => $t['time'], +// 'ts' => $t['ts'], +// 'ua' => $t['ua'], +// ]; + } + + + protected static function formatR(array $r): array + { + return $r; + } + + + /** + * 获取关注Up动态 + * @return mixed + */ + public static function heartBeat(string $url, array $t, array $r): array + { + $headers = [ + 'Content-Type' => 'application/json', + ]; + // 加密部分 + $payload = [ + 't' => static::formatT($t), + 'r' => static::formatR($r) + ]; + return Request::putJson(true, 'other', $url, $payload, $headers); + } + +} + diff --git a/src/Api/DynamicSvr/ApiDynamicSvr.php b/src/Api/DynamicSvr/ApiDynamicSvr.php index 5d4128e..6acc7ee 100644 --- a/src/Api/DynamicSvr/ApiDynamicSvr.php +++ b/src/Api/DynamicSvr/ApiDynamicSvr.php @@ -23,7 +23,7 @@ use Bhp\User\User; class ApiDynamicSvr { /** - * @use 获取关注Up动态 + * 获取关注Up动态 * @return mixed */ public static function followUpDynamic(): array diff --git a/src/Api/Esports/ApiGuess.php b/src/Api/Esports/ApiGuess.php index 6cadeaf..c2fd2be 100644 --- a/src/Api/Esports/ApiGuess.php +++ b/src/Api/Esports/ApiGuess.php @@ -23,7 +23,7 @@ use Bhp\User\User; class ApiGuess { /** - * @use 获取赛事竞猜 + * 获取赛事竞猜 * @param int $pn * @param int $ps * @return array @@ -45,7 +45,7 @@ class ApiGuess } /** - * @use 竞猜 + * 竞猜 * @param int $oid * @param int $main_id * @param int $detail_id diff --git a/src/Api/LinkGroup/ApiLoveClub.php b/src/Api/LinkGroup/ApiLoveClub.php index 56fe20a..85dde2c 100644 --- a/src/Api/LinkGroup/ApiLoveClub.php +++ b/src/Api/LinkGroup/ApiLoveClub.php @@ -23,7 +23,7 @@ use Bhp\Sign\Sign; class ApiLoveClub { /** - * @use 获取我的友爱社列表 + * 获取我的友爱社列表 * @return array */ public static function myGroups(): array diff --git a/src/Api/Manga/ApiManga.php b/src/Api/Manga/ApiManga.php index 4a78b0d..ff59c0a 100644 --- a/src/Api/Manga/ApiManga.php +++ b/src/Api/Manga/ApiManga.php @@ -24,7 +24,7 @@ class ApiManga { /** - * @use 签到 + * 签到 * @return array */ public static function ClockIn(): array @@ -38,7 +38,7 @@ class ApiManga /** - * @use 分享 + * 分享 * @return array */ public static function ShareComic(): array @@ -52,7 +52,7 @@ class ApiManga } /** - * @use 签到信息 + * 签到信息 * @return array */ public static function GetClockInInfo(): array diff --git a/src/Api/Passport/ApiCaptcha.php b/src/Api/Passport/ApiCaptcha.php index 7ede5fb..8a071c8 100644 --- a/src/Api/Passport/ApiCaptcha.php +++ b/src/Api/Passport/ApiCaptcha.php @@ -23,7 +23,7 @@ use Bhp\Sign\Sign; class ApiCaptcha { /** - * @use 获取验证码 + * 获取验证码 * @param int $plat * @return mixed */ @@ -39,7 +39,7 @@ class ApiCaptcha } /** - * @use 识别验证码 + * 识别验证码 * @param array $captcha * @return array */ diff --git a/src/Api/Passport/ApiLogin.php b/src/Api/Passport/ApiLogin.php index 50f0c12..731db48 100644 --- a/src/Api/Passport/ApiLogin.php +++ b/src/Api/Passport/ApiLogin.php @@ -23,7 +23,7 @@ use Bhp\Sign\Sign; class ApiLogin { /** - * @use 密码登录 + * 密码登录 * @param string $username * @param string $password * @param string $validate @@ -49,7 +49,7 @@ class ApiLogin } /** - * @use 发送短信验证码 + * 发送短信验证码 * @param string $phone * @param string $cid * @return string @@ -61,7 +61,7 @@ class ApiLogin $payload = [ 'cid' => $cid, 'tel' => $phone, - 'statistics' => '{"appId":1,"platform":3,"version":"6.72.0","abtest":""}', + 'statistics' => '{"appId":1,"platform":3,"version":"6.83.0","abtest":""}', ]; // {"code":0,"message":"0","ttl":1,"data":{"is_new":false,"captcha_key":"4e292933816755442c1568e2043b8e41","recaptcha_url":""}} // {"code":0,"message":"0","ttl":1,"data":{"is_new":false,"captcha_key":"","recaptcha_url":"https://www.bilibili.com/h5/project-msg-auth/verify?ct=geetest\u0026recaptcha_token=ad520c3a4a3c46e29b1974d85efd2c4b\u0026gee_gt=1c0ea7c7d47d8126dda19ee3431a5f38\u0026gee_challenge=c772673050dce482b9f63ff45b681ceb\u0026hash=ea2850a43cc6b4f1f7b925d601098e5e"}} @@ -69,7 +69,7 @@ class ApiLogin } /** - * @use 短信验证码登录 + * 短信验证码登录 * @param array $captcha * @param string $code * @return array diff --git a/src/Api/Passport/ApiOauth2.php b/src/Api/Passport/ApiOauth2.php index 72fa230..1cd30c8 100644 --- a/src/Api/Passport/ApiOauth2.php +++ b/src/Api/Passport/ApiOauth2.php @@ -34,11 +34,11 @@ class ApiOauth2 'access_token' => $token, ]; // {"ts":1234,"code":0,"data":{"mid":1234,"access_token":"1234","expires_in":7759292}} - return Request::getJson(true, 'app', $url, Sign::common($payload)); + return Request::getJson(true, 'app', $url, Sign::login($payload)); } /** - * @use 新令牌信息 + * 新令牌信息 * @param string $token * @return array */ @@ -48,12 +48,12 @@ class ApiOauth2 $payload = [ 'access_key' => $token, ]; - return Request::postJson(true, 'app', $url, Sign::common($payload)); - + // {"code":0,"message":"0","ttl":1,"data":{"mid":"","access_token":"","expires_in":9787360,"refresh":true}} + return Request::getJson(true, 'app', $url, Sign::login($payload)); } /** - * @use 刷新令牌信息 + * 刷新令牌信息 * @param string $token * @param string $r_token * @return array @@ -63,15 +63,14 @@ class ApiOauth2 $url = 'https://passport.bilibili.com/x/passport-login/oauth2/refresh_token'; $payload = [ 'access_key' => $token, - 'access_token' => $token, 'refresh_token' => $r_token, ]; // {"message":"user not login","ts":1593111694,"code":-101} - return Request::postJson(true, 'app', $url, Sign::common($payload)); + return Request::postJson(true, 'app', $url, Sign::login($payload)); } /** - * @use 刷新令牌信息 + * 刷新令牌信息 * @param string $token * @param string $r_token * @return array @@ -80,15 +79,29 @@ class ApiOauth2 { $url = 'https://passport.bilibili.com/api/v2/oauth2/refresh_token'; $payload = [ - 'access_token' => $token, + 'access_key' => $token, 'refresh_token' => $r_token, ]; // {"message":"user not login","ts":1593111694,"code":-101} - return Request::postJson(true, 'app', $url, Sign::common($payload)); + return Request::postJson(true, 'app', $url, Sign::login($payload)); } /** - * @use 获取公钥 + * 登录用户信息 + * @param string $token + * @return array + */ + public static function myInfo(string $token): array + { + $url = 'https://app.bilibili.com/x/v2/account/myinfo'; + $payload = [ + 'access_key' => $token, + ]; + return Request::getJson(true, 'app', $url, Sign::login($payload)); + } + + /** + * 获取公钥 * @return array */ public static function getKey(): array @@ -100,7 +113,7 @@ class ApiOauth2 } /** - * @use 刷新COOKIE + * 刷新COOKIE * @param string $token * @return array */ @@ -111,7 +124,7 @@ class ApiOauth2 'access_key' => $token, 'gourl' => 'https%3A%2F%2Faccount.bilibili.com%2Faccount%2Fhome' ]; - return Request::headers('app', $url, Sign::tv($payload)); + return Request::headers('app', $url, Sign::login($payload)); } } diff --git a/src/Api/PassportTv/ApiQrcode.php b/src/Api/PassportTv/ApiQrcode.php index 99ed674..97dbc5a 100644 --- a/src/Api/PassportTv/ApiQrcode.php +++ b/src/Api/PassportTv/ApiQrcode.php @@ -24,7 +24,7 @@ class ApiQrcode { /** - * @use 获取authCode + * 获取authCode * @return array */ public static function authCode(): array @@ -35,11 +35,11 @@ class ApiQrcode 'content-type' => 'application/x-www-form-urlencoded', ]; // {"code":0,"message":"0","ttl":1,"data":{"url":"https://passport.bilibili.com/x/passport-tv-login/h5/qrcode/auth?auth_code=xxxx","auth_code":"xxxx"}} - return Request::postJson(true, 'app', $url, Sign::tv($payload), $headers); + return Request::postJson(true, 'app', $url, Sign::login($payload), $headers); } /** - * @use 验证登录 + * 验证登录 * @param string $auth_code * @return mixed */ @@ -53,7 +53,7 @@ class ApiQrcode 'content-type' => 'application/x-www-form-urlencoded', ]; // {"code":0,"message":"0","ttl":1,"data":{"mid":123,"access_token":"xxx","refresh_token":"xxx","expires_in":2592000}} - return Request::postJson(true, 'app', $url, Sign::tv($payload), $headers); + return Request::postJson(true, 'app', $url, Sign::login($payload), $headers); } diff --git a/src/Api/Pay/ApiPay.php b/src/Api/Pay/ApiPay.php index 2302fc5..fe64057 100644 --- a/src/Api/Pay/ApiPay.php +++ b/src/Api/Pay/ApiPay.php @@ -25,7 +25,7 @@ class ApiPay { /** - * @use 金瓜子 + * 金瓜子 * @param int $num * @return array */ @@ -55,7 +55,7 @@ class ApiPay } /** - * @use 电池 + * 电池 * @param int $up_mid * @param int $num * @return array diff --git a/src/Api/Pay/ApiWallet.php b/src/Api/Pay/ApiWallet.php index 46c435a..84ce7e7 100644 --- a/src/Api/Pay/ApiWallet.php +++ b/src/Api/Pay/ApiWallet.php @@ -23,7 +23,7 @@ use Bhp\Util\Common\Common; class ApiWallet { /** - * @use 获取用户钱包 + * 获取用户钱包 * @return array */ public static function getUserWallet(): array diff --git a/src/Api/Space/ApiReservation.php b/src/Api/Space/ApiReservation.php index 9523531..98f8d30 100644 --- a/src/Api/Space/ApiReservation.php +++ b/src/Api/Space/ApiReservation.php @@ -23,7 +23,7 @@ use Bhp\User\User; class ApiReservation { /** - * @use 获取预约列表 + * 获取预约列表 * @param string $vmid * @return array */ @@ -42,7 +42,7 @@ class ApiReservation } /** - * @use 预约 + * 预约 * @param int $sid * @param int $vmid * @return array diff --git a/src/Api/Video/ApiCoin.php b/src/Api/Video/ApiCoin.php index 956e101..0d7831d 100644 --- a/src/Api/Video/ApiCoin.php +++ b/src/Api/Video/ApiCoin.php @@ -23,7 +23,7 @@ use Bhp\User\User; class ApiCoin { /** - * @use 投币 + * 投币 * @param string $aid * @param int $multiply * @param int $select_like @@ -55,7 +55,7 @@ class ApiCoin } /** - * @use 获取硬币 + * 获取硬币 * @return array */ public static function getCoin(): array @@ -70,7 +70,7 @@ class ApiCoin } /** - * @use 投币日志 + * 投币日志 * @return array */ public static function addLog(): array diff --git a/src/Api/Video/ApiShare.php b/src/Api/Video/ApiShare.php index 05c4620..a7fca7e 100644 --- a/src/Api/Video/ApiShare.php +++ b/src/Api/Video/ApiShare.php @@ -23,7 +23,7 @@ use Bhp\User\User; class ApiShare { /** - * @use 分享视频 + * 分享视频 * @param string $aid * @param string $cid * @return array diff --git a/src/Api/Video/ApiVideo.php b/src/Api/Video/ApiVideo.php index f133100..ddc8d56 100644 --- a/src/Api/Video/ApiVideo.php +++ b/src/Api/Video/ApiVideo.php @@ -38,7 +38,7 @@ class ApiVideo } /** - * @use 获取分区动态/首页推荐 + * 获取分区动态/首页推荐 * @param int $ps * @return array */ @@ -56,7 +56,7 @@ class ApiVideo } /** - * @use 获取榜单稿件 + * 获取榜单稿件 * @return array */ public static function ranking(): array diff --git a/src/Api/Video/ApiWatch.php b/src/Api/Video/ApiWatch.php index e0d1381..9662e28 100644 --- a/src/Api/Video/ApiWatch.php +++ b/src/Api/Video/ApiWatch.php @@ -23,7 +23,7 @@ use Bhp\User\User; class ApiWatch { /** - * @use 观看视频 + * 观看视频 * @param string $aid * @param string $cid * @return array @@ -56,7 +56,7 @@ class ApiWatch } /** - * @use 发送心跳 + * 发送心跳 * @param string $aid * @param string $cid * @param int $duration diff --git a/src/Api/Vip/ApiPrivilege.php b/src/Api/Vip/ApiPrivilege.php index 25b7a55..d9b30a3 100644 --- a/src/Api/Vip/ApiPrivilege.php +++ b/src/Api/Vip/ApiPrivilege.php @@ -23,7 +23,7 @@ use Bhp\User\User; class ApiPrivilege { /** - * @use 获取我的大会员权益列表 + * 获取我的大会员权益列表 * @return array */ public static function my(): array @@ -39,7 +39,7 @@ class ApiPrivilege } /** - * @use 领取权益 + * 领取权益 * @param int $type * @return array */ diff --git a/src/Api/Vip/ApiUser.php b/src/Api/Vip/ApiUser.php index 17057a8..c72b6b2 100644 --- a/src/Api/Vip/ApiUser.php +++ b/src/Api/Vip/ApiUser.php @@ -22,7 +22,7 @@ use Bhp\Request\Request; class ApiUser { /** - * @use 用户信息 + * 用户信息 * @return array */ public static function userInfo(): array diff --git a/src/Api/XLive/ApiRevenueWallet.php b/src/Api/XLive/ApiRevenueWallet.php index 646c3d7..317c3e2 100644 --- a/src/Api/XLive/ApiRevenueWallet.php +++ b/src/Api/XLive/ApiRevenueWallet.php @@ -24,7 +24,7 @@ use Bhp\User\User; class ApiRevenueWallet { /** - * @use app银瓜子兑换硬币 + * app银瓜子兑换硬币 * @return array */ public static function appSilver2coin(): array @@ -36,7 +36,7 @@ class ApiRevenueWallet } /** - * @use pc银瓜子兑换硬币 + * pc银瓜子兑换硬币 * @return array */ public static function pcSilver2coin(): array @@ -55,7 +55,7 @@ class ApiRevenueWallet } /** - * @use 钱包状态 + * 钱包状态 * @return array */ public static function getStatus(): array @@ -67,7 +67,7 @@ class ApiRevenueWallet } /** - * @use 我的钱包 + * 我的钱包 * @return array */ public static function myWallet(): array diff --git a/src/Api/XLive/ApiXLiveSign.php b/src/Api/XLive/ApiXLiveSign.php index 7ba6687..94fd3fe 100644 --- a/src/Api/XLive/ApiXLiveSign.php +++ b/src/Api/XLive/ApiXLiveSign.php @@ -22,7 +22,7 @@ use Bhp\Request\Request; class ApiXLiveSign { /** - * @use 签到信息 + * 签到信息 * @return array */ public static function webGetSignInfo(): array @@ -38,7 +38,7 @@ class ApiXLiveSign } /** - * @use 签到 + * 签到 * @return array */ public static function doSign(): array diff --git a/src/Api/XLive/AppUcenter/V1/ApiFansMedal.php b/src/Api/XLive/AppUcenter/V1/ApiFansMedal.php new file mode 100644 index 0000000..c76304a --- /dev/null +++ b/src/Api/XLive/AppUcenter/V1/ApiFansMedal.php @@ -0,0 +1,44 @@ + $pn, + 'page_size' => $ps, + ]; + // {"code":0,"message":"0","ttl":1,"data":{"list":[],"special_list":[],"bottom_bar":null,"page_info":{"number":0,"current_page":1,"has_more":false,"next_page":2,"next_light_status":2},"total_number":0,"has_medal":0}} + return Request::getJson(true, 'app', $url, Sign::common($payload)); + } + + +} \ No newline at end of file diff --git a/src/Api/XLive/DataInterface/V1/HeartBeat/ApiHeartBeat.php b/src/Api/XLive/DataInterface/V1/HeartBeat/ApiHeartBeat.php new file mode 100644 index 0000000..4c6f977 --- /dev/null +++ b/src/Api/XLive/DataInterface/V1/HeartBeat/ApiHeartBeat.php @@ -0,0 +1,96 @@ + 'application/x-www-form-urlencoded', + ]; + $payload = [ + 'platform' => 'android', + 'uuid' => Common::customCreateUUID((string)$user['uid']), + 'buvid' => Request::getBuvid(), + 'seq_id' => '1', + 'room_id' => $room_id, + 'parent_id' => $parent_id, + 'area_id' => $area_id, + 'timestamp' => time() - 60, + 'secret_key' => 'axoaadsffcazxksectbbb', + 'watch_time' => '60', + 'up_id' => $up_id, + 'up_level' => '40', + 'jump_from' => '30000', + 'gu_id' => strtoupper(Common::randString(43)), + 'play_type' => '0', + 'play_url' => '', + 's_time' => '0', + 'data_behavior_id' => '', + 'data_source_id' => '', + 'up_session' => "l:one:live:record:$room_id:" . time() - 88888, + 'visit_id' => strtoupper(Common::randString(32)), + 'watch_status' => '%7B%22pk_id%22%3A0%2C%22screen_status%22%3A1%7D', + 'click_id' => Common::customCreateUUID(strrev((string)$user['uid'])), + 'session_id' => '', + 'player_type' => '0', + 'client_ts' => time(), + ]; + // + $payload['client_sign'] = self::calcClientSign($payload); + // + return Request::postJson(true, 'app', $url, Sign::common($payload), $headers); + } + + /** + * 计算 TODO 调整位置 + * @param array $t + * @return string + */ + protected static function calcClientSign(array $t): string + { + $url = getConf('heartbeat.app'); + $r = [3, 7, 2, 6, 8]; + $response = ApiCalcSign::heartBeat($url, $t, $r); + if ($response['code'] != 0) { + Log::warning("心跳加密错误: {$response['code']}->{$response['message']}"); + } + return $response['s']; + } +} \ No newline at end of file diff --git a/src/Api/XLive/LotteryInterface/V2/ApiBox.php b/src/Api/XLive/LotteryInterface/V2/ApiBox.php index 754c510..040938b 100644 --- a/src/Api/XLive/LotteryInterface/V2/ApiBox.php +++ b/src/Api/XLive/LotteryInterface/V2/ApiBox.php @@ -22,7 +22,7 @@ use Bhp\Request\Request; class ApiBox { /** - * @use 抽奖 + * 抽奖 * @param int $aid * @param int $round * @return array @@ -40,7 +40,7 @@ class ApiBox /** - * @use 获取状态 + * 获取状态 * @param int $aid * @return array */ diff --git a/src/Api/XLive/WebRoom/V1/Index/ApiIndex.php b/src/Api/XLive/WebRoom/V1/Index/ApiIndex.php new file mode 100644 index 0000000..2bc013d --- /dev/null +++ b/src/Api/XLive/WebRoom/V1/Index/ApiIndex.php @@ -0,0 +1,38 @@ + $room_id + ]; + // {"code":0,"message":"0","ttl":1,"data":{"room_info":{"uid":11153765,"room_id":23058,"short_id":3,"title":"哔哩哔哩音悦台","cover":"","tags":"","background":"https://i0.hdslb.com/bfs/live/2836bb7b84c792e2c6aadfd4d1cce13484775fa3.jpg","description":"

这里是哔哩哔哩官方音乐台喔!

一起来听音乐吧ε=ε=(ノ≧∇≦)ノ

没想到蒸汽配圣诞下装,意外的很暴露呢=3=

\n","live_status":1,"live_start_time":1642502066,"live_screen_type":0,"lock_status":0,"lock_time":0,"hidden_status":0,"hidden_time":0,"area_id":190,"area_name":"唱见电台","parent_area_id":5,"parent_area_name":"电台","keyframe":"http://i0.hdslb.com/bfs/live-key-frame/keyframe060819060000000230586pqb4d.jpg","special_type":0,"up_session":"204681708782508562","pk_status":0,"is_studio":false,"pendants":{"frame":{"name":"","value":"","desc":""}},"on_voice_join":0,"online":3841,"room_type":{"2-3":0,"3-21":0}},"anchor_info":{"base_info":{"uname":"3号直播间","face":"http://i2.hdslb.com/bfs/face/5d35da6e93fbfb1a77ad6d1f1004b08413913f9a.jpg","gender":"保密","official_info":{"role":1,"title":"哔哩哔哩直播 官方账号","desc":"","is_nft":0,"nft_dmark":"https://i0.hdslb.com/bfs/live/9f176ff49d28c50e9c53ec1c3297bd1ee539b3d6.gif"}},"live_info":{"level":40,"level_color":16746162,"score":255529748,"upgrade_score":0,"current":[25000000,147013810],"next":[],"rank":">10000"},"relation_info":{"attention":247329},"medal_info":{"medal_name":"电音","medal_id":123,"fansclub":1342}},"news_info":{"uid":11153765,"ctime":"2021-09-24 12:49:50","content":"3号大歌厅是音悦台特别推出的测试栏目,23日-25日11点-23点为期3天,希望大家支持!"},"rankdb_info":{"roomid":23058,"rank_desc":"小时总榜","color":"#FB7299","h5_url":"https://live.bilibili.com/p/html/live-app-rankcurrent/index.html?is_live_half_webview=1&hybrid_half_ui=1,5,85p,70p,FFE293,0,30,100,10;2,2,320,100p,FFE293,0,30,100,0;4,2,320,100p,FFE293,0,30,100,0;6,5,65p,60p,FFE293,0,30,100,10;5,5,55p,60p,FFE293,0,30,100,10;3,5,85p,70p,FFE293,0,30,100,10;7,5,65p,60p,FFE293,0,30,100,10;&anchor_uid=11153765&rank_type=master_realtime_hour_room&area_hour=1&area_v2_id=190&area_v2_parent_id=5","web_url":"https://live.bilibili.com/blackboard/room-current-rank.html?rank_type=master_realtime_hour_room&area_hour=1&area_v2_id=190&area_v2_parent_id=5","timestamp":1654686465},"area_rank_info":{"areaRank":{"index":0,"rank":">1000"},"liveRank":{"rank":">10000"}},"battle_rank_entry_info":{"first_rank_img_url":"","rank_name":"尚无段位","show_status":1},"tab_info":{"list":[{"type":"seven-rank","desc":"高能榜","isFirst":1,"isEvent":0,"eventType":"","listType":"","apiPrefix":"","rank_name":"room_7day"},{"type":"guard","desc":"大航海","isFirst":0,"isEvent":0,"eventType":"","listType":"top-list","apiPrefix":"","rank_name":""}]},"activity_init_info":{"eventList":[],"weekInfo":{"bannerInfo":null,"giftName":null},"giftName":null,"lego":{"timestamp":1654686465,"config":"[{\"name\":\"frame-mng\",\"url\":\"https:\\/\\/live.bilibili.com\\/p\\/html\\/live-web-mng\\/index.html?roomid=#roomid#&arae_id=#area_id#&parent_area_id=#parent_area_id#&ruid=#ruid#\",\"startTime\":1559544736,\"endTime\":1877167950,\"type\":\"frame-mng\"},{\"name\":\"s10-fun\",\"target\":\"sidebar\",\"icon\":\"https:\\/\\/i0.hdslb.com\\/bfs\\/activity-plat\\/static\\/20200908\\/3435f7521efc759ae1f90eae5629a8f0\\/HpxrZ7SOT.png\",\"text\":\"\\u7545\\u73a9s10\",\"url\":\"https:\\/\\/live.bilibili.com\\/s10\\/fun\\/index.html?room_id=#roomid#&width=376&height=600&source=sidebar\",\"color\":\"#2e6fc0\",\"startTime\":1600920000,\"endTime\":1604721600,\"parentAreaId\":2,\"areaId\":86},{\"name\":\"genshin-avatar\",\"target\":\"sidebar\",\"icon\":\"https:\\/\\/i0.hdslb.com\\/bfs\\/activity-plat\\/static\\/20210721\\/fa538c98e9e32dc98919db4f2527ad02\\/qWxN1d0ACu.jpg\",\"text\":\"\\u539f\\u77f3\\u798f\\u5229\",\"url\":\"https:\\/\\/live.bilibili.com\\/activity\\/live-activity-full\\/genshin_avatar\\/mobile.html?no-jump=1&room_id=#roomid#&width=376&height=550#\\/\",\"color\":\"#2e6fc0\",\"frameAllowNoBg\":\"1\",\"frameAllowDrag\":\"1\",\"startTime\":1627012800,\"endTime\":1630425540,\"parentAreaId\":3,\"areaId\":321}]"}},"voice_join_info":{"status":{"open":0,"anchor_open":0,"status":0,"uid":0,"user_name":"","head_pic":"","guard":0,"start_at":0,"current_time":1654686465},"icons":{"icon_close":"https://i0.hdslb.com/bfs/live/a176d879dffe8de1586a5eb54c2a08a0c7d31392.png","icon_open":"https://i0.hdslb.com/bfs/live/70f0844c9a12d29db1e586485954290144534be9.png","icon_wait":"https://i0.hdslb.com/bfs/live/1049bb88f1e7afd839cc1de80e13228ccd5807e8.png","icon_starting":"https://i0.hdslb.com/bfs/live/948433d1647a0704f8216f017c406224f9fff518.gif"},"web_share_link":"https://live.bilibili.com/h5/23058"},"ad_banner_info":{"data":[{"id":152654,"title":"夏日歌谣季","location":"room_advertisement","position":3,"pic":"https://i0.hdslb.com/bfs/live/fb53a315289477790a4760561f8e348666d846d4.png","link":"https://live.bilibili.com/blackboard/activity-2WD0tBntYO.html","weight":0,"room_id":0,"up_id":0,"parent_area_id":0,"area_id":0,"live_status":0,"av_id":0,"is_ad":false,"ad_transparent_content":null,"show_ad_icon":false},{"id":153962,"title":"夏日互动派对","location":"room_advertisement","position":4,"pic":"https://i0.hdslb.com/bfs/live/71bedfcd89f065d8d4a45c8d8e88a59b45eac8c4.jpg","link":"https://www.bilibili.com/blackboard/live/activity-k1NFbOeWmt.html","weight":0,"room_id":0,"up_id":0,"parent_area_id":0,"area_id":0,"live_status":0,"av_id":0,"is_ad":false,"ad_transparent_content":null,"show_ad_icon":false},{"id":151469,"title":"万元直播奖金等你瓜分!","location":"room_advertisement","position":5,"pic":"https://i0.hdslb.com/bfs/live/c07bdf3bfd518967bb26bd23a588cce01740944c.jpg","link":"https://www.bilibili.com/blackboard/cxhsy.html","weight":0,"room_id":0,"up_id":0,"parent_area_id":0,"area_id":0,"live_status":0,"av_id":0,"is_ad":false,"ad_transparent_content":null,"show_ad_icon":false}]},"skin_info":{"id":0,"skin_name":"","skin_config":"","show_text":"","skin_url":"","start_time":0,"end_time":0,"current_time":1654686465},"web_banner_info":{"id":0,"title":"","left":"","right":"","jump_url":"","bg_color":"","hover_color":"","text_bg_color":"","text_hover_color":"","link_text":"","link_color":"","input_color":"","input_text_color":"","input_hover_color":"","input_border_color":"","input_search_color":""},"lol_info":{"lol_activity":{"status":0,"guess_cover":"http://i0.hdslb.com/bfs/live/61d1c4bcce470080a5408d6c03b7b48e0a0fa8d7.png","vote_cover":"https://i0.hdslb.com/bfs/activity-plat/static/20190930/4ae8d4def1bbff9483154866490975c2/oWyasOpox.png","vote_h5_url":"https://live.bilibili.com/p/html/live-app-wishhelp/index.html?is_live_half_webview=1&hybrid_biz=live-app-wishhelp&hybrid_rotate_d=1&hybrid_half_ui=1,3,100p,360,0c1333,0,30,100;2,2,375,100p,0c1333,0,30,100;3,3,100p,360,0c1333,0,30,100;4,2,375,100p,0c1333,0,30,100;5,3,100p,360,0c1333,0,30,100;6,3,100p,360,0c1333,0,30,100;7,3,100p,360,0c1333,0,30,100;8,3,100p,360,0c1333,0,30,100;","vote_use_h5":true}},"pk_info":null,"battle_info":null,"silent_room_info":{"type":"","level":0,"second":0,"expire_time":0},"switch_info":{"close_guard":false,"close_gift":false,"close_online":false,"close_danmaku":false},"record_switch_info":{"record_tab":false},"room_config_info":{"dm_text":"发个弹幕呗~"},"gift_memory_info":{"list":null},"new_switch_info":{"room-socket":1,"room-prop-send":1,"room-sailing":1,"room-info-popularity":1,"room-danmaku-editor":1,"room-effect":1,"room-fans_medal":1,"room-report":1,"room-feedback":1,"room-player-watermark":1,"room-recommend-live_off":1,"room-activity":1,"room-web_banner":1,"room-silver_seeds-box":1,"room-wishing_bottle":1,"room-board":1,"room-supplication":1,"room-hour_rank":1,"room-week_rank":1,"room-anchor_rank":1,"room-info-integral":1,"room-super-chat":1,"room-tab":1,"room-hot-rank":1,"fans-medal-progress":1,"gift-bay-screen":1,"room-enter":1,"room-my-idol":1,"room-topic":1,"fans-club":1},"super_chat_info":{"status":1,"jump_url":"https://live.bilibili.com/p/html/live-app-superchat2/index.html?is_live_half_webview=1&hybrid_half_ui=1,3,100p,70p,ffffff,0,30,100,12,0;2,2,375,100p,ffffff,0,30,100,0,0;3,3,100p,70p,ffffff,0,30,100,12,0;4,2,375,100p,ffffff,0,30,100,0,0;5,3,100p,60p,ffffff,0,30,100,12,0;6,3,100p,60p,ffffff,0,30,100,12,0;7,3,100p,60p,ffffff,0,30,100,12,0","icon":"https://i0.hdslb.com/bfs/live/0a9ebd72c76e9cbede9547386dd453475d4af6fe.png","ranked_mark":0,"message_list":[]},"online_gold_rank_info_v2":{"list":[{"uid":87212425,"face":"http://i0.hdslb.com/bfs/face/member/noface.jpg","uname":"我家的大懒猫","score":"129","rank":1,"guard_level":0},{"uid":6331378,"face":"http://i1.hdslb.com/bfs/face/95d0f044829772cfc871008b56a3e8543f6d846f.jpg","uname":"伊卡萌神","score":"109","rank":2,"guard_level":0},{"uid":8604164,"face":"http://i2.hdslb.com/bfs/face/87a572e9203955777a2c7b8cbb6f00b863a015e6.jpg","uname":"我太伤心了","score":"100","rank":3,"guard_level":0},{"uid":3051401,"face":"http://i2.hdslb.com/bfs/face/784c71adbfc68558f62f79b8a4e3c93a77ec52a9.jpg","uname":"百合天堂","score":"59","rank":4,"guard_level":0},{"uid":10113007,"face":"http://i1.hdslb.com/bfs/face/26a519556ea5b072a9c843f7d28fe0784bc55671.jpg","uname":"乃木坂七花骑","score":"57","rank":5,"guard_level":0},{"uid":27108173,"face":"http://i2.hdslb.com/bfs/face/30cd9328b0dea0303b633dd59fae0ffac94012a0.jpg","uname":"拍楼上柰子","score":"46","rank":6,"guard_level":0},{"uid":17256283,"face":"http://i1.hdslb.com/bfs/face/57b496ebadacf059f1475f164dabfbf918ec4189.jpg","uname":"MJ.King","score":"45","rank":7,"guard_level":0}]},"dm_emoticon_info":{"is_open_emoticon":1,"is_shield_emoticon":0},"dm_tag_info":{"dm_tag":0,"platform":[],"extra":"","dm_chronos_extra":"","dm_mode":[],"dm_setting_switch":0,"material_conf":null},"topic_info":{"topic_id":0,"topic_name":""},"game_info":{"game_status":0},"watched_show":{"switch":true,"num":1321,"text_small":"1321","text_large":"1321人看过","icon":"","icon_location":0,"icon_web":""},"topic_room_info":{"interactive_h5_url":"","watermark":1},"show_reserve_status":false,"second_create_info":{"click_permission":0},"video_connection_info":null,"player_throttle_info":{"status":1,"normal_sleep_time":1800,"fullscreen_sleep_time":3600,"tab_sleep_time":1800,"prompt_time":30},"guard_info":{"count":0,"anchor_guard_achieve_level":0},"hot_rank_info":null}} + return Request::getJson(true, 'other', $url, $payload); + } +} \ No newline at end of file diff --git a/src/Bootstrap/Bootstrap.php b/src/Bootstrap/Bootstrap.php index aa7ca2e..2c4be85 100644 --- a/src/Bootstrap/Bootstrap.php +++ b/src/Bootstrap/Bootstrap.php @@ -17,7 +17,6 @@ namespace Bhp\Bootstrap; -use Bhp\BiliInfo\BiliInfo; use Bhp\Cache\Cache; use Bhp\Console\Console; use Bhp\Core\Core; @@ -27,6 +26,7 @@ use Bhp\Log\Log; use Bhp\Notice\Notice; use Bhp\Plugin\Plugin; use Bhp\Request\Request; +use Bhp\Schedule\Schedule; use Bhp\Sign\Sign; use Bhp\Task\Task; use Bhp\TimeLock\TimeLock; @@ -63,6 +63,10 @@ class Bootstrap extends SingleTon { // 核心 Core::getInstance($this->global_path, $this->profile_name); + // 排程 + Schedule::getInstance(); + // 插件中心 + Plugin::getInstance(); // 配置 Config::getInstance(); // 缓存中心 @@ -87,8 +91,6 @@ class Bootstrap extends SingleTon Notice::getInstance(); // 任务中心 Task::getInstance(); - // 插件中心 - Plugin::getInstance(); // 控制台 Console::getInstance(); } diff --git a/src/Cache/Cache.php b/src/Cache/Cache.php index 8c7c4b8..654dc90 100644 --- a/src/Cache/Cache.php +++ b/src/Cache/Cache.php @@ -31,7 +31,7 @@ class Cache extends SingleTon /** * @var array|null */ - protected array $caches = []; + protected ?array $caches = []; /** * @var Flintstone @@ -73,7 +73,7 @@ class Cache extends SingleTon } /** - * @use 写入值 + * 写入值 * @param string $key * @param mixed $value * @param string|null $classname @@ -87,7 +87,7 @@ class Cache extends SingleTon } /** - * @use 获取值 + * 获取值 * @param string $key * @param string|null $classname * @return false|mixed @@ -101,7 +101,7 @@ class Cache extends SingleTon } /** - * @use 强转一下类型 + * 强转一下类型 * @param string|null $classname * @return Flintstone */ @@ -115,7 +115,7 @@ class Cache extends SingleTon } /** - * @use 获取调用者类名 + * 获取调用者类名 * @return string */ protected function getCallClassName(): string @@ -132,7 +132,7 @@ class Cache extends SingleTon } /** - * @use 去除特殊符号 + * 去除特殊符号 * @param string $str * @return string */ @@ -146,7 +146,7 @@ class Cache extends SingleTon } /** - * @use 获取调用链类 + * 获取调用链类 * @return mixed */ protected function backtraceClass(): mixed diff --git a/src/Config/Config.php b/src/Config/Config.php index 3184b5e..1c79cc2 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -31,7 +31,7 @@ class Config extends BaseResource } /** - * @use 重写获取路径 + * 重写获取路径 * @param string $filename * @return string */ diff --git a/src/Console/Console.php b/src/Console/Console.php index 69f3140..151196f 100644 --- a/src/Console/Console.php +++ b/src/Console/Console.php @@ -61,7 +61,7 @@ LOGO; } /** - * @use 解析参数 + * 解析参数 * @param array $argv * @param string $default * @return string diff --git a/src/Device/Device.php b/src/Device/Device.php index 1d58c90..d0b13b1 100644 --- a/src/Device/Device.php +++ b/src/Device/Device.php @@ -17,14 +17,12 @@ namespace Bhp\Device; -use Bhp\Log\Log; use Bhp\Util\Resource\BaseResource; class Device extends BaseResource { /** * @param string $filename - * @param string $default_filename * @return void */ public function init(string $filename = 'device.yaml'): void @@ -33,7 +31,7 @@ class Device extends BaseResource } /** - * @use 重写真实路径获取 + * 重写真实路径获取 * @param string $filename * @return string */ @@ -43,7 +41,7 @@ class Device extends BaseResource } /** - * @use 重写真实路径 + * 重写真实路径 * @param string $filename * @param string $default_filename * @return string diff --git a/src/Env/Env.php b/src/Env/Env.php index d5fd170..570d172 100644 --- a/src/Env/Env.php +++ b/src/Env/Env.php @@ -66,7 +66,7 @@ class Env extends BaseResource } /** - * @use 检查是否开启 + * 检查是否开启 * @return $this */ protected function inspectExtension(): Env @@ -84,7 +84,7 @@ class Env extends BaseResource } /** - * @use 检查php环境 + * 检查php环境 * @return $this */ protected function inspectConfigure(): Env @@ -102,7 +102,7 @@ class Env extends BaseResource } /** - * @use 重写获取路径 + * 重写获取路径 * @param string $filename * @return string */ @@ -112,7 +112,7 @@ class Env extends BaseResource } /** - * @use Check: running in docker? + * Check: running in docker? * @return bool */ public static function isDocker(): bool diff --git a/src/FilterWords/FilterWords.php b/src/FilterWords/FilterWords.php index 34c2cae..c67fb65 100644 --- a/src/FilterWords/FilterWords.php +++ b/src/FilterWords/FilterWords.php @@ -31,7 +31,7 @@ class FilterWords extends BaseResource } /** - * @use 重写真实路径 + * 重写真实路径 * @param string $filename * @return string */ diff --git a/src/Helpers.php b/src/Helpers.php index db5a2ec..2843cd7 100644 --- a/src/Helpers.php +++ b/src/Helpers.php @@ -27,7 +27,7 @@ use JetBrains\PhpStorm\NoReturn; // -------------------------------------------------------------------------------------------------------------------- /** - * @use 用户配置读取 + * 用户配置读取 * @param string $key * @param mixed|null $default * @param string $type @@ -39,7 +39,7 @@ function getConf(string $key, mixed $default = null, string $type = 'default'): } /**用户 - * @use 配置写入 + * 配置写入 * @param string $key * @param mixed $value * @return void @@ -50,7 +50,7 @@ function setConf(string $key, mixed $value): void } /** - * @use 配置开关获取(大量调用独立抽取) + * 配置开关获取(大量调用独立抽取) * @param string $key * @param bool $default * @return bool @@ -61,7 +61,7 @@ function getEnable(string $key, bool $default = false): bool } /** - * @use 获取用户相关信息(Login) + * 获取用户相关信息(Login) * @param string $key * @return mixed */ @@ -76,7 +76,7 @@ function getU(string $key): mixed } /** - * @use 设置用户相关信息(Login) + * 设置用户相关信息(Login) * @param string $key * @param mixed $value * @return void @@ -94,7 +94,7 @@ function setU(string $key, mixed $value): void // -------------------------------------------------------------------------------------------------------------------- /** - * @use 获取APP名称 + * 获取APP名称 * @return string */ function getAppName(): string @@ -103,7 +103,7 @@ function getAppName(): string } /** - * @use 获取APP版本 + * 获取APP版本 * @return string */ function getAppVersion(): string @@ -112,7 +112,7 @@ function getAppVersion(): string } /** - * @use 获取APP主页 + * 获取APP主页 * @return string */ function getAppHomePage(): string @@ -125,7 +125,7 @@ function getAppHomePage(): string // -------------------------------------------------------------------------------------------------------------------- /** - * @use 错误退出 + * 错误退出 * @param $message * @param array $context * @param int $delay @@ -147,7 +147,7 @@ function getAppHomePage(): string // -------------------------------------------------------------------------------------------------------------------- /** - * @use 获取设备信息 + * 获取设备信息 * @param string $key * @param mixed|null $default * @param string $type @@ -159,7 +159,7 @@ function getDevice(string $key, mixed $default = null, string $type = 'default') } ///** -// * @use 缓存读取 +// * 缓存读取 // * @param string $key // * @param string $extra_name // * @return mixed @@ -170,7 +170,7 @@ function getDevice(string $key, mixed $default = null, string $type = 'default') //} // ///** -// * @use 缓存写入 +// * 缓存写入 // * @param string $key // * @param $data // * @param string $extra_name diff --git a/src/Log/Log.php b/src/Log/Log.php index 781b931..f58f8df 100644 --- a/src/Log/Log.php +++ b/src/Log/Log.php @@ -39,7 +39,7 @@ class Log extends SingleTon } /** - * @use 初始化日志服务 + * 初始化日志服务 * @return Logger */ protected function getLogger(): Logger @@ -56,7 +56,7 @@ class Log extends SingleTon } /** - * @use 通用 + * 通用 * @param string $level * @param string $msg * @param array $context @@ -102,7 +102,7 @@ class Log extends SingleTon } /** - * @use 错误 + * 错误 * @param mixed $message * @param array $context * @return void @@ -113,7 +113,7 @@ class Log extends SingleTon } /** - * @use 警告 + * 警告 * @param mixed $message * @param array $context * @return void @@ -124,7 +124,7 @@ class Log extends SingleTon } /** - * @use 提醒 + * 提醒 * @param mixed $message * @param array $context * @return void @@ -135,7 +135,7 @@ class Log extends SingleTon } /** - * @use 信息 + * 信息 * @param mixed $message * @param array $context * @return void @@ -146,7 +146,7 @@ class Log extends SingleTon } /** - * @use 调试 + * 调试 * @param mixed $message * @param array $context * @return void @@ -157,7 +157,7 @@ class Log extends SingleTon } /** - * @use 堆栈 + * 堆栈 * @return string */ protected function backtrace(): string @@ -167,7 +167,7 @@ class Log extends SingleTon } /** - * @use 前缀 + * 前缀 * @return string */ protected function prefix(): string @@ -180,7 +180,7 @@ class Log extends SingleTon } /** - * @use 写日志 + * 写日志 * @param string $type * @param string $message */ @@ -198,7 +198,7 @@ class Log extends SingleTon } /** - * @use 回调 + * 回调 * @param int $levelId * @param string $level * @param mixed $message diff --git a/src/Notice/Notice.php b/src/Notice/Notice.php index 9dafdd0..140ba0a 100644 --- a/src/Notice/Notice.php +++ b/src/Notice/Notice.php @@ -41,7 +41,7 @@ class Notice extends SingleTon /** - * @use 推送消息 + * 推送消息 * @param string $type * @param string $msg * @return void @@ -58,7 +58,7 @@ class Notice extends SingleTon /** - * @use 发送消息 + * 发送消息 * @param string $type * @param string $msg * @return void @@ -100,7 +100,7 @@ class Notice extends SingleTon } /** - * @use 过滤信息 + * 过滤信息 * @param string $msg * @return bool */ @@ -119,7 +119,7 @@ class Notice extends SingleTon } /** - * @use 填充消息 + * 填充消息 * @param string $type * @param string $msg * @return array @@ -198,7 +198,7 @@ class Notice extends SingleTon } /** - * @use DingTalkbot推送 + * DingTalkbot推送 * @doc https://developers.dingtalk.com/document/robots/custom-robot-access * @param array $info */ @@ -226,7 +226,7 @@ class Notice extends SingleTon } /** - * @use TeleBot推送 + * TeleBot推送 * @doc https://core.telegram.org/bots/api#sendmessage * @param array $info */ @@ -250,8 +250,8 @@ class Notice extends SingleTon } /** - * @use ServerChan推送 - * @use https://sc.ftqq.com/ + * ServerChan推送 + * https://sc.ftqq.com/ * @param array $info */ protected function scSend(array $info): void @@ -273,7 +273,7 @@ class Notice extends SingleTon } /** - * @use ServerChan(Turbo)推送 + * ServerChan(Turbo)推送 * @doc https://sct.ftqq.com/ * @param array $info */ @@ -297,7 +297,7 @@ class Notice extends SingleTon } /** - * @use PushPlus酱推送 + * PushPlus酱推送 * @doc http://www.pushplus.plus/doc/ * @param array $info */ @@ -321,7 +321,7 @@ class Notice extends SingleTon } /** - * @use GO-CQHTTP推送 + * GO-CQHTTP推送 * @doc https://docs.go-cqhttp.org/api/ * @param array $info */ @@ -345,7 +345,7 @@ class Notice extends SingleTon } /** - * @use 个人调试使用 + * 个人调试使用 * @doc https://localhost:8921/doc * @param array $info */ @@ -370,7 +370,7 @@ class Notice extends SingleTon } /** - * @use 企业微信群机器人 + * 企业微信群机器人 * @doc https://open.work.weixin.qq.com/api/doc/90000/90136/91770 * @param array $info */ @@ -396,7 +396,7 @@ class Notice extends SingleTon } /** - * @use 企业微信应用消息 + * 企业微信应用消息 * @doc https://open.work.weixin.qq.com/wwopen/devtool/interface?doc_id=10167 * @param array $info */ @@ -445,7 +445,7 @@ class Notice extends SingleTon /** - * @use 飞书推送 + * 飞书推送 * @doc https://developers.dingtalk.com/document/robots/custom-robot-access * @param array $info */ diff --git a/src/Plugin/BasePluginInfo.php b/src/Plugin/BasePluginInfo.php index a9f7274..69806a5 100644 --- a/src/Plugin/BasePluginInfo.php +++ b/src/Plugin/BasePluginInfo.php @@ -39,7 +39,7 @@ trait BasePluginInfo protected ?array $info; /** - * @use 设置Hook + * 设置Hook * @param string $value * @param string $key * @return $this @@ -51,7 +51,7 @@ trait BasePluginInfo } /** - * @use 设置名称 + * 设置名称 * @param string $value * @param string $key * @return $this @@ -63,7 +63,7 @@ trait BasePluginInfo } /** - * @use 设置版本 + * 设置版本 * @param string $value * @param string $key * @return $this @@ -75,7 +75,7 @@ trait BasePluginInfo } /** - * @use 设置描述 + * 设置描述 * @param string $value * @param string $key * @return $this @@ -87,7 +87,7 @@ trait BasePluginInfo } /** - * @use 设置优先级 + * 设置优先级 * @param int $value * @param string $key * @return $this @@ -99,7 +99,7 @@ trait BasePluginInfo } /** - * @use 设置运行周期 + * 设置运行周期 * @param string $value * @param string $key * @return $this @@ -111,7 +111,7 @@ trait BasePluginInfo } /** - * @use 返回插件信息 + * 返回插件信息 * @return array|string[] */ public function getPluginInfo(): array diff --git a/src/Plugin/Plugin.php b/src/Plugin/Plugin.php index 8062e83..84e7cdc 100644 --- a/src/Plugin/Plugin.php +++ b/src/Plugin/Plugin.php @@ -17,27 +17,26 @@ namespace Bhp\Plugin; -use Bhp\Log\Log; use Bhp\Util\AsciiTable\AsciiTable; use Bhp\Util\DesignPattern\SingleTon; class Plugin extends SingleTon { /** - * @use 监听插件的启用/关闭|UUID下标 + * 监听插件的启用/关闭|UUID下标 * @access private * @var array */ protected array $_staff = []; /** - * @use 保存所有插件信息 + * 保存所有插件信息 * @var array */ protected array $_plugins = []; /** - * @use 保存插件优先级信息 + * 保存插件优先级信息 * @var array */ protected array $_priority = []; @@ -75,7 +74,7 @@ class Plugin extends SingleTon } /** - * @use 这个是全局使用的触发钩子动作方法 + * 这个是全局使用的触发钩子动作方法 * @param string $hook * @param string $data * @return string @@ -104,7 +103,7 @@ class Plugin extends SingleTon } /** - * @use 这里是在插件中使用的方法 用来注册插件 + * 这里是在插件中使用的方法 用来注册插件 * @param object $class_obj * @param string $method * @return void @@ -166,7 +165,7 @@ class Plugin extends SingleTon } /** - * @use 初始化插件(all) + * 初始化插件(all) * @return void */ protected function detector(): void @@ -191,10 +190,10 @@ class Plugin extends SingleTon } /** - * @use 获取插件信息(all) - * @use 假定了插件在根目录的/plugin - * @use 假定插件的入口和插件文件夹的名字是一样的 - * @use 注意:这个执行文件我放在了根目录 以下路径请根据实际情况获取 + * 获取插件信息(all) + * 假定了插件在根目录的/plugin + * 假定插件的入口和插件文件夹的名字是一样的 + * 注意:这个执行文件我放在了根目录 以下路径请根据实际情况获取 * @return array */ protected function getActivePlugins(): array @@ -217,7 +216,7 @@ class Plugin extends SingleTon } /** - * @use 插件排序 + * 插件排序 * @param string $column_key * @param int $sort_order * @return void diff --git a/src/Request/Request.php b/src/Request/Request.php index 4c36334..6c854f1 100644 --- a/src/Request/Request.php +++ b/src/Request/Request.php @@ -80,6 +80,15 @@ class Request extends SingleTon $this->timeout = $timeout; } + /** + * @return string + */ + public static function getBuvid(): string + { + return self::getInstance()->buvid; + } + + /** * 初始化客户端 * @param string $request_id @@ -97,7 +106,7 @@ class Request extends SingleTon } /** - * @use 请求地址 + * 请求地址 * @param string $request_id * @param string $url * @return $this @@ -109,7 +118,7 @@ class Request extends SingleTon } /** - * @use 请求方式 + * 请求方式 * @param string $request_id * @param string $method * @return $this @@ -121,7 +130,7 @@ class Request extends SingleTon } /** - * @use 请求头 + * 请求头 * @param string $request_id * @param string $os * @param array $headers @@ -171,7 +180,7 @@ class Request extends SingleTon } /** - * @use 客户端配置 + * 客户端配置 * @param string $request_id * @param array $add_options * @param float $timeout @@ -197,7 +206,7 @@ class Request extends SingleTon } /** - * @use 处理请求 + * 处理请求 * @param string $request_id * @return ResponseInterface */ @@ -231,7 +240,7 @@ class Request extends SingleTon } /** - * @use Method GetResponse + * Method GetResponse * @param string $os * @param string $url * @param array $params @@ -264,7 +273,7 @@ class Request extends SingleTon } /** - * @use Method Get + * Method Get * @param mixed ...$params * @return string */ @@ -275,7 +284,7 @@ class Request extends SingleTon } /** - * @use Method GetJson + * Method GetJson * @param bool|null $associative * @param mixed ...$params * @return mixed @@ -288,7 +297,7 @@ class Request extends SingleTon } /** - * @use Method PostResponse + * Method PostResponse * @param $os * @param $url * @param array $params @@ -321,7 +330,7 @@ class Request extends SingleTon } /** - * @use Method Post + * Method Post * @param mixed ...$params * @return string */ @@ -332,7 +341,7 @@ class Request extends SingleTon } /** - * @use Method PostJson + * Method PostJson * @param bool|null $associative * @param mixed ...$params * @return mixed @@ -345,7 +354,7 @@ class Request extends SingleTon } /** - * @use Method PutResponse + * Method PutResponse * @param $os * @param $url * @param array $params @@ -378,7 +387,7 @@ class Request extends SingleTon } /** - * @use Method Put + * Method Put * @param mixed ...$params * @return string */ @@ -389,7 +398,7 @@ class Request extends SingleTon } /** - * @use Method PutJson + * Method PutJson * @param bool|null $associative * @param mixed ...$params * @return mixed @@ -403,7 +412,7 @@ class Request extends SingleTon /** - * @use 下载文件 + * 下载文件 * @param $os * @param $url * @param string $filepath @@ -421,7 +430,7 @@ class Request extends SingleTon } /** - * @use 单次请求 + * 单次请求 * @param string $method * @param string $url * @param array $payload @@ -483,7 +492,7 @@ class Request extends SingleTon } /** - * @use 开始请求 + * 开始请求 * @return string */ protected function startRequest(): string @@ -515,7 +524,7 @@ class Request extends SingleTon } /** - * @use 结束请求 + * 结束请求 * @param string $request_id * @return void */ @@ -525,7 +534,7 @@ class Request extends SingleTon } /** - * @use GET请求 + * GET请求 * @param $os * @param $url * @param array $params diff --git a/src/Schedule/Schedule.php b/src/Schedule/Schedule.php new file mode 100644 index 0000000..8166f0f --- /dev/null +++ b/src/Schedule/Schedule.php @@ -0,0 +1,109 @@ +repository === '') { + self::getInstance()->repository = PROFILE_TASK_PATH . getConf('login_account.username') . '.json'; + // 仓库不存在自动创建 + // 仓库不存在自动创建 + if (!file_exists(self::getInstance()->repository)) { + $fh = fopen(self::getInstance()->repository, "w"); + fwrite($fh, "{}"); + fclose($fh); + Log::info('任务排程文件不存在,初始化所有任务。'); + } else { + Log::info('任务排程文件存在,继续执行所有任务。'); + } + } + } + + /** + * 读 + * @return array + */ + protected function reader(): array + { + $data = file_get_contents($this->repository); + return json_decode($data, true); + } + + /** + * 写 + * @param array $data + * @return int|false + */ + protected function writer(array $data): int|false + { + return file_put_contents($this->repository, json_encode($data)); + } + + + /** + * 写入 + * @param string $class + * @param int $lock + * @return void + */ + public static function set(string $class, int $lock): void + { + $data = self::getInstance()->reader(); + $data[$class] = $lock; + self::getInstance()->writer($data); + } + + /** + * 读取 + * @param string $class + * @return int + */ + public static function get(string $class): int + { + $data = self::getInstance()->reader(); + if (array_key_exists($class, $data)) { + return $data[$class]; + } + return 0; + } + + /** + * 复位 + */ + public static function restore(): void + { + Log::info('复位任务排程文件。'); + File::del(self::getInstance()->repository); + self::getInstance()->repository = ''; + self::getInstance()->init(); + } + + +} \ No newline at end of file diff --git a/src/Sign/Sign.php b/src/Sign/Sign.php index e5318f6..7a90422 100644 --- a/src/Sign/Sign.php +++ b/src/Sign/Sign.php @@ -30,11 +30,11 @@ class Sign extends SingleTon } /** - * @use 登录签名 + * 安卓 * @param array $payload * @return array */ - public static function login(array $payload): array + public static function android(array $payload): array { # Android 新 $app_key = base64_decode(getDevice('app.bili_a.app_key_n')); @@ -54,12 +54,25 @@ class Sign extends SingleTon // $payload = array_merge($payload, $default); return self::getInstance()->encryption($payload, $app_secret); - } /** - * @use 登录签名 + * 登录签名 + * @param array $payload + * @return array + */ + public static function login(array $payload): array + { + return match ((int)getConf('login_mode.mode')) { + 2, 1 => self::android($payload), + 3 => self::tv($payload), + default => self::common($payload), + }; + } + + /** + * 登录签名 * @param array $payload * @return array */ @@ -81,7 +94,7 @@ class Sign extends SingleTon } /** - * @use 通用签名 + * 通用签名 * @param array $payload * @return array */ @@ -106,7 +119,7 @@ class Sign extends SingleTon } /** - * @use 加密 + * 加密 * @param array $payload * @param string $app_secret * @return array diff --git a/src/TaskQueue/TaskQueue.php b/src/TaskQueue/TaskQueue.php new file mode 100644 index 0000000..b9b3b57 --- /dev/null +++ b/src/TaskQueue/TaskQueue.php @@ -0,0 +1,120 @@ +getCallClassName(); + if (!array_key_exists($class_name, self::getInstance()->queue)) { + self::getInstance()->queue[$class_name] = []; + } + } + + /** + * 入队 + * @param bool $status + * @return void + */ + public static function enqueue(bool $status = false): void + { + $class_name = self::getInstance()->getCallClassName(); + self::getInstance()->queue[$class_name]['pause'] = $status; + } + + /** + * 离队 + * @return bool + */ + public static function dequeue(): bool + { + return self::getInstance()->getQueue()['pause']; + } + + public static function consume() + { + + } + + public static function clear() + { + + } + + + /** + * @return array + */ + protected function getQueue(): array + { + $class_name = $this->getCallClassName(); + if (!array_key_exists($class_name, $this->queue)) { + failExit("当前类 $class_name 并未初始化任务队列"); + } + return $this->queue[$class_name]; + } + + /** + * 获取调用者类名 + * @param int $index + * @return string + */ + protected function getCallClassName(): string + { + // basename(str_replace('\\', '/', __CLASS__)); + $backtraces = debug_backtrace(); + $temp = pathinfo(basename($backtraces[1]['file']))['filename']; + // + if ($temp == basename(str_replace('\\', '/', __CLASS__))) { + return pathinfo(basename($backtraces[2]['file']))['filename']; + } else { + return $temp; + } + } + + /** + * 获取基础CLASS NAME + * @return string + */ + protected function getBaseClass(): string + { + return basename(str_replace('\\', '/', __CLASS__)); + } +} + \ No newline at end of file diff --git a/src/TimeLock/TimeLock.php b/src/TimeLock/TimeLock.php index 3da8f8f..3f526d7 100644 --- a/src/TimeLock/TimeLock.php +++ b/src/TimeLock/TimeLock.php @@ -18,6 +18,7 @@ namespace Bhp\TimeLock; use Amp\Delayed; +use Bhp\Schedule\Schedule; use Bhp\Util\DesignPattern\SingleTon; class TimeLock extends SingleTon @@ -36,9 +37,9 @@ class TimeLock extends SingleTon } /** - * @use 初始化时间锁 + * 初始化时间锁 * @param int $times - * @param bool $pause + * @param bool $status * @return void */ public static function initTimeLock(int $times = 0, bool $status = false): void @@ -50,7 +51,7 @@ class TimeLock extends SingleTon } /** - * @use 设置暂停状态 + * 设置暂停状态 * @param bool $status * @return void */ @@ -61,7 +62,7 @@ class TimeLock extends SingleTon } /** - * @use 获取暂停状态 + * 获取暂停状态 * @return bool */ public static function getPause(): bool @@ -70,7 +71,7 @@ class TimeLock extends SingleTon } /** - * @use 设置计时器 + * 设置计时器 * @param int $times * @return void */ @@ -78,15 +79,19 @@ class TimeLock extends SingleTon { $class_name = self::getInstance()->getCallClassName(); self::getInstance()->locks[$class_name]['times'] = time() + $times; + // + Schedule::set($class_name,self::getInstance()->locks[$class_name]['times']); } /** - * @use 获取计时器 - * @return bool + * 获取计时器 + * @return int */ public static function getTimes(): int { - return self::getInstance()->getLock()['times']; + $class_name = self::getInstance()->getCallClassName(); + return Schedule::get($class_name); + // return self::getInstance()->getLock()['times']; } /** @@ -102,7 +107,7 @@ class TimeLock extends SingleTon } /** - * @use used in Amp loop Delayed + * used in Amp loop Delayed * @param int $times * @return Delayed */ @@ -112,7 +117,7 @@ class TimeLock extends SingleTon } /** - * @use 定时 + * 定时 * @param int $hour 时 * @param int $minute 分 * @param int $seconds 秒 @@ -131,7 +136,7 @@ class TimeLock extends SingleTon } /** - * @use 判断是否在时间内 + * 判断是否在时间内 * @param string $first_time * @param string $second_time * @return bool @@ -150,8 +155,7 @@ class TimeLock extends SingleTon } /** - * @use 获取调用者类名 - * @param int $index + * 获取调用者类名 * @return string */ protected function getCallClassName(): string @@ -168,7 +172,7 @@ class TimeLock extends SingleTon } /** - * @use 获取基础CLASS NAME + * 获取基础CLASS NAME * @return string */ protected function getBaseClass(): string @@ -177,7 +181,7 @@ class TimeLock extends SingleTon } // /** -// * @use 暂停 +// * 暂停 // */ // public static function pauseLock(): void // { diff --git a/src/User/User.php b/src/User/User.php index 2d15cbd..30b4467 100644 --- a/src/User/User.php +++ b/src/User/User.php @@ -34,7 +34,7 @@ class User extends SingleTon } /** - * @use 转换信息 + * 转换信息 * @return array */ #[ArrayShape(['csrf' => "mixed|string", 'uid' => "mixed|string", 'sid' => "mixed|string"])] @@ -52,7 +52,7 @@ class User extends SingleTon } /** - * @use 是否为有效年度大会员 + * 是否为有效年度大会员 * @param string $title * @return bool */ diff --git a/src/Util/ArrayR/ArrayR.php b/src/Util/ArrayR/ArrayR.php index 72cfef9..1127967 100644 --- a/src/Util/ArrayR/ArrayR.php +++ b/src/Util/ArrayR/ArrayR.php @@ -20,7 +20,7 @@ namespace Bhp\Util\ArrayR; class ArrayR { /** - * @use 关联数组转字符串 + * 关联数组转字符串 * @param array $arr * @param string $sep1 * @param string $sep2 diff --git a/src/Util/AsciiTable/AsciiTable.php b/src/Util/AsciiTable/AsciiTable.php index a03ea59..765c7ef 100644 --- a/src/Util/AsciiTable/AsciiTable.php +++ b/src/Util/AsciiTable/AsciiTable.php @@ -346,7 +346,7 @@ class AsciiTable /** - * @use 数组转表格(外置) + * 数组转表格(外置) * @param array $data * @param string|null $title * @param bool $print diff --git a/src/Util/Common/Common.php b/src/Util/Common/Common.php index 7a96c12..e944f39 100644 --- a/src/Util/Common/Common.php +++ b/src/Util/Common/Common.php @@ -21,7 +21,7 @@ class Common { /** - * @use 获取十三位时间戳 + * 获取十三位时间戳 * @return int */ public static function getUnixTimestamp(): int @@ -32,7 +32,7 @@ class Common } /** - * @use 获取当月第一天及最后一天 + * 获取当月第一天及最后一天 * $day[0] 第一天 * $day[1] 最后一天 * @return array @@ -47,7 +47,7 @@ class Common /** - * @use 替换字符串 + * 替换字符串 * @param $str * @param $start * @param int $end @@ -79,7 +79,7 @@ class Common } /** - * @use 检查手机号格式 + * 检查手机号格式 * @param string $phone * @return bool */ @@ -91,4 +91,39 @@ class Common } return true; } + + /** + * 自定义UUID + * @param string $data + * @return string + */ + public static function customCreateUUID(string $data): string + { + //strrev + $chars = md5($data); + return substr($chars, 0, 8) . '-' + . substr($chars, 8, 4) . '-' + . substr($chars, 12, 4) . '-' + . substr($chars, 16, 4) . '-' + . substr($chars, 20, 12); + } + + /** + * @param int $length + * @return string + */ + public static function randString(int $length):string + { +// $output=''; +// for ($a = 0; $a<$length; $a++) { +// $output .= chr(mt_rand(33, 126)); //生成php随机数 +// } +// return $output; + $pattern = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ'; + for ($i = 0; $i < $length; $i++) { + $key .= $pattern[mt_rand(0, 35)]; //生成php随机数 + } + return $key; + } + } \ No newline at end of file diff --git a/src/Util/DesignPattern/SingleTon.php b/src/Util/DesignPattern/SingleTon.php index 8899f07..8d75239 100644 --- a/src/Util/DesignPattern/SingleTon.php +++ b/src/Util/DesignPattern/SingleTon.php @@ -21,20 +21,20 @@ class SingleTon { /** - * @use 创建静态私有的变量保存该类对象 + * 创建静态私有的变量保存该类对象 * @var array|null */ private static ?array $_instances = []; /** - * @use SingleTon constructor. 私有的构造方法|防止使用new直接创建对象 + * SingleTon constructor. 私有的构造方法|防止使用new直接创建对象 */ private function __construct() { } /** - * @use 创建__clone方法防止对象被复制克隆 + * 创建__clone方法防止对象被复制克隆 * @return void */ private function __clone(): void @@ -42,7 +42,7 @@ class SingleTon } /** - * @use 放置反序列化 + * 放置反序列化 * @return void */ public function __wakeup(): void diff --git a/src/Util/Fake/Fake.php b/src/Util/Fake/Fake.php index 4c57f38..587fd56 100644 --- a/src/Util/Fake/Fake.php +++ b/src/Util/Fake/Fake.php @@ -20,7 +20,7 @@ namespace Bhp\Util\Fake; class Fake { /** - * @use 生成UUID + * 生成UUID * @return string */ public static function uuid(): string @@ -43,7 +43,7 @@ class Fake } /** - * @use 生成uuid4 + * 生成uuid4 * @return string */ public static function uuid4(): string @@ -64,7 +64,7 @@ class Fake } /** - * @use 生成hash + * 生成hash * @return string */ public static function hash(): string @@ -76,7 +76,7 @@ class Fake } /** - * @use 生成BUVID + * 生成BUVID * @return string */ public static function buvid(): string @@ -93,7 +93,7 @@ class Fake } /** - * @use 获取颜文字信息 + * 获取颜文字信息 * @return string */ public static function emoji(): string diff --git a/src/Util/Fake/Faker.php b/src/Util/Fake/Faker.php index 32b03dd..f1fcf34 100644 --- a/src/Util/Fake/Faker.php +++ b/src/Util/Fake/Faker.php @@ -117,7 +117,7 @@ class Faker } /** - * @use 转Ascii + * 转Ascii * @param $string * @return array|string */ diff --git a/src/Util/Os/File.php b/src/Util/Os/File.php new file mode 100644 index 0000000..7793ef9 --- /dev/null +++ b/src/Util/Os/File.php @@ -0,0 +1,263 @@ + basename($filename), + "文件类型" => filetype($filename), + "文件大小" => static::transByte(filesize($filename)), + "创建时间" => date('Y-m-d H:i:s', filectime($filename)), + "修改时间" => date('Y-m-d H:i:s', filemtime($filename)), + "上一次访问时间" => date('Y-m-d H:i:s', fileatime($filename)), + ]; + } + + /** + * 转换字节大小 + * @param int $byte 字节大小 + * @param int $precision 小数点保留位数 + * @return string 转换后的单位 + */ + public static function transByte(int $byte, int $precision = 2): string + { + $kb = 1024; + $mb = 1024 * $kb; + $gb = 1024 * $mb; + $tb = 1024 * $gb; + + if ($byte < $kb) { + return $byte . 'B'; + } + + if ($byte < $mb) { + // 默认四舍五入, 保留两位小数 + return round($byte / $kb, $precision) . ' KB'; + } + + if ($byte < $gb) { + return round($byte / $mb, $precision) . ' MB'; + } + + if ($byte < $tb) { + return round($byte / $tb, $precision) . ' GB'; + } + return ''; + } + + /** + * 以字符串形式读取内容 + * @param string $filename + * @return false|string + */ + public static function readString(string $filename): bool|string + { + if (is_file($filename) && is_readable($filename)) { + return file_get_contents($filename); + } + return false; + } + + /** + * 以数组形式读取内容 + * @param string $filename + * @param bool $skip_empty_lines + * @return array|false + */ + public static function readArray(string $filename, bool $skip_empty_lines = false): bool|array + { + if (is_file($filename) && is_readable($filename)) { + if ($skip_empty_lines) { + // 忽略空行读取 + return file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + } else { + // 以数组形式直接读取, 不忽略空行 + return file($filename); + } + } + return false; + } + + /** + * 增加文件内容升级版 + * @param string $filename 路径名称 + * @param mixed $data 需要写入的数据 + * @param boolean $clear_content 是否清空原始内容再写入 + * @return bool true|false + */ + public static function write(string $filename, mixed $data, bool $clear_content = false): bool + { + $srcData = ''; + $dirname = dirname($filename); + // 检测目标路径是否存在 + if (!file_exists($dirname)) { + mkdir($dirname, 0777, true); + } + // 文件存在并且不清空原始文件 + if (is_file($filename) && !$clear_content) { + $srcData = file_get_contents($filename); + } + + // 检测数据是否为数组或者对象 + if (is_array($data) || is_object($data)) { + // 序列化数据 + $data = serialize($data); + } + // 拼装数据 + $data = $srcData . $data; + // 写入数据 + if (file_put_contents($filename, $data) !== false) { + return true; + } + return false; + } + + /** + * 截断文本 + * @param string $filename 文件名称 + * @param int $length 截断文本长度 + * @return boolean true|false + */ + public static function truncate(string $filename, int $length): bool + { + // 判断文件是否存在并且是可写的 + if (is_file($filename) && is_writeable($filename)) { + // 创建文件句柄, 以读写方式打开 + $handler = fopen($filename, 'rb+'); + $length = max($length, 0); + ftruncate($handler, $length); + fclose($handler); + } + return false; + } +} \ No newline at end of file diff --git a/src/Util/Os/Path.php b/src/Util/Os/Path.php index 8ce8ed1..d8e9c3a 100644 --- a/src/Util/Os/Path.php +++ b/src/Util/Os/Path.php @@ -20,7 +20,7 @@ namespace Bhp\Util\Os; class Path { /** - * @use Folder Permissions + * Folder Permissions * @param string $path * @param int $permissions * @return void @@ -38,7 +38,7 @@ class Path } /** - * @use Create Folder + * Create Folder * @param string $path * @param int $permissions * @return void diff --git a/src/Util/Qrcode/Lib/QrRawCode.php b/src/Util/Qrcode/Lib/QrRawCode.php index c35ccb5..4515b76 100644 --- a/src/Util/Qrcode/Lib/QrRawCode.php +++ b/src/Util/Qrcode/Lib/QrRawCode.php @@ -21,15 +21,15 @@ use Exception; class QrRawCode { - public $version; - public $datacode = []; - public $ecccode = []; - public $blocks; - public $rsblocks = []; //of RSblock - public $count; - public $dataLength; - public $eccLength; - public $b1; + public int $version; + public ?array $datacode = []; + public array $ecccode = []; + public mixed $blocks; + public array $rsblocks = []; //of RSblock + public int $count; + public int|float $dataLength; + public int|float $eccLength; + public mixed $b1; //---------------------------------------------------------------------- public function __construct(QrInput $input) @@ -103,7 +103,7 @@ class QrRawCode } //---------------------------------------------------------------------- - public function getCode() + public function getCode(): int { $ret = null; @@ -113,11 +113,11 @@ class QrRawCode if ($col >= $this->rsblocks[0]->dataLength) { $row += $this->b1; } - $ret = (int) $this->rsblocks[$row]->data[$col]; + $ret = (int)$this->rsblocks[(int)$row]->data[(int)$col]; } else if ($this->count < $this->dataLength + $this->eccLength) { $row = ($this->count - $this->dataLength) % $this->blocks; $col = ($this->count - $this->dataLength) / $this->blocks; - $ret = $this->rsblocks[$row]->ecc[$col]; + $ret = (int)$this->rsblocks[(int)$row]->ecc[(int)$col]; } else { return 0; } diff --git a/src/Util/Qrcode/Lib/QrTools.php b/src/Util/Qrcode/Lib/QrTools.php index de7e6f6..9349e56 100644 --- a/src/Util/Qrcode/Lib/QrTools.php +++ b/src/Util/Qrcode/Lib/QrTools.php @@ -20,7 +20,7 @@ namespace Bhp\Util\Qrcode\Lib; class QrTools { /** - * @use 二值化 + * 二值化 * @param array $frame * @return array */ diff --git a/src/Util/Qrcode/Qrcode.php b/src/Util/Qrcode/Qrcode.php index 65e7ee7..efacc3d 100644 --- a/src/Util/Qrcode/Qrcode.php +++ b/src/Util/Qrcode/Qrcode.php @@ -66,7 +66,7 @@ class Qrcode } /** - * @use determine the console is windows or linux. + * determine the console is windows or linux. * @return bool */ protected static function isWin(): bool @@ -75,7 +75,7 @@ class Qrcode } /** - * @use init qrCode style. + * init qrCode style. * @param OutputInterface $output */ protected static function initQrcodeStyle(OutputInterface $output): void diff --git a/src/Util/Resource/BaseResource.php b/src/Util/Resource/BaseResource.php index af8de48..ee3148d 100644 --- a/src/Util/Resource/BaseResource.php +++ b/src/Util/Resource/BaseResource.php @@ -23,37 +23,37 @@ use Bhp\Util\DesignPattern\SingleTon; abstract class BaseResource extends SingleTon { /** - * @use 配置对象变量 + * 配置对象变量 * @var EResource */ protected ?Resource $resource = null; /** - * @use 配置文件名 + * 配置文件名 * @var string */ protected string $filename = ''; /** - * @use 配置文件路径 + * 配置文件路径 * @var string */ protected string $filepath = ''; /** - * @use 最后访问文件时间 + * 最后访问文件时间 * @var int */ protected int $last_access = 0; /** - * @use 解析器 + * 解析器 * @var string */ protected string $parser = ''; /** - * @use 设置值 + * 设置值 * @param string $key * @param mixed $value * @return void @@ -65,7 +65,7 @@ abstract class BaseResource extends SingleTon } /** - * @use 根据类型获取值 + * 根据类型获取值 * @param string $key * @param mixed|null $default * @param string $type @@ -88,7 +88,7 @@ abstract class BaseResource extends SingleTon } /** - * @use 加载资源文件 + * 加载资源文件 * @param string $filename * @param string $parser * @return void @@ -106,7 +106,7 @@ abstract class BaseResource extends SingleTon } /** - * @use 检查文件是否存在 + * 检查文件是否存在 * @param string $filepath * @param string $filename * @return void @@ -136,7 +136,7 @@ abstract class BaseResource extends SingleTon } /** - * @use 更新最新修改时间 + * 更新最新修改时间 * @return void */ protected function updateLastAccess(): void @@ -145,7 +145,7 @@ abstract class BaseResource extends SingleTon } /** - * @use 获取文件真实路径 + * 获取文件真实路径 * @param string $filename * @return string */ diff --git a/src/Util/Resource/BaseResourcePoly.php b/src/Util/Resource/BaseResourcePoly.php index 21ef381..db34f2f 100644 --- a/src/Util/Resource/BaseResourcePoly.php +++ b/src/Util/Resource/BaseResourcePoly.php @@ -22,37 +22,37 @@ use Bhp\Util\Resource\Resource as EResource; abstract class BaseResourcePoly { /** - * @use 配置对象变量 + * 配置对象变量 * @var EResource */ protected ?Resource $resource = null; /** - * @use 配置文件名 + * 配置文件名 * @var string */ protected string $filename = ''; /** - * @use 配置文件路径 + * 配置文件路径 * @var string */ protected string $filepath = ''; /** - * @use 最后访问文件时间 + * 最后访问文件时间 * @var int */ protected int $last_access = 0; /** - * @use 解析器 + * 解析器 * @var string */ protected string $parser = ''; /** - * @use 设置值 + * 设置值 * @param string $key * @param mixed $value * @return void @@ -64,7 +64,7 @@ abstract class BaseResourcePoly } /** - * @use 根据类型获取值 + * 根据类型获取值 * @param string $key * @param mixed|null $default * @param string $type @@ -87,7 +87,7 @@ abstract class BaseResourcePoly } /** - * @use 加载资源文件 + * 加载资源文件 * @param string $filename * @param string $parser * @return void @@ -105,7 +105,7 @@ abstract class BaseResourcePoly } /** - * @use 检查文件是否存在 + * 检查文件是否存在 * @param string $filepath * @param string $filename * @return void @@ -135,7 +135,7 @@ abstract class BaseResourcePoly } /** - * @use 更新最新修改时间 + * 更新最新修改时间 * @return void */ protected function updateLastAccess(): void @@ -144,7 +144,7 @@ abstract class BaseResourcePoly } /** - * @use 获取文件真实路径 + * 获取文件真实路径 * @param string $filename * @return string */ diff --git a/src/Util/Resource/Resource.php b/src/Util/Resource/Resource.php index e68f03b..61e96a2 100644 --- a/src/Util/Resource/Resource.php +++ b/src/Util/Resource/Resource.php @@ -50,7 +50,7 @@ class Resource extends Collection protected string $parser; /** - * @use 加载资源文件 + * 加载资源文件 * @param string|array $file_path * @param string $parser * @return Resource @@ -70,7 +70,7 @@ class Resource extends Collection } /** - * @use 切换解析器 + * 切换解析器 * @param string $filepath * @param string $format * @return Data @@ -87,7 +87,7 @@ class Resource extends Collection } /** - * @use 清空并重载数据 + * 清空并重载数据 * @return Resource */ protected function reload(): Resource diff --git a/src/core/Core.php b/src/core/Core.php index 9fa46af..a6ce109 100644 --- a/src/core/Core.php +++ b/src/core/Core.php @@ -49,7 +49,7 @@ class Core extends SingleTon } /** - * @use 初始化全局常量 + * 初始化全局常量 * @return void */ protected function initSystemConstant(): void @@ -71,7 +71,7 @@ class Core extends SingleTon } /** - * @use 补充目录 + * 补充目录 * @param string $path * @return string */ @@ -82,7 +82,7 @@ class Core extends SingleTon } /** - * @use 初始化系统目录(创建、设置权限) + * 初始化系统目录(创建、设置权限) * @return void */ protected function initSystemPath(): void