diff --git a/plugin/GameForecast/GameForecast.php b/plugin/GameForecast/GameForecast.php new file mode 100644 index 0000000..9dfc28a --- /dev/null +++ b/plugin/GameForecast/GameForecast.php @@ -0,0 +1,176 @@ + __CLASS__, // hook + 'name' => 'GameForecast', // 插件名称 + 'version' => '0.0.1', // 插件版本 + 'desc' => '赛事预测(破产机)', // 插件描述 + 'author' => 'Lkeme',// 作者 + 'priority' => 1104, // 插件优先级 + 'cycle' => '24(小时)', // 运行周期 + ]; + + /** + * @param Plugin $plugin + */ + public function __construct(Plugin &$plugin) + { + // + TimeLock::initTimeLock(); + // $this::class + $plugin->register($this, 'execute'); + } + + /** + * @use 执行 + * @return void + */ + public function execute(): void + { + if (TimeLock::getTimes() > time() || !getEnable('game_forecast')) return; + // + $this->startStake(); + // + TimeLock::setTimes(TimeLock::timing(1, 30)); + } + + /** + * @use 获取预测赛事列表 + * @param int $pm + * @return array + */ + protected function fetchCollectionQuestions(int $pm = 10): array + { + $questions = []; + for ($i = 1; $i < $pm; $i++) { + $response = ApiGuess::collectionQuestion($i); + // + if ($response['code']) { + Log::warning("赛事预测: 获取赛事列表失败 {$response['code']} -> {$response['message']}"); + break; + } + // + if (count($response['data']['list']) == 0) { + break; + } + // 添加到集合 + foreach ($response['data']['list'] as $question) { + // 判断是否有效 正2分钟 + if (($question['contest']['stime'] - 600 - 120) > time()) { + $questions[] = $question; + } + } + // 和页面的不匹配 跳出 + if (count($response['data']['list']) != $response['data']['page']['size']) { + break; + } + } + Log::info('赛事预测: 获取到 ' . count($questions) . ' 个有效赛事'); + return $questions; + } + + /** + * @use 预计猜测结果 + * @param array $question + * @return array + */ + protected function parseQuestion(array $question): array + { + $guess = []; + $guess['oid'] = $question['contest']['id']; + $guess['main_id'] = $question['questions'][0]['id']; + $details = $question['questions'][0]['details']; + $guess['count'] = (($count = getConf('game_forecast.max_coin', 0, 'int')) <= 10) ? $count : 10; + $guess['title'] = $question['questions'][0]['title']; + foreach ($details as $detail) { + $guess['title'] .= " 队伍: {$detail['option']} 赔率: {$detail['odds']}"; + } + array_multisort(array_column($details, "odds"), SORT_ASC, $details); + switch (getConf('game_forecast.bet', 3, 'int')) { + case 1: + // 压大 + $detail = array_pop($details); + break; + case 2: + // 压小 + $detail = array_shift($details); + break; + case 3: + // 随机 + $detail = $details[array_rand($details)]; + break; + default: + // 乱序 + shuffle($details); + $detail = $details[array_rand($details)]; + break; + } + $guess['detail_id'] = $detail['detail_id']; + $profit = ceil($guess['count'] * $detail['odds']); + $guess['estimate'] = "竞猜队伍: {$detail['option']} 预计下注: {$guess['count']} 预计赚取: $profit 预计亏损: {$guess['count']} (硬币)"; + return $guess; + } + + /** + * @use 开始破产 + */ + protected function startStake(): void + { + $questions = $this->fetchCollectionQuestions(); + // + $max_guess = getConf('game_forecast.max_num', 0, 'int'); + foreach ($questions as $index => $question) { + if ($index >= $max_guess) { + break; + } + $guess = $this->parseQuestion($question); + $this->addGuess($guess); + } + } + + /** + * @use 添加竞猜 + * @param array $guess + */ + protected function addGuess(array $guess): void + { + Log::info($guess['title']); + Log::info($guess['estimate']); + // + $response = ApiGuess::guessAdd($guess['oid'], $guess['main_id'], $guess['detail_id'], $guess['count']); + // {"code":0,"message":"0","ttl":1} + if ($response['message'] == 0) { + Log::notice('赛事预测: 破产成功'); + } else { + Log::warning("赛事预测: 破产失败 {$response['code']} -> {$response['message']}"); + } + } +} + \ No newline at end of file diff --git a/plugin/LiveSignIn/LiveSignIn.php b/plugin/LiveSignIn/LiveSignIn.php index d147c63..564c426 100644 --- a/plugin/LiveSignIn/LiveSignIn.php +++ b/plugin/LiveSignIn/LiveSignIn.php @@ -80,7 +80,10 @@ class LiveSignIn extends BasePlugin Log::notice("直播签到: 今日已经签到过了哦~ 已连续签到 {$response['data']['hadSignDays']} 天"); return true; } - // + // 您被封禁了,无法进行操作 + // {"code":1011040,"message":"今日已签到过,无法重复签到","ttl":1,"data":null} + // {"code":0,"message":"0","ttl":1,"data":{"text":"3000点用户经验,2根辣条","specialText":"再签到3天可以获得666银瓜子","allDays":31,"hadSignDays":2,"isBonusDay":0}} + // {"code":0,"message":"0","ttl":1,"data":{"text":"3000点用户经验,2根辣条,50根辣条","specialText":"","allDays":31,"hadSignDays":20,"isBonusDay":1}} $response = ApiXLiveSign::doSign(); if ($response['code']) { Log::warning("直播签到: 签到失败 {$response['code']} -> {$response['message']}"); diff --git a/profile/example/config/user.ini b/profile/example/config/user.ini index 6b5c993..9fc4a0a 100644 --- a/profile/example/config/user.ini +++ b/profile/example/config/user.ini @@ -49,6 +49,13 @@ enable = true [live_sign_in] enable =true +; 游戏赛事竞猜预测(破产机)/每日竞猜次数/每次竞猜硬币(1-10)/下注(1.压大,2.压小,3.随机) +[game_forecast] +enable = false +max_num = 20 +max_coin = 10 +bet = 1 + ####################### # 通知设置 # ####################### diff --git a/src/Api/Esports/ApiGuess.php b/src/Api/Esports/ApiGuess.php new file mode 100644 index 0000000..6cadeaf --- /dev/null +++ b/src/Api/Esports/ApiGuess.php @@ -0,0 +1,78 @@ + $pn, + 'ps' => $ps, + 'stime' => date("Y-m-d H:i:s", strtotime(date("Y-m-d", time()))), + 'etime' => date("Y-m-d H:i:s", strtotime(date("Y-m-d", time())) + 86400 - 1) + ]; + $headers = [ + 'origin' => 'https://www.bilibili.com', + 'referer' => 'https://www.bilibili.com/v/game/match/competition', + ]; + return Request::getjSON(true, 'pc', $url, $payload, $headers); + } + + /** + * @use 竞猜 + * @param int $oid + * @param int $main_id + * @param int $detail_id + * @param int $count + * @return array + */ + public static function guessAdd(int $oid, int $main_id, int $detail_id, int $count): array + { + $user = User::parseCookie(); + // + $url = 'https://api.bilibili.com/x/esports/guess/add'; + $payload = [ + 'oid' => $oid, + 'main_id' => $main_id, + 'detail_id' => $detail_id, + 'count' => $count, + 'is_fav' => 0, + 'csrf' => $user['csrf'], + 'csrf_token' => $user['csrf'], + ]; + $headers = [ + 'origin' => 'https://www.bilibili.com', + 'referer' => 'https://www.bilibili.com/v/game/match/competition' + ]; + return Request::postJson(true, 'pc', $url, $payload, $headers); + } + + +} + \ No newline at end of file