[update] VipPoint

This commit is contained in:
Lkeme 2022-09-11 12:34:24 +08:00
parent b2d53d755e
commit f79488ba67
13 changed files with 666 additions and 1 deletions

2
.gitignore vendored
View File

@ -11,7 +11,7 @@ tmp/
out
gen
composer.lock
Traits/
#Traits/
README1.md
script.php

View File

@ -0,0 +1,41 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
trait Bonus
{
use CommonTaskInfo;
/**
* @param array $data
* @param string $name
* @return bool
*/
public function bonus(array $data, string $name): bool
{
$title = '福利任务';
$code = 'bonus';
//
if ($this->isComplete($data, $name, $title, $code)) {
return true;
}
//
$this->worker($data, $name, $title, $code,1);
return false;
}
}

View File

@ -0,0 +1,39 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
trait BuyVipMall
{
use CommonTaskInfo;
/**
* @param array $data
* @param string $name
* @return bool
*/
public function buyVipMall(array $data, string $name): bool
{
$title = '日常任务';
$code = 'vipmallbuy';
//
if ($this->isComplete($data, $name, $title, $code)) {
return true;
}
//
return $this->worker($data, $name, $title, $code, 4);
}
}

View File

@ -0,0 +1,39 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
trait BuyVipProduct
{
use CommonTaskInfo;
/**
* @param array $data
* @param string $name
* @return bool
*/
public function buyVipProduct(array $data, string $name): bool
{
$title = '日常任务';
$code = 'subscribe';
//
if ($this->isComplete($data, $name, $title, $code)) {
return true;
}
//
return $this->worker($data, $name, $title, $code, 4);
}
}

View File

@ -0,0 +1,39 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
trait BuyVipVideo
{
use CommonTaskInfo;
/**
* @param array $data
* @param string $name
* @return bool
*/
public function buyVipVideo(array $data, string $name): bool
{
$title = '日常任务';
$code = 'tvodbuy';
//
if ($this->isComplete($data, $name, $title, $code)) {
return true;
}
//
return $this->worker($data, $name, $title, $code, 4);
}
}

View File

@ -0,0 +1,170 @@
<?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\Log\Log;
trait CommonTaskInfo
{
/**
* 是否已经完成
* @param array $data
* @param string $name
* @param $title
* @param $code
* @return bool
*/
protected function isComplete(array $data, string $name, $title, $code): bool
{
$item = $this->getTaskInfo($data, $title, $code);
// 异常情况1
if (empty($item)) {
Log::warning("大会员积分@{$name}: 任务异常,暂定完成,通知开发者修复");
return true;
}
// 完成情况1
if ($item['state'] == 3) {
Log::notice("大会员积分@{$name}: {$item['task_code']} 任务已经完成");
return true;
}
// 需要领取或者需要完成
if (in_array($item['state'], [0, 1])) {
return false;
}
// 额外情况
Log::warning("大会员积分@{$name}: {$item['task_code']} 任务出现额外情况,暂定完成,通知开发者修复");
return true;
}
/**
* 获取任务
* @param array $data
* @param string $title
* @param string $code
* @return array
*/
protected function getTaskInfo(array $data, string $title, string $code): array
{
$modules = $data['data']['task_info']['modules'] ?? [];
if (empty($modules)) return [];
//
foreach ($modules as $module) {
if ($module['module_title'] != $title) continue;
//
foreach ($module['common_task_item'] as $item) {
if ($item['task_code'] != $code) continue;
//
return $item;
}
}
return [];
}
/**
* @param array $data
* @param string $name
* @param string $title
* @param string $code
* @param int $c
* @param string $arg
* @return bool
*/
protected function worker(array $data, string $name, string $title, string $code, int $c, string $arg = ''): bool
{
$item = $this->getTaskInfo($data, $title, $code);
if ($item['state'] == 0) {
// 领取任务
$response = \Bhp\Api\Api\Pgc\Activity\Score\ApiTask::receive($item['task_code']);
if ($response['code']) {
Log::warning("大会员积分@{$name}: {$item['task_code']} 任务领取失败 " . json_encode($response));
return false;
}
Log::notice("大会员积分@{$name}: {$item['task_code']} 任务领取成功");
}
// 做任务
return match ($c) {
1 => $this->complete($item['task_code'], $name),
2 => $this->completeView($item['task_code'], $name, $arg),
3 => $this->completeVipMallView($item['task_code'], $name),
4 => $this->completeReceive(),
default => false,
};
}
/**
* @param string $task_code
* @param string $name
* @return bool
*/
protected function complete(string $task_code, string $name): bool
{
// 做任务
$response = \Bhp\Api\Api\Pgc\Activity\Score\ApiTask::complete($task_code);
if ($response['code']) {
Log::warning("大会员积分@{$name}: {$task_code} 任务执行失败 " . json_encode($response));
return false;
}
Log::notice("大会员积分@{$name}: {$task_code} 任务执行成功");
return true;
}
/**
* @param string $task_code
* @param string $name
* @param string $channel
* @return bool
*/
protected function completeView(string $task_code, string $name, string $channel): bool
{
sleep(mt_rand(10, 20));
// 做任务
$response = \Bhp\Api\Api\Pgc\Activity\Deliver\ApiTask::complete($channel);
if ($response['code']) {
Log::warning("大会员积分@{$name}: {$task_code} 任务执行失败 " . json_encode($response));
return false;
}
Log::notice("大会员积分@{$name}: {$task_code} 任务执行成功");
return true;
}
/**
* @param string $task_code
* @param string $name
* @return bool
*/
protected function completeVipMallView(string $task_code, string $name,): bool
{
sleep(mt_rand(10, 20));
// 做任务
$response = \Bhp\Api\Show\Api\Activity\Fire\Common\ApiEvent::dispatch();
if ($response['code']) {
Log::warning("大会员积分@{$name}: {$task_code} 任务执行失败 " . json_encode($response));
return false;
}
Log::notice("大会员积分@{$name}: {$task_code} 任务执行成功");
return true;
}
/**
* @return bool
*/
protected function completeReceive(): bool
{
return true;
}
}

View File

@ -0,0 +1,36 @@
<?php declare(strict_types=1);
use Bhp\Log\Log;
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
trait PointInfo
{
/**
* @param array $data
* @param string $name
* @return bool
*/
public function pointInfo(array $data, string $name): bool
{
$now = date('Y-m-d H:i:s', $data['data']['current_ts']);
$point = $data['data']['point_info']['point'];
Log::notice("大会员积分@{$name}: 截至 {$now} 您当前拥有 {$point} 个积分");
return true;
}
}

View File

@ -0,0 +1,41 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
trait Privilege
{
use CommonTaskInfo;
/**
* @param array $data
* @param string $name
* @return bool
*/
public function privilege(array $data, string $name):bool
{
$title = '体验任务';
$code = 'privilege';
if ($this->isComplete($data, $name, $title, $code)) {
return true;
}
//
$this->worker($data, $name, $title, $code,1);
return false;
}
}

View File

@ -0,0 +1,96 @@
<?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\Api\Pgc\Activity\Score\ApiTask;
use Bhp\Log\Log;
trait SignIn
{
/**
* 签到
* @param array $data
* @param string $name
* @return bool
*/
public function signIn(array $data, string $name): bool
{
if ($this->isSignIn($data, $name)) {
return true;
}
//
$this->_signIn($name);
return false;
}
/**
* 签到
* @param string $name
* @return bool
*/
protected function _signIn(string $name): bool
{
// {"code":0,"message":"success"}
$response = ApiTask::sign();
//
if ($response['code']) {
Log::warning("大会员积分@{$name}: 签到失败" . json_encode($response));
return false;
}
return true;
}
/**
* 是否已经签到
* @param array $data
* @param string $now
* @return int
*/
protected function _isSignIn(array $data, string $now): int
{
$histories = $data['data']['task_info']['sing_task_item']['histories'] ?? [];
//
foreach ($histories as $h) {
// day: "2022-09-10" is_today: true score: 5 signed: true
if ($h['day'] == $now && isset($h['is_today']) && $h['signed'] && $h['is_today']) {
return $h['score'];
}
}
return 0;
}
/**
* 是否已经签到
* @param array $data
* @param string $name
* @return bool
*/
protected function isSignIn(array $data, string $name): bool
{
$now = date("Y-m-d");
//
if ($score = $this->_isSignIn($data, $now)) {
Log::info("大会员积分@{$name}: 今日完成签到,获得积分 {$score}分 已累计签到 {$data['data']['task_info']['sing_task_item']['count']}");
return true;
}
return false;
}
}

View File

@ -0,0 +1,42 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
trait ViewAnimate
{
use CommonTaskInfo;
/**
* @param array $data
* @param string $name
* @return bool
*/
public function viewAnimate(array $data, string $name): bool
{
$title = '日常任务';
$code = 'animatetab';
$channel = 'jp_channel';
//
if ($this->isComplete($data, $name, $title, $code)) {
return true;
}
//
$this->worker($data, $name, $title, $code, 2, $channel);
return false;
}
}

View File

@ -0,0 +1,42 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
trait ViewFilmChannel
{
use CommonTaskInfo;
/**
* @param array $data
* @param string $name
* @return bool
*/
public function viewFilmChannel(array $data, string $name): bool
{
$title = '日常任务';
$code = 'filmtab';
$channel = 'tv_channel';
//
if ($this->isComplete($data, $name, $title, $code)) {
return true;
}
//
$this->worker($data, $name, $title, $code,2, $channel);
return false;
}
}

View File

@ -0,0 +1,39 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
trait ViewVideo
{
use CommonTaskInfo;
/**
* @param array $data
* @param string $name
* @return bool
*/
public function viewVideo(array $data, string $name): bool
{
$title = '日常任务';
$code = 'ogvwatch';
//
if ($this->isComplete($data, $name, $title, $code)) {
return true;
}
//
return $this->worker($data, $name, $title, $code, 4);
}
}

View File

@ -0,0 +1,41 @@
<?php declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2022 ~ 2023
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & l、
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ /   \、゙ ~ *
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \  じしf_, )
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
*/
trait ViewVipMall
{
use CommonTaskInfo;
/**
* @param array $data
* @param string $name
* @return bool
*/
public function viewVipMall(array $data, string $name): bool
{
$title = '日常任务';
$code = 'vipmallview';
//
if ($this->isComplete($data, $name, $title, $code)) {
return true;
}
//
$this->worker($data, $name, $title, $code,3);
return false;
}
}