diff --git a/plugin/MainSite/MainSite.php b/plugin/MainSite/MainSite.php index 3801f7b..ea5a71b 100644 --- a/plugin/MainSite/MainSite.php +++ b/plugin/MainSite/MainSite.php @@ -25,6 +25,7 @@ use Bhp\Log\Log; use Bhp\Plugin\BasePlugin; use Bhp\Plugin\Plugin; use Bhp\TimeLock\TimeLock; +use Bhp\User\User; use Bhp\Util\ArrayR\ArrayR; use Bhp\Util\Exceptions\NoLoginException; use Bhp\Cache\Cache; @@ -123,6 +124,14 @@ class MainSite extends BasePlugin protected function coinTask(string $key = 'coin'): bool { if (!getConf('main_site.add_coin', false, 'bool')) return true; + // 已满6级 + if (!getConf('main_site.when_lv6_stop_coin', false, 'bool')) { + $userInfo = User::userNavInfo(); + if ($userInfo->level_info->current_level >= 6) { + Log::notice('主站任务: 已满6级, 停止投币'); + return true; + } + }; // if (in_array($this->getKey(), $this->records[$key])) return true; // 预计数量 失败默认0 避免损失 @@ -259,7 +268,7 @@ class MainSite extends BasePlugin return 0; } // - $logs = $response['data']['list'] ?? []; + $logs = $response['data']['list'] ; $coins = 0; // foreach ($logs as $log) { diff --git a/profile/example/config/user.ini b/profile/example/config/user.ini index 84741fe..12af4e6 100644 --- a/profile/example/config/user.ini +++ b/profile/example/config/user.ini @@ -51,6 +51,8 @@ share = true ; 每日视频投币/投币稿件数(每日任务最大5) add_coin = true add_coin_num = 5 +; 当等级达到6级时停止投币 +when_lv6_stop_coin = false ; 漫画助手(每日签到、分享) [manga] diff --git a/src/Api/Vip/ApiUser.php b/src/Api/Vip/ApiUser.php index 9440ecc..341f596 100644 --- a/src/Api/Vip/ApiUser.php +++ b/src/Api/Vip/ApiUser.php @@ -18,14 +18,16 @@ namespace Bhp\Api\Vip; use Bhp\Request\Request; +use Bhp\User\User; +use Bhp\WbiSign\WbiSign; class ApiUser { /** - * 用户信息 + * 用户VIP信息 * @return array */ - public static function userInfo(): array + public static function userVipInfo(): array { $url = 'https://api.bilibili.com/x/vip/web/user/info'; $payload = []; @@ -36,4 +38,51 @@ class ApiUser // {"code":0,"message":"0","ttl":1,"data":{"mid":1234,"vip_type":2,"vip_status":1,"vip_due_date":1667750400000,"vip_pay_type":0,"theme_type":0,"label":{"text":"年度大会员","label_theme":"annual_vip","text_color":"#FFFFFF","bg_style":1,"bg_color":"#FB7299","border_color":""},"avatar_subscript":1,"avatar_subscript_url":"http://i0.hdslb.com/bfs/vip/icon_Certification_big_member_22_3x.png","nickname_color":"#FB7299","is_new_user":false}} return Request::getJson(true, 'pc', $url, $payload, $headers); } + + /** + * 用户NAV信息 + * @return array + */ + public static function userNavInfo(): array + { + $user = User::parseCookie(); + // + $url = 'https://api.bilibili.com/x/web-interface/nav'; + $payload = []; + $headers = [ + 'origin' => 'https://space.bilibili.com', + 'referer' => 'https://space.bilibili.com/' . $user['uid'] + ]; + // {"code":-101,"message":"账号未登录","ttl":1,"data":{"isLogin":false,"wbi_img":{"img_url":"https://i0.hdslb.com/bfs/wbi/d2f367bf78934216b7fc14b6e80bb705.png","sub_url":"https://i0.hdslb.com/bfs/wbi/91246ef1d9a6446e9665517705c08269.png"}}} + return Request::getJson(true, 'pc', $url, $payload, $headers); + } + + /** + * 用户SPACE信息 + * @param int $uid + * @return array + */ + public static function userSpaceInfo(int $uid = 0): array + { + if ($uid == 0) { + $user = User::parseCookie(); + $uid = $user['uid']; + } + // + $url = 'https://api.bilibili.com/x/space/wbi/acc/info'; + // + $payload = [ + 'mid' => $uid, + 'platform' => 'web', + // 'wts'=>time(), + // 'w_rid'=>'', + ]; + $headers = [ + 'origin' => 'https://www.bilibili.com', + 'referer' => 'https://www.bilibili.com/', + ]; + return Request::getJson(true, 'pc', $url, WbiSign::encryption($payload), $headers); + } + + } diff --git a/src/LiveSign/LiveSign.php b/src/LiveSign/LiveSign.php new file mode 100644 index 0000000..ad82ef7 --- /dev/null +++ b/src/LiveSign/LiveSign.php @@ -0,0 +1,93 @@ + 'HMAC-MD5', + 1 => 'HMAC-SHA1', + 2 => 'HMAC-SHA256', + 3 => 'HMAC-SHA224', + 4 => 'HMAC-SHA512', + 5 => 'HMAC-SHA384', + ]; + + /** + * @var array|int[] + */ + protected array $default_app_r = [2, 5, 1, 4]; + + /** + * @var string + */ + protected string $default_app_benchmark = 'seacasdgyijfhofiuxoannn'; + + /** + * @var array|int[] + */ + protected array $default_pc_r = [2, 5, 1, 4]; + + /** + * @var string + */ + protected string $default_pc_benchmark = ''; + + /** + * @return void + */ + public function init(): void + { + + } + + /** + * APP + * @param string $benchmark + * @param array $r + * @param array $data + * @return string + */ + public static function app(string $benchmark, array $r, array $data): string + { + $_data = json_encode($data); + foreach ($r as $key) { + $_data = hash_hmac(static::$algorithm[$key], $_data, $benchmark); + } + return $_data; + } + + + /** + * PC + * @param string $benchmark + * @param array $r + * @param array $data + * @return string + */ + public static function pc(string $benchmark, array $r, array $data): string + { + + } + + +} diff --git a/src/User/User.php b/src/User/User.php index e853f6e..b38431f 100644 --- a/src/User/User.php +++ b/src/User/User.php @@ -61,7 +61,7 @@ class User extends SingleTon */ public static function isVip(string $title = '用户信息', array $scope = [1, 2], string $info = '大会员'): bool { - $response = ApiUser::userInfo(); + $response = ApiUser::userVipInfo(); // if ($response['code']) { Log::warning("$title: 获取大会员信息失败 {$response['code']} -> {$response['message']}"); @@ -89,4 +89,21 @@ class User extends SingleTon return self::isVip($title, $scope, $info); } + /** + * 用户信息对象 + * @return object + */ + public static function userNavInfo(): object + { + $response = ApiUser::userNavInfo(); + // + if ($response['code']) { + Log::warning("用户信息: 获取用户信息失败 {$response['code']} -> {$response['message']}"); + return new \stdClass(); + } else { + Log::info("用户信息: 获取用户信息成功"); + return json_decode(json_encode($response['data']), false); + } + } + } diff --git a/src/WbiSign/WbiSign.php b/src/WbiSign/WbiSign.php new file mode 100644 index 0000000..1e3158c --- /dev/null +++ b/src/WbiSign/WbiSign.php @@ -0,0 +1,106 @@ +