mirror of
https://github.com/lkeme/BiliHelper-personal.git
synced 2025-12-19 01:20:08 +08:00
[update] MainSite(when level >= 6 stop some task)
This commit is contained in:
parent
03cc07bd48
commit
dc2bde92c1
@ -25,6 +25,7 @@ use Bhp\Log\Log;
|
|||||||
use Bhp\Plugin\BasePlugin;
|
use Bhp\Plugin\BasePlugin;
|
||||||
use Bhp\Plugin\Plugin;
|
use Bhp\Plugin\Plugin;
|
||||||
use Bhp\TimeLock\TimeLock;
|
use Bhp\TimeLock\TimeLock;
|
||||||
|
use Bhp\User\User;
|
||||||
use Bhp\Util\ArrayR\ArrayR;
|
use Bhp\Util\ArrayR\ArrayR;
|
||||||
use Bhp\Util\Exceptions\NoLoginException;
|
use Bhp\Util\Exceptions\NoLoginException;
|
||||||
use Bhp\Cache\Cache;
|
use Bhp\Cache\Cache;
|
||||||
@ -123,6 +124,14 @@ class MainSite extends BasePlugin
|
|||||||
protected function coinTask(string $key = 'coin'): bool
|
protected function coinTask(string $key = 'coin'): bool
|
||||||
{
|
{
|
||||||
if (!getConf('main_site.add_coin', false, 'bool')) return true;
|
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;
|
if (in_array($this->getKey(), $this->records[$key])) return true;
|
||||||
// 预计数量 失败默认0 避免损失
|
// 预计数量 失败默认0 避免损失
|
||||||
@ -259,7 +268,7 @@ class MainSite extends BasePlugin
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
$logs = $response['data']['list'] ?? [];
|
$logs = $response['data']['list'] ;
|
||||||
$coins = 0;
|
$coins = 0;
|
||||||
//
|
//
|
||||||
foreach ($logs as $log) {
|
foreach ($logs as $log) {
|
||||||
|
|||||||
@ -51,6 +51,8 @@ share = true
|
|||||||
; 每日视频投币/投币稿件数(每日任务最大5)
|
; 每日视频投币/投币稿件数(每日任务最大5)
|
||||||
add_coin = true
|
add_coin = true
|
||||||
add_coin_num = 5
|
add_coin_num = 5
|
||||||
|
; 当等级达到6级时停止投币
|
||||||
|
when_lv6_stop_coin = false
|
||||||
|
|
||||||
; 漫画助手(每日签到、分享)
|
; 漫画助手(每日签到、分享)
|
||||||
[manga]
|
[manga]
|
||||||
|
|||||||
@ -18,14 +18,16 @@
|
|||||||
namespace Bhp\Api\Vip;
|
namespace Bhp\Api\Vip;
|
||||||
|
|
||||||
use Bhp\Request\Request;
|
use Bhp\Request\Request;
|
||||||
|
use Bhp\User\User;
|
||||||
|
use Bhp\WbiSign\WbiSign;
|
||||||
|
|
||||||
class ApiUser
|
class ApiUser
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 用户信息
|
* 用户VIP信息
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function userInfo(): array
|
public static function userVipInfo(): array
|
||||||
{
|
{
|
||||||
$url = 'https://api.bilibili.com/x/vip/web/user/info';
|
$url = 'https://api.bilibili.com/x/vip/web/user/info';
|
||||||
$payload = [];
|
$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}}
|
// {"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);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
93
src/LiveSign/LiveSign.php
Normal file
93
src/LiveSign/LiveSign.php
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Website: https://mudew.com/
|
||||||
|
* Author: Lkeme
|
||||||
|
* License: The MIT License
|
||||||
|
* Email: Useri@live.cn
|
||||||
|
* Updated: 2023 ~ 2024
|
||||||
|
*
|
||||||
|
* _____ _ _ _ _ _ _____ _ _____ _____ _____
|
||||||
|
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & /l、
|
||||||
|
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、 。 7
|
||||||
|
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ / \、゙ ~ヽ *
|
||||||
|
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \ じしf_, )ノ
|
||||||
|
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Bhp\LiveSign;
|
||||||
|
|
||||||
|
use Bhp\Util\DesignPattern\SingleTon;
|
||||||
|
|
||||||
|
class LiveSign extends SingleTon
|
||||||
|
{
|
||||||
|
|
||||||
|
// ["sha512", "sha3_512", "sha384", "sha3_384", "blake2b"]:
|
||||||
|
protected static array $algorithm = [
|
||||||
|
0 => '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
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -61,7 +61,7 @@ class User extends SingleTon
|
|||||||
*/
|
*/
|
||||||
public static function isVip(string $title = '用户信息', array $scope = [1, 2], string $info = '大会员'): bool
|
public static function isVip(string $title = '用户信息', array $scope = [1, 2], string $info = '大会员'): bool
|
||||||
{
|
{
|
||||||
$response = ApiUser::userInfo();
|
$response = ApiUser::userVipInfo();
|
||||||
//
|
//
|
||||||
if ($response['code']) {
|
if ($response['code']) {
|
||||||
Log::warning("$title: 获取大会员信息失败 {$response['code']} -> {$response['message']}");
|
Log::warning("$title: 获取大会员信息失败 {$response['code']} -> {$response['message']}");
|
||||||
@ -89,4 +89,21 @@ class User extends SingleTon
|
|||||||
return self::isVip($title, $scope, $info);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
106
src/WbiSign/WbiSign.php
Normal file
106
src/WbiSign/WbiSign.php
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Website: https://mudew.com/
|
||||||
|
* Author: Lkeme
|
||||||
|
* License: The MIT License
|
||||||
|
* Email: Useri@live.cn
|
||||||
|
* Updated: 2023 ~ 2024
|
||||||
|
*
|
||||||
|
* _____ _ _ _ _ _ _____ _ _____ _____ _____
|
||||||
|
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & /l、
|
||||||
|
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、 。 7
|
||||||
|
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ / \、゙ ~ヽ *
|
||||||
|
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \ じしf_, )ノ
|
||||||
|
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Bhp\WbiSign;
|
||||||
|
|
||||||
|
use Bhp\Api\Vip\ApiUser;
|
||||||
|
use Bhp\Util\DesignPattern\SingleTon;
|
||||||
|
|
||||||
|
class WbiSign extends SingleTon
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var array|int[]
|
||||||
|
*/
|
||||||
|
protected static array $mixinKeyEncTab = [
|
||||||
|
46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49,
|
||||||
|
33, 9, 42, 19, 29, 28, 14, 39, 12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40,
|
||||||
|
61, 26, 17, 0, 1, 60, 51, 30, 4, 22, 25, 54, 21, 56, 59, 6, 63, 57, 62, 11,
|
||||||
|
36, 20, 34, 44, 52
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function init(): void
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取最新的 img_key 和 sub_key
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected static function getWbiKeys(): array
|
||||||
|
{
|
||||||
|
$response = ApiUser::userNavInfo();
|
||||||
|
//
|
||||||
|
$img_url = $response['data']['wbi_img']['img_url'];
|
||||||
|
$sub_url = $response['data']['wbi_img']['sub_url'];
|
||||||
|
$img_key = explode('.', array_slice(explode('/', $img_url), -1)[0])[0];
|
||||||
|
$sub_key = explode('.', array_slice(explode('/', $sub_url), -1)[0])[0];
|
||||||
|
|
||||||
|
return [$img_key, $sub_key];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对 imgKey 和 subKey 进行字符顺序打乱编码
|
||||||
|
* @param string $orig
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected static function getMixinKey(string $orig): string
|
||||||
|
{
|
||||||
|
$mixinKey = "";
|
||||||
|
//
|
||||||
|
foreach (self::$mixinKeyEncTab as $index) {
|
||||||
|
$mixinKey .= $orig[$index];
|
||||||
|
}
|
||||||
|
//
|
||||||
|
return substr($mixinKey, 0, 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为请求参数进行 wbi 签名
|
||||||
|
* @param array $payload
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function encryption(array $payload): array
|
||||||
|
{
|
||||||
|
// 删除payload中的w_rid和wts
|
||||||
|
unset($payload['w_rid']);
|
||||||
|
unset($payload['wts']);
|
||||||
|
//
|
||||||
|
list($img_key, $sub_key) = self::getWbiKeys();
|
||||||
|
//
|
||||||
|
$mixin_key = self::getMixinKey($img_key . $sub_key);
|
||||||
|
$payload['wts'] = round(time());
|
||||||
|
// 按照 key 重排参数
|
||||||
|
ksort($payload);
|
||||||
|
// 过滤 value 中的 "!'()*" 字符
|
||||||
|
array_walk($payload, function (&$value, $key) {
|
||||||
|
$value = str_replace(["!", "'", "(", ")", "*"], "", $value);
|
||||||
|
});
|
||||||
|
// 序列化参数
|
||||||
|
$data = http_build_query($payload);
|
||||||
|
// 计算 w_rid
|
||||||
|
$payload['w_rid'] = md5($data . $mixin_key);;
|
||||||
|
//
|
||||||
|
return $payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user