diff --git a/plugin/Silver2Coin/Silver2Coin.php b/plugin/Silver2Coin/Silver2Coin.php index 08996a4..0405789 100644 --- a/plugin/Silver2Coin/Silver2Coin.php +++ b/plugin/Silver2Coin/Silver2Coin.php @@ -56,12 +56,48 @@ class Silver2Coin extends BasePlugin { if (TimeLock::getTimes() > time() || !getEnable('silver2coin')) return; // - if ($this->exchangeTask()) { - // 定时10点 + 1-60分钟随机 - TimeLock::setTimes(TimeLock::timing(10, 0, 0, true)); - } else { - TimeLock::setTimes(3600); + if ($this->before()) { + if (!$this->exchangeTask()) { + TimeLock::setTimes(3600); + return; + } + // + $this->after(); } + // 定时10点 + 1-60分钟随机 + TimeLock::setTimes(TimeLock::timing(10, 0, 0, true)); + } + + /** + * @return void + */ + protected function after(): void + { + ApiRevenueWallet::myWallet(); + } + + /** + * @return bool + */ + protected function before(): bool + { + $response = ApiRevenueWallet::getStatus(); + // + if ($response['code']) { + Log::warning("银瓜子兑换硬币: 获取钱包状态失败 {$response['code']} -> {$response['message']}"); + return true; + } + // + if ($response['data']['silver_2_coin_left'] == 0) { + Log::notice("银瓜子兑换硬币: 今日已兑换过一次了哦~"); + return false; + } + // + if ($response['data']['silver'] < 700) { + Log::notice("银瓜子兑换硬币: 瓜子余额不足以兑换哦~~"); + return false; + } + return true; } /** @@ -105,6 +141,5 @@ class Silver2Coin extends BasePlugin return false; } - } \ No newline at end of file diff --git a/src/Api/XLive/ApiRevenueWallet.php b/src/Api/XLive/ApiRevenueWallet.php index 787d96f..646c3d7 100644 --- a/src/Api/XLive/ApiRevenueWallet.php +++ b/src/Api/XLive/ApiRevenueWallet.php @@ -31,6 +31,7 @@ class ApiRevenueWallet { $url = 'https://api.live.bilibili.com/AppExchange/silver2coin'; $payload = []; + // {"code":403,"data":{"coin":0,"gold":0,"silver":0,"tid":""},"message":"银瓜子余额不足"} return Request::postJson(true, 'app', $url, Sign::common($payload)); } @@ -49,9 +50,39 @@ class ApiRevenueWallet 'csrf' => $user['csrf'], 'visit_id' => '' ]; + // {"code":403,"data":{"coin":0,"gold":0,"silver":0,"tid":""},"message":"银瓜子余额不足"} return Request::postJson(true, 'pc', $url, $payload); } + /** + * @use 钱包状态 + * @return array + */ + public static function getStatus(): array + { + $url = "https://api.live.bilibili.com/xlive/revenue/v1/wallet/getStatus"; + $payload = []; + // {"code":0,"message":"0","ttl":1,"data":{"silver":1111,"gold":0,"coin":11,"bp":11,"coin_2_silver_left":50,"silver_2_coin_left":1,"num":50,"status":1,"vip":1}} + return Request::getJson(true, 'pc', $url, $payload); + } + + /** + * @use 我的钱包 + * @return array + */ + public static function myWallet(): array + { + $url = 'https://api.live.bilibili.com/xlive/revenue/v1/wallet/myWallet'; + $payload = [ + 'need_bp' => 1, + 'need_metal' => 1, + 'platform' => 'pc' + ]; + // {"code":0,"message":"0","ttl":1,"data":{"gold":0,"silver":111,"bp":"0","metal":111,"need_use_new_bp":true,"ios_bp":0,"common_bp":0,"new_bp":"0","bp_2_gold_amount":0}} + return Request::getJson(true, 'pc', $url, $payload); + + } + } \ No newline at end of file