mirror of
https://github.com/lkeme/BiliHelper-personal.git
synced 2025-12-18 17:00:06 +08:00
[feat] Common
This commit is contained in:
parent
6d5ea149fd
commit
e37434e3c8
12
.github/FUNDING.yml
vendored
Normal file
12
.github/FUNDING.yml
vendored
Normal file
@ -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' ]
|
||||
47
.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE_CN.md
vendored
Normal file
47
.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE_CN.md
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
# Issue: BiliHepler 程序问题
|
||||
|
||||
<!-- 上面是标题 下面才是正文 -->
|
||||
|
||||
### 版本、安装方式、系统
|
||||
|
||||
1. 你在使用什么版本的 BiliHelper
|
||||
|
||||
|
||||
2. 你通过什么方式安装 BiliHepler
|
||||
|
||||
|
||||
3. 你所使用的操作系统
|
||||
|
||||
---
|
||||
|
||||
### 描述问题
|
||||
|
||||
<!-- 在下方简要描述问题 -->
|
||||
|
||||
|
||||
---
|
||||
|
||||
### 复现问题的步骤
|
||||
|
||||
<!-- 在下方描述如何复现问题 -->
|
||||
|
||||
|
||||
---
|
||||
|
||||
### BiliHelper 运行日志:
|
||||
|
||||
<!-- 如果条件允许请附日志 -->
|
||||
|
||||
```shell
|
||||
# 此处贴入运行日志
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 截图
|
||||
|
||||
<!-- 如果条件允许请附图 -->
|
||||
|
||||
47
.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE_EN.md
vendored
Normal file
47
.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE_EN.md
vendored
Normal file
@ -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
|
||||
|
||||
<!-- Describe your problem below -->
|
||||
|
||||
|
||||
---
|
||||
|
||||
### Steps to reproduce
|
||||
|
||||
<!-- Describe how to reproduce problem below -->
|
||||
|
||||
|
||||
---
|
||||
|
||||
### BiliHelper Logs:
|
||||
|
||||
<!-- Paste log if possible -->
|
||||
|
||||
```shell
|
||||
# Paste running logs here
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Screenshot
|
||||
|
||||
<!-- Paste screenshot if possible -->
|
||||
|
||||
22
.github/workflows/build_image_bhp.yml
vendored
Normal file
22
.github/workflows/build_image_bhp.yml
vendored
Normal file
@ -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 }}
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -49,7 +49,7 @@ class LiveSignIn extends BasePlugin
|
||||
}
|
||||
|
||||
/**
|
||||
* @use 执行
|
||||
* 执行
|
||||
* @return void
|
||||
*/
|
||||
public function execute(): void
|
||||
|
||||
@ -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":"<user mid>","access_token":"<current 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
|
||||
*/
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -49,7 +49,7 @@ class PluginTemplate extends BasePlugin
|
||||
}
|
||||
|
||||
/**
|
||||
* @use 执行
|
||||
* 执行
|
||||
* @return void
|
||||
*/
|
||||
public function execute(): void
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -47,7 +47,7 @@ enable = true
|
||||
|
||||
; 直播签到
|
||||
[live_sign_in]
|
||||
enable =true
|
||||
enable = true
|
||||
|
||||
; 游戏赛事竞猜预测(破产机)/每日竞猜次数/每次竞猜硬币(1-10)/下注(1.压大,2.压小,3.随机)
|
||||
[game_forecast]
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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
|
||||
|
||||
66
src/Api/Custom/ApiCalcSign.php
Normal file
66
src/Api/Custom/ApiCalcSign.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Website: https://mudew.com/
|
||||
* Author: Lkeme
|
||||
* License: The MIT License
|
||||
* Email: Useri@live.cn
|
||||
* Updated: 2022 ~ 2023
|
||||
*
|
||||
* _____ _ _ _ _ _ _____ _ _____ _____ _____
|
||||
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & /l、
|
||||
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、 。 7
|
||||
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ / \、゙ ~ヽ *
|
||||
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \ じしf_, )ノ
|
||||
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
|
||||
*/
|
||||
|
||||
namespace Bhp\Api\Custom;
|
||||
|
||||
use Bhp\Request\Request;
|
||||
use Bhp\User\User;
|
||||
use JetBrains\PhpStorm\ArrayShape;
|
||||
|
||||
class ApiCalcSign
|
||||
{
|
||||
|
||||
protected static function formatT(array $t): array
|
||||
{
|
||||
return $t;
|
||||
// return [
|
||||
// 'id' => $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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ use Bhp\User\User;
|
||||
class ApiDynamicSvr
|
||||
{
|
||||
/**
|
||||
* @use 获取关注Up动态
|
||||
* 获取关注Up动态
|
||||
* @return mixed
|
||||
*/
|
||||
public static function followUpDynamic(): array
|
||||
|
||||
@ -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
|
||||
|
||||
@ -23,7 +23,7 @@ use Bhp\Sign\Sign;
|
||||
class ApiLoveClub
|
||||
{
|
||||
/**
|
||||
* @use 获取我的友爱社列表
|
||||
* 获取我的友爱社列表
|
||||
* @return array
|
||||
*/
|
||||
public static function myGroups(): array
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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":"<user mid>","access_token":"<current 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -23,7 +23,7 @@ use Bhp\Util\Common\Common;
|
||||
class ApiWallet
|
||||
{
|
||||
/**
|
||||
* @use 获取用户钱包
|
||||
* 获取用户钱包
|
||||
* @return array
|
||||
*/
|
||||
public static function getUserWallet(): array
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -23,7 +23,7 @@ use Bhp\User\User;
|
||||
class ApiShare
|
||||
{
|
||||
/**
|
||||
* @use 分享视频
|
||||
* 分享视频
|
||||
* @param string $aid
|
||||
* @param string $cid
|
||||
* @return array
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
@ -22,7 +22,7 @@ use Bhp\Request\Request;
|
||||
class ApiUser
|
||||
{
|
||||
/**
|
||||
* @use 用户信息
|
||||
* 用户信息
|
||||
* @return array
|
||||
*/
|
||||
public static function userInfo(): array
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
44
src/Api/XLive/AppUcenter/V1/ApiFansMedal.php
Normal file
44
src/Api/XLive/AppUcenter/V1/ApiFansMedal.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Website: https://mudew.com/
|
||||
* Author: Lkeme
|
||||
* License: The MIT License
|
||||
* Email: Useri@live.cn
|
||||
* Updated: 2022 ~ 2023
|
||||
*
|
||||
* _____ _ _ _ _ _ _____ _ _____ _____ _____
|
||||
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & /l、
|
||||
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、 。 7
|
||||
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ / \、゙ ~ヽ *
|
||||
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \ じしf_, )ノ
|
||||
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
|
||||
*/
|
||||
|
||||
namespace Bhp\Api\XLive\AppUcenter\V1;
|
||||
|
||||
use Bhp\Request\Request;
|
||||
use Bhp\Sign\Sign;
|
||||
|
||||
class ApiFansMedal
|
||||
{
|
||||
/**
|
||||
* 粉丝勋章面板
|
||||
* @param int $pn
|
||||
* @param int $ps
|
||||
* @return array
|
||||
*/
|
||||
public static function panel(int $pn, int $ps): array
|
||||
{
|
||||
// https://live.bilibili.com/p/html/live-app-fansmedal-manange/index.html
|
||||
$url = 'https://api.live.bilibili.com/xlive/app-ucenter/v1/fansMedal/panel';
|
||||
$payload = [
|
||||
'page' => $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));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
96
src/Api/XLive/DataInterface/V1/HeartBeat/ApiHeartBeat.php
Normal file
96
src/Api/XLive/DataInterface/V1/HeartBeat/ApiHeartBeat.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Website: https://mudew.com/
|
||||
* Author: Lkeme
|
||||
* License: The MIT License
|
||||
* Email: Useri@live.cn
|
||||
* Updated: 2022 ~ 2023
|
||||
*
|
||||
* _____ _ _ _ _ _ _____ _ _____ _____ _____
|
||||
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & /l、
|
||||
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、 。 7
|
||||
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ / \、゙ ~ヽ *
|
||||
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \ じしf_, )ノ
|
||||
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
|
||||
*/
|
||||
|
||||
namespace Bhp\Api\XLive\DataInterface\V1\HeartBeat;
|
||||
|
||||
use Bhp\Api\Custom\ApiCalcSign;
|
||||
use Bhp\Config\Config;
|
||||
use Bhp\Log\Log;
|
||||
use Bhp\Request\Request;
|
||||
use Bhp\Sign\Sign;
|
||||
use Bhp\User\User;
|
||||
use Bhp\Util\Common\Common;
|
||||
|
||||
class ApiHeartBeat
|
||||
{
|
||||
/**
|
||||
* 心跳
|
||||
* @param int $room_id
|
||||
* @param int $up_id
|
||||
* @param int $parent_id
|
||||
* @param int $area_id
|
||||
* @param string $client_sign
|
||||
* @return array
|
||||
*/
|
||||
public static function mobileHeartBeat(int $room_id, int $up_id, int $parent_id, int $area_id, string $client_sign): array
|
||||
{
|
||||
$user = User::parseCookie();
|
||||
//
|
||||
$url = 'https://live-trace.bilibili.com/xlive/data-interface/v1/heartbeat/mobileHeartBeat';
|
||||
$headers = [
|
||||
'Content-Type' => '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'];
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
*/
|
||||
|
||||
38
src/Api/XLive/WebRoom/V1/Index/ApiIndex.php
Normal file
38
src/Api/XLive/WebRoom/V1/Index/ApiIndex.php
Normal file
File diff suppressed because one or more lines are too long
@ -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();
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -31,7 +31,7 @@ class Config extends BaseResource
|
||||
}
|
||||
|
||||
/**
|
||||
* @use 重写获取路径
|
||||
* 重写获取路径
|
||||
* @param string $filename
|
||||
* @return string
|
||||
*/
|
||||
|
||||
@ -61,7 +61,7 @@ LOGO;
|
||||
}
|
||||
|
||||
/**
|
||||
* @use 解析参数
|
||||
* 解析参数
|
||||
* @param array $argv
|
||||
* @param string $default
|
||||
* @return string
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -31,7 +31,7 @@ class FilterWords extends BaseResource
|
||||
}
|
||||
|
||||
/**
|
||||
* @use 重写真实路径
|
||||
* 重写真实路径
|
||||
* @param string $filename
|
||||
* @return string
|
||||
*/
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
109
src/Schedule/Schedule.php
Normal file
109
src/Schedule/Schedule.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Website: https://mudew.com/
|
||||
* Author: Lkeme
|
||||
* License: The MIT License
|
||||
* Email: Useri@live.cn
|
||||
* Updated: 2022 ~ 2023
|
||||
*
|
||||
* _____ _ _ _ _ _ _____ _ _____ _____ _____
|
||||
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & /l、
|
||||
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、 。 7
|
||||
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ / \、゙ ~ヽ *
|
||||
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \ じしf_, )ノ
|
||||
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
|
||||
*/
|
||||
|
||||
namespace Bhp\Schedule;
|
||||
|
||||
use Bhp\Log\Log;
|
||||
use Bhp\Util\DesignPattern\SingleTon;
|
||||
use Bhp\Util\Os\File;
|
||||
|
||||
class Schedule extends SingleTon
|
||||
{
|
||||
protected string $repository = '';
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
if (self::getInstance()->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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -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
|
||||
|
||||
120
src/TaskQueue/TaskQueue.php
Normal file
120
src/TaskQueue/TaskQueue.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Website: https://mudew.com/
|
||||
* Author: Lkeme
|
||||
* License: The MIT License
|
||||
* Email: Useri@live.cn
|
||||
* Updated: 2022 ~ 2023
|
||||
*
|
||||
* _____ _ _ _ _ _ _____ _ _____ _____ _____
|
||||
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & /l、
|
||||
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、 。 7
|
||||
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ / \、゙ ~ヽ *
|
||||
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \ じしf_, )ノ
|
||||
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
|
||||
*/
|
||||
|
||||
namespace Bhp\TaskQueue;
|
||||
|
||||
use Amp\Delayed;
|
||||
use Bhp\Util\DesignPattern\SingleTon;
|
||||
|
||||
class TaskQueue extends SingleTon
|
||||
{
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
protected ?array $queue = [];
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化任务队列
|
||||
* @return void
|
||||
*/
|
||||
public static function initTaskQueue(): void
|
||||
{
|
||||
$class_name = self::getInstance()->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__));
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
// {
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
@ -20,7 +20,7 @@ namespace Bhp\Util\ArrayR;
|
||||
class ArrayR
|
||||
{
|
||||
/**
|
||||
* @use 关联数组转字符串
|
||||
* 关联数组转字符串
|
||||
* @param array $arr
|
||||
* @param string $sep1
|
||||
* @param string $sep2
|
||||
|
||||
@ -346,7 +346,7 @@ class AsciiTable
|
||||
|
||||
|
||||
/**
|
||||
* @use 数组转表格(外置)
|
||||
* 数组转表格(外置)
|
||||
* @param array $data
|
||||
* @param string|null $title
|
||||
* @param bool $print
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -117,7 +117,7 @@ class Faker
|
||||
}
|
||||
|
||||
/**
|
||||
* @use 转Ascii
|
||||
* 转Ascii
|
||||
* @param $string
|
||||
* @return array|string
|
||||
*/
|
||||
|
||||
263
src/Util/Os/File.php
Normal file
263
src/Util/Os/File.php
Normal file
@ -0,0 +1,263 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Website: https://mudew.com/
|
||||
* Author: Lkeme
|
||||
* License: The MIT License
|
||||
* Email: Useri@live.cn
|
||||
* Updated: 2022 ~ 2023
|
||||
*
|
||||
* _____ _ _ _ _ _ _____ _ _____ _____ _____
|
||||
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & /l、
|
||||
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、 。 7
|
||||
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ / \、゙ ~ヽ *
|
||||
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \ じしf_, )ノ
|
||||
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
|
||||
*/
|
||||
|
||||
namespace Bhp\Util\Os;
|
||||
|
||||
class File
|
||||
{
|
||||
/**
|
||||
* 创建文件
|
||||
* @param string $filename
|
||||
* @return bool
|
||||
*/
|
||||
public static function create(string $filename): bool
|
||||
{
|
||||
if (file_exists($filename)) {
|
||||
return false;
|
||||
}
|
||||
// 判断文件类型是否为目录, 如果不存在则创建
|
||||
if (!file_exists(dirname($filename))) {
|
||||
mkdir(dirname($filename), 0777, true);
|
||||
}
|
||||
if (touch($filename)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param string $filename
|
||||
* @return bool
|
||||
*/
|
||||
public static function del(string $filename): bool
|
||||
{
|
||||
// 如果文件不存在或者权限不够, 则返回false
|
||||
if (!file_exists($filename) || !is_writeable($filename)) {
|
||||
return false;
|
||||
}
|
||||
if (unlink($filename)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拷贝文件
|
||||
* @param string $filename
|
||||
* @param string $dest
|
||||
* @return bool
|
||||
*/
|
||||
public static function copy(string $filename, string $dest): bool
|
||||
{
|
||||
if (!is_dir($dest)) {
|
||||
mkdir($dest, 0777, true);
|
||||
}
|
||||
// DIRECTORY_SEPARATOR '/'分割符
|
||||
$destName = $dest . DIRECTORY_SEPARATOR . basename($filename);
|
||||
if (copy($filename, $destName)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件重命名
|
||||
* @param string $oldname
|
||||
* @param string $newname
|
||||
* @return bool
|
||||
*/
|
||||
public static function rename(string $oldname, string $newname): bool
|
||||
{
|
||||
if (!is_file($oldname)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$path = dirname($oldname);
|
||||
$destName = $path . DIRECTORY_SEPARATOR . $newname;
|
||||
|
||||
if (!is_file($destName)) {
|
||||
return rename($oldname, $newname);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 剪切文件
|
||||
* @param $filename
|
||||
* @param $dest
|
||||
* @return bool
|
||||
*/
|
||||
public static function cut($filename, $dest): bool
|
||||
{
|
||||
if (!file_exists($filename)) {
|
||||
return false;
|
||||
}
|
||||
// 检测文件目录是否存在, 如果不存在则创建
|
||||
if (!is_dir($dest)) {
|
||||
mkdir($dest, 0777, true);
|
||||
}
|
||||
// 检测文件夹是否包含同名文件
|
||||
$destName = $dest . DIRECTORY_SEPARATOR . basename($filename);
|
||||
// 如果是一个文档则returnfalse 如果不是文档则剪切文档
|
||||
if (!is_file($destName)) {
|
||||
return rename($filename, $destName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件详细信息
|
||||
* @param string $filename
|
||||
* @return array|bool
|
||||
*/
|
||||
public static function getInfo(string $filename): array|bool
|
||||
{
|
||||
// 如果不是文件 或者 不可读返回false
|
||||
if (!is_file($filename) || !is_readable($filename)) {
|
||||
return false;
|
||||
}
|
||||
// 否则直接返回文件信息, 定义一个关联数组
|
||||
return [
|
||||
"文件名称" => 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;
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ namespace Bhp\Util\Qrcode\Lib;
|
||||
class QrTools
|
||||
{
|
||||
/**
|
||||
* @use 二值化
|
||||
* 二值化
|
||||
* @param array $frame
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user