using DownKyi.Core.BiliApi.Users.Models; using DownKyi.Core.Logging; using Newtonsoft.Json; using System; namespace DownKyi.Core.BiliApi.Users { /// /// 用户基本信息 /// public static class UserInfo { /// /// 导航栏用户信息 /// /// public static UserInfoForNavigation GetUserInfoForNavigation() { string url = "https://api.bilibili.com/x/web-interface/nav"; string referer = "https://www.bilibili.com"; string response = WebClient.RequestWeb(url, referer); try { UserInfoForNavigationOrigin userInfo = JsonConvert.DeserializeObject(response); if (userInfo == null || userInfo.Data == null) { return null; } if (userInfo.Data.IsLogin) { return userInfo.Data; } else { return null; } } catch (Exception e) { Utils.Debugging.Console.PrintLine("GetUserInfoForNavigation()发生异常: {0}", e); LogManager.Error("UserInfo", e); return null; } } /// /// 用户空间详细信息 /// /// /// public static UserInfoForSpace GetUserInfoForSpace(long mid) { string url = $"https://api.bilibili.com/x/space/acc/info?mid={mid}"; string referer = "https://www.bilibili.com"; string response = WebClient.RequestWeb(url, referer); try { UserInfoForSpaceOrigin spaceInfo = JsonConvert.DeserializeObject(response); if (spaceInfo == null || spaceInfo.Data == null) { return null; } return spaceInfo.Data; } catch (Exception e) { Utils.Debugging.Console.PrintLine("GetInfoForSpace()发生异常: {0}", e); LogManager.Error("UserInfo", e); return null; } } /// /// 本用户详细信息 /// /// public static MyInfo GetMyInfo() { string url = "https://api.bilibili.com/x/space/myinfo"; string referer = "https://www.bilibili.com"; string response = WebClient.RequestWeb(url, referer); try { MyInfoOrigin myInfo = JsonConvert.DeserializeObject(response); if (myInfo == null || myInfo.Data == null) { return null; } return myInfo.Data; } catch (Exception e) { Utils.Debugging.Console.PrintLine("GetMyInfo()发生异常: {0}", e); LogManager.Error("UserInfo", e); return null; } } } }