[update] Version v2.2.0.230806

This commit is contained in:
Lkeme 2023-08-06 12:15:11 +08:00
parent 9159b5076e
commit df8f192ac3
8 changed files with 597 additions and 250 deletions

View File

@ -1,4 +1,4 @@
<p align="center"><img width="300px" src="https://user-images.githubusercontent.com/19500576/118621710-36428180-b7f9-11eb-891d-3f5697347cef.png"></p>
<p align="center"><img width="300px" src="https://user-images.githubusercontent.com/19500576/118621710-36428180-b7f9-11eb-891d-3f5697347cef.png" alt=""></p>
[//]: # (<p align="center"><img width="300px" src="https://i.loli.net/2018/04/20/5ad97bd395912.jpeg"></p>)
@ -29,10 +29,10 @@
<p align="center">
<img src="https://img.shields.io/badge/Version-2.1.0.230430-orange.svg?longCache=true&style=for-the-badge">
<img src="https://img.shields.io/badge/PHP-8.1+-green.svg?longCache=true&style=for-the-badge">
<img src="https://img.shields.io/badge/Composer-latest-blueviolet.svg?longCache=true&style=for-the-badge">
<img src="https://img.shields.io/badge/License-mit-blue.svg?longCache=true&style=for-the-badge">
<img src="https://img.shields.io/badge/Version-2.2.0.230806-orange.svg?longCache=true&style=for-the-badge" alt="">
<img src="https://img.shields.io/badge/PHP-8.1+-green.svg?longCache=true&style=for-the-badge" alt="">
<img src="https://img.shields.io/badge/Composer-latest-blueviolet.svg?longCache=true&style=for-the-badge" alt="">
<img src="https://img.shields.io/badge/License-mit-blue.svg?longCache=true&style=for-the-badge" alt="">
</p>
@ -54,7 +54,7 @@
## 👤 游客访问
<p align="center">
<img alingn="center" src="https://profile-counter.glitch.me/BiliHelper-personal/count.svg" />
<img alingn="center" src="https://profile-counter.glitch.me/BiliHelper-personal/count.svg" alt=""/>
[//]: # ( <br>)
@ -113,7 +113,7 @@ Group: [602815575](https://jq.qq.com/?_wv=1027&k=UaalVexM) | **请不要来问
| LiveGoldBox | 0.0.1 | 直播金色宝箱(实物抽奖) | Lkeme | 1110 | 6-10(分钟) | √ |
| AwardRecords | 0.0.1 | 获奖记录 | Lkeme | 1111 | 5(分钟) | √ |
| VipPoint | 0.0.1 | 大会员积分 | Lkeme | 1112 | 5(分钟) | √ |
| Lotty | 0.0.1 | 抽奖 | MoeHero | 1113 | 5(分钟) | √ |
| Lottery | 0.0.2 | 抽奖 | MoeHero/Lkeme | 1113 | 5(分钟) | √ |
| DailyGold | 0.0.1 | 每日电池(APP) | Lkeme | 1114 | 24(小时) | √ |
| PolishMedal | 0.0.1 | 点亮灰色勋章 | possible318/Lkeme | 1115 | 1(小时) | √ |
@ -130,7 +130,7 @@ Group: [602815575](https://jq.qq.com/?_wv=1027&k=UaalVexM) | **请不要来问
效果图不代表当前版本,请以当前最新版本运行结果为准。
<p align="center"><img width="680px" src="https://user-images.githubusercontent.com/19500576/118621918-6853e380-b7f9-11eb-8c73-e041c402a56b.png"></p>
<p align="center"><img width="680px" src="https://user-images.githubusercontent.com/19500576/118621918-6853e380-b7f9-11eb-8c73-e041c402a56b.png" alt=""></p>
[comment]: <> (![Image]&#40;https://i.loli.net/2019/07/13/5d296961a4bae41364.png&#41;)
@ -145,7 +145,7 @@ Group: [602815575](https://jq.qq.com/?_wv=1027&k=UaalVexM) | **请不要来问
感谢 `JetBrains` 提供优秀的IDE。
<a href="https://www.jetbrains.com/?from=BiliHelper-personal" target="_blank">
<img src="https://tva1.sinaimg.cn/large/008eGmZEly1gov9g3tzrnj30u00wj0tn.jpg" width="150"/>
<img src="https://tva1.sinaimg.cn/large/008eGmZEly1gov9g3tzrnj30u00wj0tn.jpg" width="150" alt=""/>
</a>
## 🪪 License

View File

@ -8,12 +8,30 @@
[comment]: <> (</details>)
## v2.2.0.230806 alpha (2023-08-06)
### Added
-
### Changed
-
### Fixed
- 修复Lottery抽奖插件
-
### Remarks
- 请注意配置文件有所变动,注意更新。
## v2.1.0.230430 alpha (2023-04-30)
### Added
-
-
### Changed
@ -47,7 +65,6 @@
- 请注意配置文件有所变动,注意更新。
## v2.0.7.230311 alpha (2023-03-11)
### Added
@ -61,7 +78,7 @@
### Fixed
- 修复主站任务(投币)
-
-
### Remarks

View File

@ -15,29 +15,21 @@
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
use Bhp\Api\Space\ApiArticle;
use Bhp\Cache\Cache;
use Bhp\FilterWords\FilterWords;
use Bhp\Log\Log;
use Bhp\Plugin\BasePlugin;
use Bhp\Plugin\Plugin;
use Bhp\TimeLock\TimeLock;
use Bhp\Request\Request;
use Bhp\User\User;
use Bhp\Util\Common\Common;
use function Amp\delay;
class Lottery extends BasePlugin
{
/**
* 预计每日抽奖数量
* 用于计算当前日期的MaxId
*/
private const LOTTERY_PER_DAY = 75;
/**
* 抽奖活动开始日期
* 用于计算当前日期的MaxId
*/
private const START_LOTTERY_START_TIME = '2018-05-01';
/**
* 插件信息
* @var array|string[]
@ -45,24 +37,30 @@ class Lottery extends BasePlugin
protected ?array $info = [
'hook' => __CLASS__, // hook
'name' => 'Lottery', // 插件名称
'version' => '0.0.1', // 插件版本
'version' => '0.0.2', // 插件版本
'desc' => '抽奖', // 插件描述
'author' => 'MoeHero',// 作者
'author' => 'MoeHero/Lkeme',// 作者
'priority' => 1113, // 插件优先级
'cycle' => '2-6(小时)', // 运行周期
];
/**
* 上次任务是否完成
* @var bool
* @var array|array[]
*/
protected bool $last_task_finish = false;
protected array $config = [
'cv_list' => [], // 专栏列表
'wait_cv_list' => [], // 待处理专栏列表
'dynamic_list' => [], // 动态列表
'wait_dynamic_list' => [], // 待处理动态列表
'lottery_list' => [], // 抽奖列表
'wait_lottery_list' => [], // 待处理抽奖列表
];
/**
* @param Plugin $plugin
*/
public function __construct(Plugin &$plugin)
{
// include_once 'LotteryInfo.php';
TimeLock::initTimeLock();
Cache::initCache();
$plugin->register($this, 'execute');
@ -75,179 +73,109 @@ class Lottery extends BasePlugin
public function execute(): void
{
if (!getEnable('lottery')) return;
if (TimeLock::getTimes() > time() && $this->last_task_finish) return;
$this->lotteryTask();
//
if (TimeLock::getTimes() > time()) return;
//
$this->initConfig();
//
$global_uid = base64_decode('MTkwNTcwMjM3NQ==');
//
$this->handleArticle($global_uid);
//
$this->handleDynamic($global_uid);
//
$this->handleLottery($global_uid);
//
$this->saveConfig();
// 2-6小时 未完成6-10秒
TimeLock::setTimes($this->last_task_finish ? (mt_rand(2, 6) * 60 * 60) : mt_rand(6, 10));
TimeLock::setTimes(mt_rand(6, 16) * 60);
}
/**
* 执行抽奖任务
* @return void
*/
protected function lotteryTask(): void
protected function initConfig(): void
{
// $last_lottery_id = ($tmp = Cache::get('last_lottery_id')) ? $tmp : $this->calcLastLotteryId();
$last_lottery_id = 3015989;
$times = 0;
// 参加抽奖
while (true) {
// if (LotteryInfo::isExist($last_lottery_id)) continue;
if ($times > 9) {
$this->last_task_finish = false;
break;
}
$info = $this->getLotteryInfo($last_lottery_id);
if ($info['status'] === -9999) { // 当前抽奖不存在
$this->last_task_finish = true;
break;
} else if ($info['status'] === 2) { // 当前抽奖已开奖
$last_lottery_id++;
continue;
}
$this->joinLottery($info);
$last_lottery_id++;
Cache::set('last_lottery_id', $last_lottery_id);
$times++;
$config = Cache::get('config');
if ($config) {
$this->config = $config;
}
$times = 0;
// 删除动态
// $infos = LotteryInfo::getHasLotteryList();
// foreach ($infos as $info) {
// if ($times > 9) {
// $this->last_task_finish = false;
// break;
// }
// //TODO 删除动态
// LotteryInfo::delete($info['lottery_id']);
// $times++;
// else {
// $this->config['cv_list'] = [];
// $this->config['wait_cv_list'] = [];
// $this->config['dynamic_list'] = [];
// $this->config['wait_dynamic_list'] = [];
// $this->config['lottery_list'] = [];
// $this->config['wait_lottery_list'] = [];
// }
}
/**
* 计算最新抽奖Id
* @return int
* @return void
*/
protected function calcLastLotteryId(): int
protected function saveConfig(): void
{
$start_time = new DateTime(self::START_LOTTERY_START_TIME);
$end_time = new DateTime();
$elapsed_days = $start_time->diff($end_time)->days;
$max_id = $elapsed_days * self::LOTTERY_PER_DAY;
$min_id = max($max_id - 10000, 0);
// 如果计算出的MaxId不是未使用的Id则每次加5000
while (true) {
$info = $this->getLotteryInfo($max_id);
if ($info['status'] === -9999) break;
$min_id = $max_id;
$max_id += 5000;
}
// 如果计算出的MinId是未使用的Id则每次减5000
while (true) {
$info = $this->getLotteryInfo($min_id);
if ($info['status'] !== -9999) break;
$max_id = $min_id;
$min_id -= 5000;
}
$times = 0;
while (true) {
$times++;
$middle = intval(($min_id + $max_id) / 2);
$info = $this->getLotteryInfo($middle);
if ($info['status'] !== -9999) {
$min_id = $middle;
} else {
$max_id = $middle;
}
if ($max_id - $min_id == 1) break;
}
Log::info("抽奖计算出最新抽奖Id Id: $max_id 请求次数: $times");
// 抽奖模式 0.从最新Id开始抽奖 1.从最新Id的前2400个开始抽奖
if (getConf('lottery.lottery_mode', 0) == 1) return $max_id - 2400;
return $max_id;
Cache::set('config', $this->config);
}
/**
* 获取抽奖信息
* @param int $business_id
* @return array
* 处理专栏
* @param string $uid
* @return void
*/
protected function getLotteryInfo(int $business_id): array
protected function handleArticle(string $uid): void
{
$this->fetchValidArticleUrls($uid);
//
$this->fetchValidDynamicUrl($uid);
//
delay(3);
$user = User::parseCookie();
$url = 'https://api.vc.bilibili.com/lottery_svr/v1/lottery_svr/lottery_notice';
$headers = [
'origin' => 'https://www.bilibili.com',
'referer' => 'https://www.bilibili.com/'
];
$payload = [
'business_id' => $business_id,
'business_type' => 10, // 1.转发动态 10.直播预约
'csrf' => $user['csrf'],
];
echo $business_id.PHP_EOL;
$response = Request::getJson(true, 'pc', $url, $payload, $headers);
print_r($response);
// 抽奖不存在/请求错误/请求被拦截
if ($response['code'] === -9999 || $response['code'] === 4000014 || $response['code'] === -412) {
return [
'status' => -9999,
];
}
$data = $response['data'];
// 已开奖
if ($data['lottery_time'] <= time()) {
return [
'status' => 2,
];
}
return [
'business_id' => $business_id, // business_type=1时是动态Id business_type=10时是预约直播Id
'lottery_id' => $data['lottery_id'], // 抽奖ID
'lottery_time' => $data['lottery_time'], // 开奖时间
'lottery_detail_url' => $data['lottery_detail_url'], // 抽奖详情页
'need_feed' => $data['lottery_feed_limit'] === 1, // 是否需要关注
'need_post' => $data['need_post'] === 1, //是否需要发货地址
'sender_uid' => $data['sender_uid'], // 发起人UID
'status' => $data['status'], // 0 未开奖 2 已开奖 -1 已失效 -9999 不存在
'type' => $data['business_type'], // 1.转发动态 10.直播预约
'ts' => $data['ts'], // 时间戳
'prizes' => $this->parsePrizes($data), // 奖品
];
}
/**
* 解析奖品
* @param array $data
* @return string
* 处理动态
* @param string $uid
* @return void
*/
protected function parsePrizes(array $data): string
protected function handleDynamic(string $uid): void
{
$prizes = '';
$prizeData = [
'first_prize' => ['一等奖', 'first_prize_cmt'],
'second_prize' => ['二等奖', 'second_prize_cmt'],
'third_prize' => ['三等奖', 'third_prize_cmt']
];
$this->fetchDynamicReserve();
//
foreach ($prizeData as $key => $value) {
if (isset($data[$key]) && isset($data[$value[1]])) {
$prizes .= "{$value[0]}: {$data[$value[1]]} * {$data[$key]}\n";
}
delay(3);
}
/**
* @param string $uid
* @return void
*/
protected function handleLottery(string $uid): void
{
$this->joinLottery();
}
/**
* @return void
*/
protected function joinLottery(): void
{
$lottery = array_shift($this->config['wait_lottery_list']);
if (is_null($lottery)) return;
//
Log::info("抽奖: 尝试预约 ID: {$lottery['rid']} UP: {$lottery['up_mid']} 预约人数: {$lottery['reserve_total']}");
Log::info("抽奖: 标题: {$lottery['title']}");
Log::info("抽奖: 地址: " . $this->setT(intval($lottery['id_str'])));
Log::info("抽奖: 奖品: {$lottery['prize']}");
//
if ($this->filterContentWords($lottery['title']) || $this->filterContentWords($lottery['prize'])) {
Log::warning("抽奖: 预约失败,标题或描述含有敏感词, 跳过");
return;
}
//
return $prizes;
$this->reserve($lottery);
}
/**
* 参加抽奖
* @param array $info
@ -259,117 +187,453 @@ class Lottery extends BasePlugin
$user = User::parseCookie();
//
$url = 'https://api.vc.bilibili.com/dynamic_mix/v1/dynamic_mix/reserve_attach_card_button';
// $headers = [
// 'origin' => 'https://space.bilibili.com',
// 'referer' => "https://space.bilibili.com/{$info['sender_uid']}/dynamic"
// ];
$headers = [
'origin' => 'https://space.bilibili.com',
'referer' => "https://space.bilibili.com/{$info['sender_uid']}/dynamic"
'origin' => 'https://t.bilibili.com',
'referer' => $this->setT(intval($info['id_str']))
];
$payload = [
'cur_btn_status' => 1,
'dynamic_id' => $info['id_str'],
'attach_card_type' => 'reserve',
'reserve_id' => $info['business_id'],
'reserve_id' => $info['rid'],
'reserve_total' => $info['reserve_total'],
'spmid' => '',
'csrf' => $user['csrf'],
];
//
$response = Request::postJson(true, 'pc', $url, $payload, $headers);
//
if ($response['code'] === 0 || $response['code'] === 7604003) { //预约成功/已经预约
Log::info("抽奖: 预约直播成功 ID: {$info['business_id']} UP: {$info['sender_uid']} 预约人数: {$info['reserve_total']}");
Log::info("抽奖: 地址: {$info['lottery_detail_url']}");
Log::info("抽奖: 奖品: {$info['prizes']}");
// $response['code'] === 7604003
if ($response['code'] === 0) { //预约成功/已经预约
Log::notice("抽奖: 预约成功 ReserveId: {$info['rid']} Toast: {$response['data']['toast']} 已有{$response['data']['desc_update']} ");
} else {
Log::warning("抽奖: 预约直播失败 ReserveId: $info[business_id] Error: {$response['code']} -> {$response['message']}");
Log::warning("抽奖: 预约失败 ReserveId: {$info['rid']} Error: {$response['code']} -> {$response['message']}");
}
}
/**
* 提取动态参数
* 获取有效动态列表
* @param string $uid
* @return void
*/
protected function fetchValidDynamicUrl(string $uid): void
{
$cv = array_shift($this->config['wait_cv_list']);
if (is_null($cv)) return;
//
$url = $this->setCv($cv);
Log::info("抽奖: 开始提取专栏 $url");
$payload = [];
$headers = [
'referer' => "https://space.bilibili.com/$uid/",
];
$response = Request::get('pc', $url, $payload, $headers);
//
$this->_fetchValidDynamicUrl($response);
//
Log::info("抽奖: 获取有效动态列表成功 当前未处理Count: " . count($this->config['wait_dynamic_list']));
}
/**
* 获取有效动态列表
* @param string $data
* @return array
*/
protected function extractDynamicParameters(string $data): array
protected function _fetchValidDynamicUrl(string $data): array
{
$result = [];
preg_match('/"reserve_total":(\d+)/', $data, $b); // 正则匹配
if (isset($b[1])) {
$result['reserve_total'] = $b[1];
}
preg_match('/"reserve_total": (\d+)/', $data, $b); // 正则匹配
if (isset($b[1])) {
$result['reserve_total'] = $b[1];
}
preg_match('/"id_str":(\d+)/', $data, $b); // 正则匹配
if (isset($b[1])) {
$result['id_str'] = $b[1];
}
preg_match('/"id_str": (\d+)/', $data, $b); // 正则匹配
if (isset($b[1])) {
$result['id_str'] = $b[1];
}
return $result;
}
/**
* 过滤指定动态
* @param array $dynamic_list
* @param int $rid
* @return array
*/
protected function filterDynamic(array $dynamic_list, int $rid): array
{
foreach ($dynamic_list as $dynamic) {
$dynamic_str = json_encode($dynamic);
if (str_contains($dynamic_str, '"rid":' . $rid) || str_contains($dynamic_str, '"rid": ' . $rid)) {
return $this->extractDynamicParameters($dynamic_str);
$urls = [];
// 使用正则表达式从页面内容中提取URL
$pattern = '/https:\/\/t\.bilibili\.com\/[0-9]+/';
preg_match_all($pattern, $data, $matches);
//
foreach ($matches[0] as $url) {
//
if (in_array($this->getT($url), $this->config['dynamic_list'])) {
continue;
}
//
$this->addDynamicList($this->getT($url));
//
$urls[] = $url;
}
return [];
return $urls;
}
/**
* 获取有效专栏列表
* @param string $uid
* @return void
*/
protected function fetchValidArticleUrls(string $uid): void
{
//
$response = ApiArticle::article($uid);
//
if ($response['code'] == 0) {
$this->_fetchValidArticleUrls($response['data']);
Log::info("抽奖: 获取有效专栏列表成功 当前未处理Count: " . count($this->config['wait_cv_list']));
} else {
Log::warning("抽奖: 获取有效专栏列表失败 Error: {$response['code']} -> {$response['message']}");
}
//
}
/**
* 获取指定空间动态列表
* @param int $host_mid
* @return array
* 获取有效专栏列表
* @param array $data
* @return void
*/
protected function fetchSpaceDynamic(int $host_mid): array
protected function _fetchValidArticleUrls(array $data): void
{
$url = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space';
foreach ($data['articles'] as $item) {
if (!Common::isTimestampInToday($item['publish_time'])) {
continue;
}
if (!str_contains($item['title'], '抽奖') && !str_contains($item['title'], '预约')) {
continue;
}
//
if (in_array($item['id'], $this->config['cv_list'])) {
continue;
}
$this->addCvList($item['id']);
//
}
}
/**
* 获取动态预约
* @return void
*/
protected function fetchDynamicReserve(): void
{
// $t = array_shift($this->config['wait_dynamic_list']);
$t = array_pop($this->config['wait_dynamic_list']);
if (is_null($t)) return;
$t_url = $this->setT($t);
Log::info("抽奖: 开始提取动态 $t_url");
//
$url = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/detail';
$headers = [
'origin' => 'https://space.bilibili.com',
'referer' => "https://space.bilibili.com/{$host_mid}/dynamic"
'origin' => 'https://t.bilibili.com',
'referer' => $t_url,
];
$payload = [
'offset' => '',
'host_mid' => $host_mid,
'timezone_offset' => '-480',
'id' => $t,
'features' => 'itemOpusStyle'
];
//
$response = Request::getJson(true, 'pc', $url, $payload, $headers);
//
if ($response['code']) {
Log::warning("获取({$host_mid})空间动态失败: {$response['code']} -> {$response['message']}");
return [];
}
//
return $response['data']['items'] ?? [];
}
protected function joinLottery(array $info): void
{
$dynamic_list = $this->fetchSpaceDynamic($info['sender_uid']);
$dynamic = $this->filterDynamic($dynamic_list, $info['business_id']);
if (!isset($dynamic['id_str']) || !isset($dynamic['reserve_total'])) {
Log::warning("抽奖: 未找到指定动态 ReserveId: $info[business_id]");
Log::warning("抽奖: 提取动态($t)失败: {$response['code']} -> {$response['message']}");
return;
}
// 合并数组
$info = array_merge($info, $dynamic);
$this->reserve($info);
//
$this->_fetchDynamicReserve($response['data']);
Log::info("抽奖: 获取有效预约列表成功 当前未处理Count: " . count($this->config['wait_lottery_list']));
}
/**
* 获取动态预约
* @param array $data
* @return void
*/
protected function _fetchDynamicReserve(array $data): void
{
if (!isset($data['item']['modules']['module_dynamic']['additional']['reserve'])) {
Log::warning("抽奖: 提取动态预约失败: 未找到预约信息");
return;
}
//
if (!$data['item']['visible']) {
Log::warning("抽奖: 提取动态预约失败: 动态已不可见");
return;
}
//
$reserve = $data['item']['modules']['module_dynamic']['additional']['reserve'];
//
if ($reserve['button']['uncheck']['text'] != '预约' || $reserve['button']['status'] != 1 || $reserve['button']['type'] != 2) {
Log::warning("抽奖: 提取动态预约失败: 预约按钮状态异常");
return;
}
//
if ($reserve['state'] != 0 || $reserve['stype'] != 2) {
Log::warning("抽奖: 提取动态预约失败: 预约动态状态异常");
return;
}
//
$lottery = [
'reserve_total' => $reserve['reserve_total'],
'rid' => $reserve['rid'],
'title' => $reserve['title'],
'up_mid' => $reserve['up_mid'],
'prize' => $reserve['desc3']['text'],
'id_str' => $data['item']['id_str'],
];
$this->addLotteryList($lottery);
}
/**
* @param array $lottery
* @return void
*/
protected function addLotteryList(array $lottery): void
{
if (!array_key_exists("rid{$lottery['rid']}", $this->config['lottery_list'])) {
$this->config['lottery_list']["rid{$lottery['rid']}"] = $lottery;
$this->config['wait_lottery_list']["rid{$lottery['rid']}"] = $lottery;
}
}
/**
* @param int $cv
* @return void
*/
protected function addCvList(int $cv): void
{
if (!in_array($cv, $this->config['cv_list'])) {
$this->config['cv_list'][] = $cv;
$this->config['wait_cv_list'][] = $cv;
}
}
/**
* @param int $dynamic
* @return void
*/
protected function addDynamicList(int $dynamic): void
{
if (!in_array($dynamic, $this->config['dynamic_list'])) {
$this->config['dynamic_list'][] = $dynamic;
$this->config['wait_dynamic_list'][] = $dynamic;
}
}
/**
* 获取cv号
* @param string $url
* @return int
*/
protected function getCv(string $url): int
{
return intval(str_replace('https://www.bilibili.com/read/cv', '', $url));
}
/**
* 设置cv号
* @param int $cv
* @return string
*/
protected function setCv(int $cv): string
{
return 'https://www.bilibili.com/read/cv' . $cv;
}
/**
* 获取动态
* @param string $url
* @return int
*/
protected function getT(string $url): int
{
return intval(str_replace('https://t.bilibili.com/', '', $url));
}
/**
* 设置动态
* @param int $t
* @return string
*/
protected function setT(int $t): string
{
return 'https://t.bilibili.com/' . $t;
}
/**
* 过滤抽奖信息
* @param string $content
* @return bool
*/
protected function filterContentWords(string $content): bool
{
$sensitive_words = FilterWords::getInstance()->get('LiveGoldBox.sensitive');
//
foreach ($sensitive_words as $word) {
if (str_contains($content, $word)) {
return true;
}
}
return false;
}
// /**
// * 获取抽奖信息
// * @param int $business_id
// * @return array
// */
// protected function getLotteryInfo(int $business_id): array
// {
// delay(3);
// $user = User::parseCookie();
// $url = 'https://api.vc.bilibili.com/lottery_svr/v1/lottery_svr/lottery_notice';
// $headers = [
// 'origin' => 'https://www.bilibili.com',
// 'referer' => 'https://www.bilibili.com/'
// ];
// $payload = [
// 'business_id' => $business_id,
// 'business_type' => 10, // 1.转发动态 10.直播预约
// 'csrf' => $user['csrf'],
// ];
// echo $business_id . PHP_EOL;
// $response = Request::getJson(true, 'pc', $url, $payload, $headers);
// print_r($response);
//
// // 抽奖不存在/请求错误/请求被拦截
// if ($response['code'] === -9999 || $response['code'] === 4000014 || $response['code'] === -412) {
// return [
// 'status' => -9999,
// ];
// }
// $data = $response['data'];
// // 已开奖
// if ($data['lottery_time'] <= time()) {
// return [
// 'status' => 2,
// ];
// }
//
// return [
// 'business_id' => $business_id, // business_type=1时是动态Id business_type=10时是预约直播Id
// 'lottery_id' => $data['lottery_id'], // 抽奖ID
// 'lottery_time' => $data['lottery_time'], // 开奖时间
// 'lottery_detail_url' => $data['lottery_detail_url'], // 抽奖详情页
// 'need_feed' => $data['lottery_feed_limit'] === 1, // 是否需要关注
// 'need_post' => $data['need_post'] === 1, //是否需要发货地址
// 'sender_uid' => $data['sender_uid'], // 发起人UID
// 'status' => $data['status'], // 0 未开奖 2 已开奖 -1 已失效 -9999 不存在
// 'type' => $data['business_type'], // 1.转发动态 10.直播预约
// 'ts' => $data['ts'], // 时间戳
// 'prizes' => $this->parsePrizes($data), // 奖品
// ];
// }
//
//
// /**
// * 解析奖品
// * @param array $data
// * @return string
// */
// protected function parsePrizes(array $data): string
// {
// $prizes = '';
// $prizeData = [
// 'first_prize' => ['一等奖', 'first_prize_cmt'],
// 'second_prize' => ['二等奖', 'second_prize_cmt'],
// 'third_prize' => ['三等奖', 'third_prize_cmt']
// ];
// //
// foreach ($prizeData as $key => $value) {
// if (isset($data[$key]) && isset($data[$value[1]])) {
// $prizes .= "{$value[0]}: {$data[$value[1]]} * {$data[$key]}\n";
// }
// }
// //
// return $prizes;
// }
//
// /**
// * 提取动态参数
// * @param string $data
// * @return array
// */
// protected function extractDynamicParameters(string $data): array
// {
// $result = [];
// preg_match('/"reserve_total":(\d+)/', $data, $b); // 正则匹配
// if (isset($b[1])) {
// $result['reserve_total'] = $b[1];
// }
// preg_match('/"reserve_total": (\d+)/', $data, $b); // 正则匹配
// if (isset($b[1])) {
// $result['reserve_total'] = $b[1];
// }
// preg_match('/"id_str":(\d+)/', $data, $b); // 正则匹配
// if (isset($b[1])) {
// $result['id_str'] = $b[1];
// }
// preg_match('/"id_str": (\d+)/', $data, $b); // 正则匹配
// if (isset($b[1])) {
// $result['id_str'] = $b[1];
// }
// return $result;
// }
//
// /**
// * 过滤指定动态
// * @param array $dynamic_list
// * @param int $rid
// * @return array
// */
// protected function filterDynamic(array $dynamic_list, int $rid): array
// {
// foreach ($dynamic_list as $dynamic) {
// $dynamic_str = json_encode($dynamic);
// if (str_contains($dynamic_str, '"rid":' . $rid) || str_contains($dynamic_str, '"rid": ' . $rid)) {
// return $this->extractDynamicParameters($dynamic_str);
// }
// }
// return [];
// }
//
// /**
// * 获取指定空间动态列表
// * @param int $host_mid
// * @return array
// */
// protected function fetchSpaceDynamic(int $host_mid): array
// {
// $url = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space';
// $headers = [
// 'origin' => 'https://space.bilibili.com',
// 'referer' => "https://space.bilibili.com/{$host_mid}/dynamic"
// ];
// $payload = [
// 'host_mid' => $host_mid,
// 'timezone_offset' => '-480',
// 'features' => 'itemOpusStyle'
// ];
// //
// $response = Request::getJson(true, 'pc', $url, $payload, $headers);
// //
// if ($response['code']) {
// Log::warning("获取({$host_mid})空间动态失败: {$response['code']} -> {$response['message']}");
// return [];
// }
// //
// return $response['data']['items'] ?? [];
// }
//
// protected function joinLottery(array $info): void
// {
// $dynamic_list = $this->fetchSpaceDynamic($info['sender_uid']);
// $dynamic = $this->filterDynamic($dynamic_list, $info['business_id']);
// if (!isset($dynamic['id_str']) || !isset($dynamic['reserve_total'])) {
// Log::warning("抽奖: 未找到指定动态 ReserveId: $info[business_id]");
// return;
// }
// // 合并数组
// $info = array_merge($info, $dynamic);
// $this->reserve($info);
// }
}

View File

@ -115,8 +115,6 @@ enable = false
; 卍预约直播抽奖
[lottery]
enable = false
; 抽奖模式 0.从最新Id开始抽奖 1.从最新Id的前2400个开始抽奖
lottery_mode = 0
; 每日电池 对应直播间ID和直播间UID
[daily_gold]

View File

@ -2,7 +2,6 @@
"code": 200,
"LiveGoldBox": {
"sensitive": [
"测试",
"加密",
"test",
"TEST",
@ -159,8 +158,6 @@
"脸皮厚",
"ceshi",
"测试",
"测试",
"测试",
"脚本",
"抽奖号",
"星段位",
@ -178,7 +175,6 @@
"TEST",
"加密",
"QQ",
"测试",
"測試",
"VX",
"vx",

View File

@ -7,10 +7,10 @@
"dev_raw_url": "https://gh.notifyplus.cf/https://github.com/lkeme/BiliHelper-personal/blob/dev/resources/version.json",
"master_purge_url": "https://cdn.staticaly.com/gh/lkeme/BiliHelper-personal/master/resources/version.json",
"dev_purge_url": "https://cdn.staticaly.com/gh/lkeme/BiliHelper-personal/dev/resources/version.json",
"version": "2.1.0.230430",
"version": "2.2.0.230806",
"des": "程序有更新,请及时线上查看更新哦~",
"time": "2023年04月30日",
"time": "2023年08月06日",
"ini_version": "0.0.1",
"ini_des": "配置有更新,请及时线上查看更新哦~",
"ini_time": "2023年04月30日"
"ini_time": "2023年08月06日"
}

View File

@ -0,0 +1,49 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2023 ~ 2024
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
namespace Bhp\Api\Space;
use Bhp\Request\Request;
class ApiArticle
{
/**
* 获取用户专栏列表
* @param string $uid
* @param int $pn 页码
* @param int $ps 每页数量 1-30
* @param string $sort publish_time最新发布 / view最多阅读 / fav最多收藏
* @return array
*/
public static function article(string $uid, int $pn = 1, int $ps = 2, string $sort = 'publish_time'): array
{
$url = 'https://api.bilibili.com/x/space/article';
$payload = [
'mid' => $uid,
'pn' => $pn,
'ps' => $ps,
'sort' => $sort,
];
$headers = [
'origin' => 'https://space.bilibili.com',
'referer' => "https://space.bilibili.com/$uid/"
];
//
return Request::getJson(true, 'other', $url, $payload, $headers);
}
}

View File

@ -20,6 +20,29 @@ namespace Bhp\Util\Common;
class Common
{
/**
* 判断指定时间戳是否在今天内
* @param int $timestamp
* @return bool
*/
public static function isTimestampInToday(int $timestamp): bool
{
// 将时间戳转换为日期
$date = date('Y-m-d', $timestamp);
// 获取今天的日期
$today = date('Y-m-d');
// 判断日期是否相等
if ($date == $today) {
// 该时间戳在今天内
return true;
} else {
// 该时间戳不在今天内
return false;
}
}
/**
* 获取十三位时间戳
* @return int