BiliHelper-personal/src/plugin/Silver.php
2020-03-18 14:32:06 +08:00

109 lines
2.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2020 ~ 2021
*/
namespace BiliHelper\Plugin;
use BiliHelper\Core\Log;
use BiliHelper\Core\Curl;
use BiliHelper\Util\TimeLock;
class Silver
{
use TimeLock;
protected static $task = [];
public static function run()
{
if (self::getLock() > time()) {
return;
}
if (empty(self::$task)) {
self::getSilverBox();
} else {
self::openSilverBox();
}
}
/**
* @use 获取宝箱
*/
private static function getSilverBox()
{
$url = 'https://api.live.bilibili.com/lottery/v1/SilverBox/getCurrentTask';
$payload = [];
$data = Curl::get('app', $url, Sign::common($payload));
$data = json_decode($data, true);
if (isset($data['code']) && $data['code'] == -10017) {
Log::notice($data['message']);
if (User::isMaster()) {
self::setLock(self::timing(6));
} else {
self::setLock(self::timing(10));
}
return;
}
if (isset($data['code']) && $data['code']) {
Log::error("check freeSilverCurrentTask failed! Error message: {$data['message']}");
die();
}
Log::info("获得一个宝箱,内含 {$data['data']['silver']} 个瓜子");
Log::info("开启宝箱需等待 {$data['data']['minute']} 分钟");
self::$task = [
'time_start' => $data['data']['time_start'],
'time_end' => $data['data']['time_end'],
];
self::setLock($data['data']['minute'] * 60 + 5);
}
/**
* @use 开启宝箱
*/
private static function openSilverBox()
{
$url = 'https://api.live.bilibili.com/mobile/freeSilverAward';
$payload = [
'time_end' => self::$task['time_end'],
'time_start' => self::$task['time_start']
];
$data = Curl::get('app', $url, Sign::common($payload));
$data = json_decode($data, true);
if ($data['code'] == -800) {
self::setLock(12 * 60 * 60);
Log::warning("领取宝箱失败,{$data['message']}!");
return;
}
if ($data['code'] == -903) {
Log::warning("领取宝箱失败,{$data['message']}!");
self::$task = [];
self::setLock(60);
return;
}
if (isset($data['code']) && $data['code']) {
Log::warning("领取宝箱失败,{$data['message']}!");
self::setLock(60);
return;
}
Log::notice("领取宝箱成功Silver: {$data['data']['silver']}(+{$data['data']['awardSilver']})");
self::$task = [];
self::setLock(10);
}
}