Skip to content

Commit

Permalink
feat: 游客添加随机buvid3解决部分接口风控(真实buvid3暂未实现、后续可以考虑)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaobiao131 committed Mar 5, 2024
1 parent 602e29c commit bc5be4f
Show file tree
Hide file tree
Showing 21 changed files with 421 additions and 537 deletions.
4 changes: 2 additions & 2 deletions DownKyi.Core/BiliApi/Login/LoginHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public static bool SaveLoginInfoCookies(string url)
/// 获得登录的cookies
/// </summary>
/// <returns></returns>
public static CookieContainer GetLoginInfoCookies()
public static CookieContainer? GetLoginInfoCookies()
{
string tempFile = LOCAL_LOGIN_INFO + "-" + Guid.NewGuid().ToString("N");
var tempFile = LOCAL_LOGIN_INFO + "-" + Guid.NewGuid().ToString("N");

if (File.Exists(LOCAL_LOGIN_INFO))
{
Expand Down
2 changes: 1 addition & 1 deletion DownKyi.Core/BiliApi/Users/Models/SpacePublication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace DownKyi.Core.BiliApi.Users.Models;
// https://api.bilibili.com/x/space/arc/search
public class SpacePublicationOrigin : BaseModel
{
[JsonProperty("data")] public SpacePublication Data { get; set; }
[JsonProperty("data")] public SpacePublication? Data { get; set; }
}

public class SpacePublication : BaseModel
Expand Down
2 changes: 1 addition & 1 deletion DownKyi.Core/BiliApi/Users/Models/SpacePublicationList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ namespace DownKyi.Core.BiliApi.Users.Models;
public class SpacePublicationList : BaseModel
{
[JsonProperty("tlist")] public SpacePublicationListType Tlist { get; set; }
[JsonProperty("vlist")] public List<SpacePublicationListVideo> Vlist { get; set; }
[JsonProperty("vlist")] public List<SpacePublicationListVideo>? Vlist { get; set; }
}
4 changes: 2 additions & 2 deletions DownKyi.Core/BiliApi/Users/Models/UserInfoForSpace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class UserInfoForSpaceOrigin : BaseModel
//public string Message { get; set; }
//[JsonProperty("ttl")]
//public int Ttl { get; set; }
[JsonProperty("data")] public UserInfoForSpace Data { get; set; }
[JsonProperty("data")] public UserInfoForSpace? Data { get; set; }
}

public class UserInfoForSpace : BaseModel
Expand All @@ -37,7 +37,7 @@ public class UserInfoForSpace : BaseModel
//public bool FansBadge { get; set; }
// fans_medal
// official
[JsonProperty("vip")] public UserInfoVip Vip { get; set; }
[JsonProperty("vip")] public UserInfoVip? Vip { get; set; }

// pendant
// nameplate
Expand Down
2 changes: 1 addition & 1 deletion DownKyi.Core/BiliApi/Users/Models/UserInfoVip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class UserInfoVip : BaseModel

// vip_pay_type
// theme_type
[JsonProperty("label")] public UserInfoVipLabel Label { get; set; }
[JsonProperty("label")] public UserInfoVipLabel? Label { get; set; }
[JsonProperty("avatar_subscript")] public int AvatarSubscript { get; set; }

[JsonProperty("nickname_color")] public string NicknameColor { get; set; }
Expand Down
51 changes: 19 additions & 32 deletions DownKyi.Core/BiliApi/Users/UserInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,17 @@ public static class UserInfo
/// 导航栏用户信息
/// </summary>
/// <returns></returns>
public static UserInfoForNavigation GetUserInfoForNavigation()
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);
const string url = "https://api.bilibili.com/x/web-interface/nav";
const string referer = "https://www.bilibili.com";
var response = WebClient.RequestWeb(url, referer);

try
{
UserInfoForNavigationOrigin userInfo =
JsonConvert.DeserializeObject<UserInfoForNavigationOrigin>(response);
if (userInfo == null || userInfo.Data == null)
{
return null;
}
var userInfo = JsonConvert.DeserializeObject<UserInfoForNavigationOrigin>(response);

return userInfo.Data;
return userInfo?.Data;
}
catch (Exception e)
{
Expand All @@ -45,26 +40,22 @@ public static UserInfoForNavigation GetUserInfoForNavigation()
/// </summary>
/// <param name="mid"></param>
/// <returns></returns>
public static UserInfoForSpace GetUserInfoForSpace(long mid)
public static UserInfoForSpace? GetUserInfoForSpace(long mid)
{
var parameters = new Dictionary<string, object>
{
{ "mid", mid }
};
string query = WbiSign.ParametersToQuery(WbiSign.EncodeWbi(parameters));
string url = $"https://api.bilibili.com/x/space/wbi/acc/info?{query}";
string referer = "https://www.bilibili.com";
string response = WebClient.RequestWeb(url, referer);
var query = WbiSign.ParametersToQuery(WbiSign.EncodeWbi(parameters));
var url = $"https://api.bilibili.com/x/space/wbi/acc/info?{query}";
const string referer = "https://www.bilibili.com";
var response = WebClient.RequestWeb(url, referer, needRandomBvuid3: true);

try
{
UserInfoForSpaceOrigin spaceInfo = JsonConvert.DeserializeObject<UserInfoForSpaceOrigin>(response);
if (spaceInfo == null || spaceInfo.Data == null)
{
return null;
}
var spaceInfo = JsonConvert.DeserializeObject<UserInfoForSpaceOrigin>(response);

return spaceInfo.Data;
return spaceInfo?.Data;
}
catch (Exception e)
{
Expand All @@ -78,21 +69,17 @@ public static UserInfoForSpace GetUserInfoForSpace(long mid)
/// 本用户详细信息
/// </summary>
/// <returns></returns>
public static MyInfo GetMyInfo()
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);
const string url = "https://api.bilibili.com/x/space/myinfo";
const string referer = "https://www.bilibili.com";
var response = WebClient.RequestWeb(url, referer);

try
{
MyInfoOrigin myInfo = JsonConvert.DeserializeObject<MyInfoOrigin>(response);
if (myInfo == null || myInfo.Data == null)
{
return null;
}
var myInfo = JsonConvert.DeserializeObject<MyInfoOrigin>(response);

return myInfo.Data;
return myInfo?.Data;
}
catch (Exception e)
{
Expand Down
Loading

0 comments on commit bc5be4f

Please sign in to comment.