From 346607c2e67e77ba9bdfd524b57c7c2250a767be Mon Sep 17 00:00:00 2001 From: nilaoda Date: Thu, 26 Oct 2023 22:43:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E4=BA=8C=E7=BB=B4=E7=A0=81?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=8E=A5=E5=8F=A3=E5=8F=98=E5=8A=A8=20Fix=20?= =?UTF-8?q?#748?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BBDown/BBDownLoginUtil.cs | 20 +++++++++++++------- BBDown/BBDownUtil.cs | 12 ------------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/BBDown/BBDownLoginUtil.cs b/BBDown/BBDownLoginUtil.cs index d2afefca9..f0191110c 100644 --- a/BBDown/BBDownLoginUtil.cs +++ b/BBDown/BBDownLoginUtil.cs @@ -13,14 +13,20 @@ namespace BBDown { internal class BBDownLoginUtil { + public static async Task 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; @@ -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) { diff --git a/BBDown/BBDownUtil.cs b/BBDown/BBDownUtil.cs index 41b633df1..8343f3d52 100644 --- a/BBDown/BBDownUtil.cs +++ b/BBDown/BBDownUtil.cs @@ -334,18 +334,6 @@ public static string GetQueryString(string name, string url) return ""; } - public static async Task 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) {