From df8f192ac36df12ef52803d3c94839485a4e97ff Mon Sep 17 00:00:00 2001 From: Lkeme <19500576+lkeme@users.noreply.github.com> Date: Sun, 6 Aug 2023 12:15:11 +0800 Subject: [PATCH] [update] Version v2.2.0.230806 --- README.md | 18 +- docs/CHANGELOG.md | 23 +- plugin/Lottery/Lottery.php | 722 ++++++++++++++++++++++---------- profile/example/config/user.ini | 2 - resources/filter_library.json | 4 - resources/version.json | 6 +- src/Api/Space/ApiArticle.php | 49 +++ src/Util/Common/Common.php | 23 + 8 files changed, 597 insertions(+), 250 deletions(-) create mode 100644 src/Api/Space/ApiArticle.php diff --git a/README.md b/README.md index b131e7a..c90b665 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -

+

[//]: # (

) @@ -29,10 +29,10 @@

- - - - + + + +

@@ -54,7 +54,7 @@ ## 👤 游客访问

- + [//]: # (
) @@ -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) | **请不要来问 效果图不代表当前版本,请以当前最新版本运行结果为准。 -

+

[comment]: <> (![Image](https://i.loli.net/2019/07/13/5d296961a4bae41364.png)) @@ -145,7 +145,7 @@ Group: [602815575](https://jq.qq.com/?_wv=1027&k=UaalVexM) | **请不要来问 感谢 `JetBrains` 提供优秀的IDE。 - + ## 🪪 License diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 98090ff..c8ae26a 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -8,12 +8,30 @@ [comment]: <> () +## 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 diff --git a/plugin/Lottery/Lottery.php b/plugin/Lottery/Lottery.php index 1ac8929..b1aaddc 100644 --- a/plugin/Lottery/Lottery.php +++ b/plugin/Lottery/Lottery.php @@ -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); +// } + } diff --git a/profile/example/config/user.ini b/profile/example/config/user.ini index 099715d..1871fab 100644 --- a/profile/example/config/user.ini +++ b/profile/example/config/user.ini @@ -115,8 +115,6 @@ enable = false ; 卍预约直播抽奖 [lottery] enable = false -; 抽奖模式 0.从最新Id开始抽奖 1.从最新Id的前2400个开始抽奖 -lottery_mode = 0 ; 每日电池 对应直播间ID和直播间UID [daily_gold] diff --git a/resources/filter_library.json b/resources/filter_library.json index f822ea1..de4d93a 100644 --- a/resources/filter_library.json +++ b/resources/filter_library.json @@ -2,7 +2,6 @@ "code": 200, "LiveGoldBox": { "sensitive": [ - "测试", "加密", "test", "TEST", @@ -159,8 +158,6 @@ "脸皮厚", "ceshi", "测试", - "测试", - "测试", "脚本", "抽奖号", "星段位", @@ -178,7 +175,6 @@ "TEST", "加密", "QQ", - "测试", "測試", "VX", "vx", diff --git a/resources/version.json b/resources/version.json index 31d138d..1e3bf82 100644 --- a/resources/version.json +++ b/resources/version.json @@ -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日" } diff --git a/src/Api/Space/ApiArticle.php b/src/Api/Space/ApiArticle.php new file mode 100644 index 0000000..ebdf3fb --- /dev/null +++ b/src/Api/Space/ApiArticle.php @@ -0,0 +1,49 @@ + $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); + } + +} diff --git a/src/Util/Common/Common.php b/src/Util/Common/Common.php index c5f3abb..1bbfa3a 100644 --- a/src/Util/Common/Common.php +++ b/src/Util/Common/Common.php @@ -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