diff --git a/.gitignore b/.gitignore index 525bbe8..e580b6d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,7 @@ tmp/ out gen composer.lock -Traits/ +#Traits/ README1.md script.php diff --git a/plugin/VipPoint/Traits/Bonus.php b/plugin/VipPoint/Traits/Bonus.php new file mode 100644 index 0000000..9390a4e --- /dev/null +++ b/plugin/VipPoint/Traits/Bonus.php @@ -0,0 +1,41 @@ +isComplete($data, $name, $title, $code)) { + return true; + } + // + $this->worker($data, $name, $title, $code,1); + return false; + } + + +} diff --git a/plugin/VipPoint/Traits/BuyVipMall.php b/plugin/VipPoint/Traits/BuyVipMall.php new file mode 100644 index 0000000..29c8824 --- /dev/null +++ b/plugin/VipPoint/Traits/BuyVipMall.php @@ -0,0 +1,39 @@ +isComplete($data, $name, $title, $code)) { + return true; + } + // + return $this->worker($data, $name, $title, $code, 4); + } + + +} diff --git a/plugin/VipPoint/Traits/BuyVipProduct.php b/plugin/VipPoint/Traits/BuyVipProduct.php new file mode 100644 index 0000000..96d3546 --- /dev/null +++ b/plugin/VipPoint/Traits/BuyVipProduct.php @@ -0,0 +1,39 @@ +isComplete($data, $name, $title, $code)) { + return true; + } + // + return $this->worker($data, $name, $title, $code, 4); + } + + +} diff --git a/plugin/VipPoint/Traits/BuyVipVideo.php b/plugin/VipPoint/Traits/BuyVipVideo.php new file mode 100644 index 0000000..ecc43b0 --- /dev/null +++ b/plugin/VipPoint/Traits/BuyVipVideo.php @@ -0,0 +1,39 @@ +isComplete($data, $name, $title, $code)) { + return true; + } + // + return $this->worker($data, $name, $title, $code, 4); + } + + +} diff --git a/plugin/VipPoint/Traits/CommonTaskInfo.php b/plugin/VipPoint/Traits/CommonTaskInfo.php new file mode 100644 index 0000000..3c0f729 --- /dev/null +++ b/plugin/VipPoint/Traits/CommonTaskInfo.php @@ -0,0 +1,170 @@ +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; + } +} diff --git a/plugin/VipPoint/Traits/PointInfo.php b/plugin/VipPoint/Traits/PointInfo.php new file mode 100644 index 0000000..ee6fd29 --- /dev/null +++ b/plugin/VipPoint/Traits/PointInfo.php @@ -0,0 +1,36 @@ +isComplete($data, $name, $title, $code)) { + return true; + } + // + $this->worker($data, $name, $title, $code,1); + return false; + } + + +} diff --git a/plugin/VipPoint/Traits/SignIn.php b/plugin/VipPoint/Traits/SignIn.php new file mode 100644 index 0000000..0dc7263 --- /dev/null +++ b/plugin/VipPoint/Traits/SignIn.php @@ -0,0 +1,96 @@ +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; + } + +} diff --git a/plugin/VipPoint/Traits/ViewAnimate.php b/plugin/VipPoint/Traits/ViewAnimate.php new file mode 100644 index 0000000..e5fde82 --- /dev/null +++ b/plugin/VipPoint/Traits/ViewAnimate.php @@ -0,0 +1,42 @@ +isComplete($data, $name, $title, $code)) { + return true; + } + // + $this->worker($data, $name, $title, $code, 2, $channel); + return false; + } + + +} diff --git a/plugin/VipPoint/Traits/ViewFilmChannel.php b/plugin/VipPoint/Traits/ViewFilmChannel.php new file mode 100644 index 0000000..cf51274 --- /dev/null +++ b/plugin/VipPoint/Traits/ViewFilmChannel.php @@ -0,0 +1,42 @@ +isComplete($data, $name, $title, $code)) { + return true; + } + // + $this->worker($data, $name, $title, $code,2, $channel); + return false; + } + + +} diff --git a/plugin/VipPoint/Traits/ViewVideo.php b/plugin/VipPoint/Traits/ViewVideo.php new file mode 100644 index 0000000..1d8792b --- /dev/null +++ b/plugin/VipPoint/Traits/ViewVideo.php @@ -0,0 +1,39 @@ +isComplete($data, $name, $title, $code)) { + return true; + } + // + return $this->worker($data, $name, $title, $code, 4); + } + + +} diff --git a/plugin/VipPoint/Traits/ViewVipMall.php b/plugin/VipPoint/Traits/ViewVipMall.php new file mode 100644 index 0000000..34dd823 --- /dev/null +++ b/plugin/VipPoint/Traits/ViewVipMall.php @@ -0,0 +1,41 @@ +isComplete($data, $name, $title, $code)) { + return true; + } + // + $this->worker($data, $name, $title, $code,3); + return false; + } + + +}