BiliHelper-personal/plugin/VipPoint/Traits/SignIn.php
2024-12-31 11:17:17 +08:00

97 lines
2.5 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 declare(strict_types=1);
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2018 ~ 2026
*
* _____ _ _ _ _ _ _____ _ _____ _____ _____
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & 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;
}
}