[add] new Plugin@VipPoint@beta

This commit is contained in:
Lkeme 2022-09-10 18:56:19 +08:00
parent 924c71ad9e
commit f4be245420
10 changed files with 554 additions and 16 deletions

View File

@ -92,6 +92,7 @@ Group: [602815575](https://jq.qq.com/?_wv=1027&k=UaalVexM) | **请不要来问
| LiveReservation | 0.0.1 | 预约直播有奖 | Lkeme | 1109 | 1-3(小时) | √ |
| LiveGoldBox | 0.0.1 | 直播金色宝箱(实物抽奖) | Lkeme | 1110 | 6-10(分钟) | √ |
| AwardRecords | 0.0.1 | 获奖记录 | Lkeme | 1111 | 5(分钟) | √ |
| VipPoint | 0.0.1 | 大会员积分 | Lkeme | 1112 | 5(分钟) | √ |
</details>

View File

@ -16,15 +16,15 @@
通常使用 `composer` 工具会自动检测以下依赖问题。
|Requirement |
|--------------------|
|PHP >=8.0 |
|php_curl |
|php_sockets |
|php_openssl |
|php_json |
|php_zlib |
|php_mbstring |
| Requirement |
|--------------|
| PHP >=8.1 |
| php_curl |
| php_sockets |
| php_openssl |
| php_json |
| php_zlib |
| php_mbstring |
## 用户文件夹含义
@ -173,6 +173,14 @@ $ php app.php
8. 请保证配置文件存在,否则默认加载`user`配置文件夹
9. 单个或者多个插件测试
```shell
$ php app.php test m:d -p plugin
$ php app.php test m:d -P plugin,plugin1
$ php app.php test m:d -p VipPoint
```
<p align="center"><img width="680px" src="https://user-images.githubusercontent.com/19500576/118621472-f8455d80-b7f8-11eb-9fec-500148a566b4.png"></p>
[comment]: <> (<p align="center"><img width="680px" src="https://i.loli.net/2018/04/21/5adb497dc3ece.png"></p>)
@ -195,7 +203,11 @@ $ docker run -itd --rm -e USER_NAME=你的B站登录账号 -e USER_PASSWORD=你
[//]: # (1. 下载[配置文件]&#40;https://raw.githubusercontent.com/lkeme/BiliHelper-personal/master/conf/user.ini.example&#41;)
[//]: # (2. 修改)
1. 下载[配置文件夹](https://github.com/lkeme/BiliHelper-personal/tree/master/profile) `注意是文件夹,可以完整下载后提出来`
1.
下载[配置文件夹](https://github.com/lkeme/BiliHelper-personal/tree/master/profile) `注意是文件夹,可以完整下载后提出来`
2. 重命名 `profile/example -> profile/user` , 修改 `profile/user/config/user.ini`
3. 通过下面的命令进行挂载并运行

View File

@ -0,0 +1,217 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
use Bhp\Cache\Cache;
use Bhp\Log\Log;
use Bhp\Plugin\BasePlugin;
use Bhp\Plugin\Plugin;
use Bhp\TimeLock\TimeLock;
use Bhp\User\User;
include_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Traits' . DIRECTORY_SEPARATOR . 'CommonTaskInfo.php');
requireDir(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Traits' . DIRECTORY_SEPARATOR, ['CommonTaskInfo.php']);
class VipPoint extends BasePlugin
{
use SignIn;
use Bonus;
use Privilege;
use ViewAnimate;
use ViewFilmChannel;
use ViewVipMall;
use ViewVideo;
/**
* 插件信息
* @var array|string[]
*/
protected ?array $info = [
'hook' => __CLASS__, // hook
'name' => 'VipPoint', // 插件名称
'version' => '0.0.1', // 插件版本
'desc' => '大会员积分', // 插件描述
'author' => 'Lkeme',// 作者
'priority' => 1112, // 插件优先级
'cycle' => '5(分钟)', // 运行周期
];
/**
* @var string
*/
protected string $title = '大会员积分';
/**
* @var array|null
*/
protected ?array $tasks = [];
/**
* 目标任务
* @var array|string[]
*/
protected array $target_tasks = [
'signIn' => '签到任务',
// 'bonus' => '福利任务',
// 'privilege' => '体验任务',
'viewAnimate' => '浏览追番频道页10秒',
'viewFilmChannel' => '浏览影视频道页10秒',
// 'viewVipMall' => '浏览会员购页面10秒',
// 'viewVideo' => '观看任意正片内容',
// 'buyVipVideo' => '购买单点付费影片',
// 'buyVipProduct' => '购买指定会员产品',
// 'buyVipMall' => '购买指定会员购商品',
];
/**
* @param Plugin $plugin
*/
public function __construct(Plugin &$plugin)
{
// 时间锁
TimeLock::initTimeLock();
// 缓存
Cache::initCache();
// $this::class
$plugin->register($this, 'execute');
}
/**
* 执行
* @return void
*/
public function execute(): void
{
if (TimeLock::getTimes() > time() || !getEnable('vip_point')) return;
//
$this->initTask();
//
$this->receiveTask();
}
/**
* @return void
*/
protected function receiveTask(): void
{
// 如果为大会员
if (!User::isVip($this->title)) return;
// 获取远程任务列表
if (!$this->getTaskList()) {
TimeLock::setTimes(10 * 60);
return;
};
//
foreach ($this->target_tasks as $target => $value) {
// 任务完成跳过
if ($this->getTask($target)) continue;
// 未完成执行
$this->executeTask($target, $value);
//
TimeLock::setTimes(5 * 60);
// 每次执行一个任务
return;
}
// 全部完成
TimeLock::setTimes(TimeLock::timing(9));
return;
}
/**
* 动态执行任务
* @param string $target
* @param string $name
* @return void
*/
protected function executeTask(string $target, string $name): void
{
$response = $this->getTask('TaskList');
//
if (!method_exists($this, $target)) {
failExit("VipPoint 不存在{$target}方法 请暂时关闭任务检查代码或通知开发者");
}
//
$this->setTask('signIn', $this->$target($response, $name));
}
/**
* @return void
*/
protected function initTask(): void
{
$now = date("Y-m-d");
if (isset($this->tasks[$now])) return;
//
$this->setTask('start', true);
//
foreach ($this->target_tasks as $target => $_) {
$this->setTask($target, false);
}
}
/**
* @return bool
*/
protected function getTaskList(): bool
{
$response = \Bhp\Api\Api\X\VipPoint\ApiTask::combine();
if ($response['code']) {
Log::warning('大会员积分: 获取任务列表失败');
return false;
}
// 设置任务
$this->setTask('TaskList', $response);
return true;
}
/**
* @param string $key
* @param mixed $value
* @return void
*/
protected function setTask(string $key, mixed $value): void
{
$now = date("Y-m-d");
//
$this->tasks[$now][$key] = $value;
}
/**
* @param string $key
* @return mixed
*/
protected function getTask(string $key): mixed
{
$now = date("Y-m-d");
//
return $this->tasks[$now][$key];
}
/**
* @param string $key
* @return void
*/
protected function delTask(string $key): void
{
$now = date("Y-m-d");
//
unset($this->tasks[$now][$key]);
}
}

View File

@ -99,6 +99,10 @@ enable = true
[award_records]
enable = true
; 大会员积分
[vip_point]
enable = false
#######################
# 通知设置 #
#######################

View File

@ -0,0 +1,61 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
namespace Bhp\Api\Api\Pgc\Activity\Deliver;
use Bhp\Request\Request;
use Bhp\Sign\Sign;
use Bhp\User\User;
class ApiTask
{
/**
* @var array|string[]
*/
protected static array $headers = [
'Referer' => 'https://big.bilibili.com/mobile/bigPoint/task'
];
/**
* @var array|string[]
*/
protected static array $payload = [
'statistics' => '{"appId":1,"platform":3,"version":"6.86.0","abtest":""}',
];
/**
* 完成任务 jp追番页浏览 tv: 影视页浏览
* @param string $position
* @return array
*/
public static function complete(string $position): array
{
//
$user = User::parseCookie();
//
$url = 'https://api.bilibili.com/pgc/activity/deliver/task/complete';
$payload = array_merge([
'disable_rcmd' => '0',
'position' => $position,
'csrf' => $user['csrf'],
], self::$payload);
$headers = array_merge([], self::$headers);
return Request::postJson(true, 'app', $url, Sign::common($payload), $headers);
}
}

View File

@ -0,0 +1,100 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
namespace Bhp\Api\Api\Pgc\Activity\Score;
use Bhp\Request\Request;
use Bhp\Sign\Sign;
use Bhp\User\User;
class ApiTask
{
/**
* @var array|string[]
*/
protected static array $headers = [
'Referer' => 'https://big.bilibili.com/mobile/bigPoint/task'
];
/**
* @var array|string[]
*/
protected static array $payload = [
'statistics' => '{"appId":1,"platform":3,"version":"6.86.0","abtest":""}',
];
/**
* 大会员签到
* @return array
*/
public static function sign(): array
{
//
$user = User::parseCookie();
//
$url = 'https://api.bilibili.com/pgc/activity/score/task/sign';
$payload = array_merge([
'disable_rcmd' => '0',
'csrf' => $user['csrf'],
], self::$payload);
$headers = array_merge([], self::$headers);
return Request::postJson(true, 'app', $url, Sign::common($payload), $headers);
}
/**
* 领取任务
* @param string $task_code
* @return array
*/
public static function receive(string $task_code): array
{
//
$user = User::parseCookie();
//
$url = 'https://api.bilibili.com/pgc/activity/score/task/receive';
$payload = array_merge([
'taskCode' => $task_code,
'csrf' => $user['csrf'],
], self::$payload);
$headers = array_merge([], self::$headers);
return Request::postJson(true, 'app', $url, Sign::common($payload), $headers);
}
/**
* 完成任务
* @param string $task_code
* @return array
*/
public static function complete(string $task_code): array
{
//
$user = User::parseCookie();
//
$url = 'https://api.bilibili.com/pgc/activity/score/task/complete';
$payload = array_merge([
'taskCode' => $task_code,
'csrf' => $user['csrf'],
'ts' => time(),
], self::$payload);
$headers = array_merge([
'Content-Type' => 'application/json'
], self::$headers);
return Request::postJson(true, 'app', $url, Sign::common($payload), $headers);
}
}

View File

@ -0,0 +1,43 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
namespace Bhp\Api\Api\X\VipPoint;
use Bhp\Request\Request;
use Bhp\Sign\Sign;
class ApiTask
{
/**
* @var array|string[]
*/
protected static array $headers = [
'Referer' => 'https://big.bilibili.com/mobile/bigPoint/task'
];
/**
* 用户信息
* @return array
*/
public static function combine(): array
{
$url = 'https://api.bilibili.com/x/vip_point/task/combine';
$payload = [];
$headers = array_merge([], self::$headers);
return Request::getJson(true, 'app', $url, Sign::common($payload), $headers);
}
}

View File

@ -0,0 +1,63 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
namespace Bhp\Api\Show\Api\Activity\Fire\Common;
use Bhp\Request\Request;
use Bhp\Sign\Sign;
use Bhp\User\User;
class ApiEvent
{
/**
* @var array|string[]
*/
protected static array $headers = [
'Referer' => 'https://big.bilibili.com/mobile/bigPoint/task'
];
/**
* @var array|string[]
*/
protected static array $payload = [
'statistics' => '{"appId":1,"platform":3,"version":"6.86.0","abtest":""}',
];
/**
* @return array
*/
public static function dispatch(): array
{
//
$user = User::parseCookie();
//
$url = 'https://show.bilibili.com/api/activity/fire/common/event/dispatch';
$payload = array_merge([
'msource' => 'member_integral_browse',
'action' => 'browse_all',
'eventId' => 'hevent_oy4b7h3epeb',
'eventTime' => '10',
'csrf' => $user['csrf'],
], self::$payload);
$headers = array_merge([
'content-type'=> 'application/json; charset=utf-8',
], self::$headers);
return Request::postJson(true, 'app', $url, Sign::common($payload), $headers);
}
}

View File

@ -182,3 +182,25 @@ function getDevice(string $key, mixed $default = null, string $type = 'default')
//{
// Cache::getInstance()->_set($key, $data, $extra_name);
//}
/**
* @param string $dir
* @param array $exclude
* @return void
*/
function requireDir(string $dir, array $exclude = []): void
{
$handle = opendir($dir);//打开文件夹
while (false !== ($file = readdir($handle))) {//读取文件
if ($file != '.' && $file != '..') {
if (in_array($file, $exclude)) continue;
//
$filepath = $dir . '/' . $file;//文件路径
if (filetype($filepath) == 'dir') {//如果是文件夹
requireDir($filepath);//继续读
} else {
include_once($filepath);//引入文件
}
}
}
}

View File

@ -51,12 +51,15 @@ class User extends SingleTon
];
}
/**
* 是否为有效年度大会员
* 是否是有效大会员
* @param string $title
* @param array $scope
* @param string $info
* @return bool
*/
public static function isYearVip(string $title = '用户信息'): bool
public static function isVip(string $title = '用户信息', array $scope = [1, 2], string $info = '大会员'): bool
{
$response = ApiUser::userInfo();
//
@ -65,13 +68,25 @@ class User extends SingleTon
return false;
}
//
if ($response['data']['vip_type'] == 2 && $response['data']['vip_due_date'] > Common::getUnixTimestamp()) {
Log::info("$title: 获取大会员信息成功 是有效的年度大会员");
if (in_array($response['data']['vip_type'], $scope) && $response['data']['vip_due_date'] > Common::getUnixTimestamp()) {
Log::info("$title: 获取大会员信息成功 是有效的$info ");
return true;
}
//
Log::warning("$title: 获取大会员信息成功 不是年度大会员或已过期");
Log::warning("$title: 获取大会员信息成功 不是{$info}或已过期");
return false;
}
}
/**
* 是否为有效年度大会员 0:无会员 1:月会员 2:年会员
* @param string $title
* @param array $scope
* @param string $info
* @return bool
*/
public static function isYearVip(string $title = '用户信息', array $scope = [2], string $info = '年度大会员'): bool
{
return self::isVip($title, $scope, $info);
}
}