Skip to content

Commit

Permalink
适配二维码登录接口变动 Fix #748
Browse files Browse the repository at this point in the history
  • Loading branch information
nilaoda committed Oct 26, 2023
1 parent 0090521 commit 346607c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
20 changes: 13 additions & 7 deletions BBDown/BBDownLoginUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ namespace BBDown
{
internal class BBDownLoginUtil
{
public static async Task<string> GetLoginStatusAsync(string qrcodeKey)
{
string queryUrl = $"https://passport.bilibili.com/x/passport-login/web/qrcode/poll?qrcode_key={qrcodeKey}&source=main-fe-header";
return await HTTPUtil.GetWebSourceAsync(queryUrl);
}

public static async Task LoginWEB()
{
try
{
Log("获取登录地址...");
string loginUrl = "https://passport.bilibili.com/qrcode/getLoginUrl";
string loginUrl = "https://passport.bilibili.com/x/passport-login/web/qrcode/generate?source=main-fe-header";
string url = JsonDocument.Parse(await HTTPUtil.GetWebSourceAsync(loginUrl)).RootElement.GetProperty("data").GetProperty("url").ToString();
string oauthKey = GetQueryString("oauthKey", url);
string qrcodeKey = GetQueryString("qrcode_key", url);
//Log(oauthKey);
//Log(url);
bool flag = false;
Expand All @@ -36,18 +42,18 @@ public static async Task LoginWEB()
while (true)
{
await Task.Delay(1000);
string w = await GetLoginStatusAsync(oauthKey);
string data = JsonDocument.Parse(w).RootElement.GetProperty("data").ToString();
if (data == "-2")
string w = await GetLoginStatusAsync(qrcodeKey);
int code = JsonDocument.Parse(w).RootElement.GetProperty("data").GetProperty("code").GetInt32();
if (code == 86038)
{
LogColor("二维码已过期, 请重新执行登录指令.");
break;
}
else if (data == "-4") //等待扫码
else if (code == 86101) //等待扫码
{
continue;
}
else if (data == "-5") //等待确认
else if (code == 86090) //等待确认
{
if (!flag)
{
Expand Down
12 changes: 0 additions & 12 deletions BBDown/BBDownUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,18 +334,6 @@ public static string GetQueryString(string name, string url)
return "";
}

public static async Task<string> GetLoginStatusAsync(string oauthKey)
{
string queryUrl = "https://passport.bilibili.com/qrcode/getLoginInfo";
NameValueCollection postValues = new()
{
{ "oauthKey", oauthKey },
{ "gourl", "https%3A%2F%2Fwww.bilibili.com%2F" }
};
byte[] responseArray = await (await AppHttpClient.PostAsync(queryUrl, new FormUrlEncodedContent(postValues.ToDictionary()))).Content.ReadAsByteArrayAsync();
return Encoding.UTF8.GetString(responseArray);
}

//https://s1.hdslb.com/bfs/static/player/main/video.9efc0c61.js
public static string GetSession(string buvid3)
{
Expand Down

0 comments on commit 346607c

Please sign in to comment.