[feat] Silver2Coin

This commit is contained in:
Lkeme 2022-06-06 14:01:23 +08:00
parent 91b2eb53bd
commit db70c23d65
4 changed files with 179 additions and 1 deletions

View File

@ -143,9 +143,16 @@ class GameForecast extends BasePlugin
*/
protected function startStake(): void
{
$questions = $this->fetchCollectionQuestions();
//
$max_guess = getConf('game_forecast.max_num', 0, 'int');
$max_coin = getConf('game_forecast.max_coin', 0, 'int');
if ($max_guess <= 0 || $max_coin <= 0) {
Log::warning('赛事预测: 每日竞猜次数或者硬币数量不能小于1');
return;
}
//
$questions = $this->fetchCollectionQuestions();
foreach ($questions as $index => $question) {
if ($index >= $max_guess) {
break;

View File

@ -0,0 +1,110 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
use Bhp\Api\XLive\ApiRevenueWallet;
use Bhp\Log\Log;
use Bhp\Plugin\BasePlugin;
use Bhp\Plugin\Plugin;
use Bhp\TimeLock\TimeLock;
class Silver2Coin extends BasePlugin
{
/**
* 插件信息
* @var array|string[]
*/
protected ?array $info = [
'hook' => __CLASS__, // hook
'name' => 'Silver2Coin', // 插件名称
'version' => '0.0.1', // 插件版本
'desc' => '银瓜子兑换硬币', // 插件描述
'author' => 'Lkeme',// 作者
'priority' => 1105, // 插件优先级
'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('silver2coin')) return;
//
if ($this->exchangeTask()) {
// 定时10点 + 1-60分钟随机
TimeLock::setTimes(TimeLock::timing(10, 0, 0, true));
} else {
TimeLock::setTimes(3600);
}
}
/**
* @use 兑换任务
* @return bool
*/
protected function exchangeTask(): bool
{
//
$response = ApiRevenueWallet::appSilver2coin();
if ($this->handle('APP', $response)) return true;
//
$response = ApiRevenueWallet::appSilver2coin();
if ($this->handle('PC', $response)) return true;
//
return false;
}
/**
* @use 处理结果
* @param string $type
* @param array $data
* @return bool
*/
protected function handle(string $type, array $data): bool
{
// {"code":403,"msg":"每天最多能兑换 1 个","message":"每天最多能兑换 1 个","data":[]}
// {"code":403,"msg":"仅主站正式会员以上的用户可以兑换","message":"仅主站正式会员以上的用户可以兑换","data":[]}
// {"code":0,"msg":"兑换成功","message":"兑换成功","data":{"gold":"5074","silver":"36734","tid":"727ab65376a15a6b117cf560a20a21122334","coin":1}}
// {"code":0,"data":{"coin":1,"gold":1234,"silver":4321,"tid":"Silver2Coin21062316490299678123456"},"message":"兑换成功"}
switch ($data['code']) {
case 0:
Log::notice("银瓜子兑换硬币[$type]: {$data['message']}");
return true;
case 403:
Log::warning("银瓜子兑换硬币[$type]: {$data['message']}");
return true;
default:
Log::warning("银瓜子兑换硬币[$type]: CODE -> {$data['code']} MSG -> {$data['message']} ");
}
return false;
}
}

View File

@ -56,6 +56,10 @@ max_num = 20
max_coin = 10
bet = 1
; 银瓜子兑换硬币
[silver2coin]
enable = true
#######################
# 通知设置 #
#######################

View File

@ -0,0 +1,57 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
namespace Bhp\Api\XLive;
use Bhp\Request\Request;
use Bhp\Sign\Sign;
use Bhp\User\User;
class ApiRevenueWallet
{
/**
* @use app银瓜子兑换硬币
* @return array
*/
public static function appSilver2coin(): array
{
$url = 'https://api.live.bilibili.com/AppExchange/silver2coin';
$payload = [];
return Request::postJson(true, 'app', $url, Sign::common($payload));
}
/**
* @use pc银瓜子兑换硬币
* @return array
*/
public static function pcSilver2coin(): array
{
$user = User::parseCookie();
// $url = "https://api.live.bilibili.com/exchange/silver2coin";
// $url = "https://api.live.bilibili.com/pay/v1/Exchange/silver2coin";
$url = "https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin";
$payload = [
'csrf_token' => $user['csrf'],
'csrf' => $user['csrf'],
'visit_id' => ''
];
return Request::postJson(true, 'pc', $url, $payload);
}
}