diff --git a/CHANGELOG.md b/CHANGELOG.md index d569e5a..b44aa61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,11 @@ ## v0.3.0.200425 alpha (2020-04-25) ### Added +- 添加调用函数 - ### Changed +- 取消一处请求头 - ### Fixed diff --git a/src/core/Curl.php b/src/core/Curl.php index daf068c..3e3f4bb 100644 --- a/src/core/Curl.php +++ b/src/core/Curl.php @@ -232,7 +232,7 @@ class Curl 'Accept-Encoding' => 'gzip', 'Accept-Language' => 'zh-cn', 'Connection' => 'keep-alive', - 'Content-Type' => 'application/x-www-form-urlencoded', + // 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Mozilla/5.0 BiliDroid/5.51.1 (bbcallen@gmail.com)', // 'Referer' => 'https://live.bilibili.com/', ]; @@ -240,7 +240,7 @@ class Curl 'Accept' => "application/json, text/plain, */*", 'Accept-Encoding' => 'gzip, deflate', 'Accept-Language' => "zh-CN,zh;q=0.9", - 'Content-Type' => 'application/x-www-form-urlencoded', + // 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/82.0.4056.0 Safari/537.36 Edg/82.0.431.0', // 'Referer' => 'https://live.bilibili.com/', ]; diff --git a/src/plugin/User.php b/src/plugin/User.php index a2ef3fa..ba98e10 100644 --- a/src/plugin/User.php +++ b/src/plugin/User.php @@ -12,6 +12,7 @@ namespace BiliHelper\Plugin; use BiliHelper\Core\Curl; use BiliHelper\Core\Config; +use http\Env\Url; class User { @@ -132,4 +133,129 @@ class User 'sid' => $sid, ]; } + + /** + * @use 获取关注列表 + * @return array + */ + public static function fetchFollowings(): array + { + $user_info = User::parseCookies(); + $uid = $user_info['uid']; + $followings = []; + for ($i = 1; $i < 100; $i++) { + $url = "https://api.bilibili.com/x/relation/followings"; + $payload = [ + 'vmid' => $uid, + 'pn' => $i, + 'ps' => 50, + ]; + $headers = [ + 'referer' => "https://space.bilibili.com/{$uid}/fans/follow?tagid=-1", + ]; + $raw = Curl::get('pc', $url, $payload, $headers); + $de_raw = json_decode($raw, true); + if ($de_raw['code'] == 0 && isset($de_raw['data']['list'])) { + foreach ($de_raw['data']['list'] as $user) { + array_push($followings, $user['mid']); + } + if (count($followings) == $de_raw['data']['total']) { + break; + } + continue; + } + break; + } + return $followings; + } + + + /** + * @use 设置用户关注 + * @param int $follow_uid + * @param bool $un_follow + * @return bool + */ + public static function setUserFollow(int $follow_uid, $un_follow = false): bool + { + $user_info = User::parseCookies(); + $url = 'https://api.live.bilibili.com/relation/v1/Feed/SetUserFollow'; + $payload = [ + 'uid' => $user_info['uid'], + 'type' => $un_follow ? 0 : 1, + 'follow' => $follow_uid, + 're_src' => 18, + 'csrf_token' => $user_info['token'], + 'csrf' => $user_info['token'], + 'visit_id' => '' + ]; + $headers = [ + 'origin' => 'https://live.bilibili.com', + 'referer' => 'https://live.bilibili.com/', + ]; + $raw = Curl::post('pc', $url, $payload, $headers); + // {"code":0,"msg":"success","message":"success","data":[]} + $de_raw = json_decode($raw, true); + if ($de_raw['code'] == 0) { + return true; + } + return false; + } + + /** + * @use 创建关注分组 + * @param string $tag_name + * @return bool + */ + public static function createRelationTag(string $tag_name): bool + { + $user_info = User::parseCookies(); + $url = 'https://api.bilibili.com/x/relation/tag/create?cross_domain=true'; + $payload = [ + 'tag' => $tag_name, + 'csrf' => $user_info['token'], + ]; + $headers = [ + 'content-type' => 'application/x-www-form-urlencoded; charset=UTF-8', + 'origin' => 'https://live.bilibili.com', + 'referer' => 'https://link.bilibili.com/iframe/blfe-link-followIframe' + ]; + $raw = Curl::post('pc', $url, $payload, $headers); + $de_raw = json_decode($raw, true); + // {"code":0,"message":"0","ttl":1,"data":{"tagid":244413}} + if ($de_raw['code'] == 0) { + return true; + } + return false; + } + + /** + * @use 添加用户到分组 + * @param int $fid + * @param int $tid + * @return bool + */ + public static function tagAddUsers(int $fid, int $tid): bool + { + $user_info = User::parseCookies(); + $url = 'https://api.bilibili.com/x/relation/tags/addUsers?cross_domain=true'; + $payload = [ + 'fids' => $fid, + 'tagids' => $tid, + 'csrf' => $user_info['token'], + ]; + $headers = [ + 'content-type' => 'application/x-www-form-urlencoded; charset=UTF-8', + 'origin' => 'https://live.bilibili.com', + 'referer' => 'https://link.bilibili.com/iframe/blfe-link-followIframe' + ]; + $raw = Curl::post('pc', $url, $payload, $headers); + $de_raw = json_decode($raw, true); + // {"code":0,"message":"0","ttl":1} + if ($de_raw['code'] == 0) { + return true; + } + return false; + } + } \ No newline at end of file