From f504dbc30c65beb37bca15aa2b8bfa3b4a13ffcb Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Sun, 9 Jan 2022 19:38:23 +0800 Subject: [PATCH] =?UTF-8?q?[BiliAccount=20@=202.5.5.27]=20*=20adds:=201.?= =?UTF-8?q?=20=E6=96=B0=E5=A2=9E=20`Linq.ByQRCode.LoginByQrCodeUrl`?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * enhancements: 1. 更新引用库版本。 --- BiliAccount/BiliAccount.csproj | 16 +++++++------ BiliAccount/Core/ByQRCode.cs | 44 +++++++++++++++++++++++++++++++--- BiliAccount/Linq/ByQRCode.cs | 30 +++++++++++++++++++++++ 3 files changed, 80 insertions(+), 10 deletions(-) diff --git a/BiliAccount/BiliAccount.csproj b/BiliAccount/BiliAccount.csproj index 24e8ba2..7498e59 100644 --- a/BiliAccount/BiliAccount.csproj +++ b/BiliAccount/BiliAccount.csproj @@ -6,12 +6,12 @@ BiliAccount true BiliAccount - 2.5.4.26 + 2.5.5.27 LeoChen zhangbudademao.com BiliAccount 用于处理B站账号类的操作 - Copyright © 2020 zhangbudademao.com, all rights reserved. + Copyright © 2022 zhangbudademao.com, all rights reserved. MIT https://github.com/LeoChen98/BiliAccount https://github.com/LeoChen98/BiliAccount @@ -19,8 +19,10 @@ bilibili bililive bililogin biliaccount favicon_4.png - fixes: - 1. 修复了由于破站改接口导致无法通过密码登录的问题。 + adds: + 1. 新增 `Linq.ByQRCode.LoginByQrCodeUrl`。 + enhancements: + 1. 更新引用库版本。 true snupkg @@ -114,9 +116,9 @@ - - - + + + diff --git a/BiliAccount/Core/ByQRCode.cs b/BiliAccount/Core/ByQRCode.cs index 56ba52a..d78b01f 100644 --- a/BiliAccount/Core/ByQRCode.cs +++ b/BiliAccount/Core/ByQRCode.cs @@ -49,6 +49,42 @@ public static void CancelLogin() Refresher.Dispose(); } + /// + /// 获取二维码要包含的登录url + /// + /// 二维码要包含的登录url + public static string GetQrcodeUrl() + { + return Http.GetBody("https://passport.bilibili.com/qrcode/getLoginUrl", null, "https://passport.bilibili.com/login", $"BiliAccount/{Config.Dll_Version}"); + } + + /// + /// 获取二维码(只返回登录url) + /// + /// 登录url + public static string GetQrcode() + { + re: + string str = GetQrcodeUrl(); + if (!string.IsNullOrEmpty(str)) + { +#if NETSTANDARD2_0 || NETCORE3_0 + GetQrcode_DataTemplete obj = JsonConvert.DeserializeObject(str); +#else + GetQrcode_DataTemplete obj = (new JavaScriptSerializer()).Deserialize(str); +#endif + + if (obj.code == 0) + { + Monitor = new Timer(MonitorCallback, obj.data.oauthKey, 1000, 1000); + Refresher = new Timer(RefresherCallback, null, 180000, Timeout.Infinite); + } + } + else goto re; + + return str; + } + /// /// 获取二维码 /// @@ -60,8 +96,7 @@ public static Bitmap GetQrcode(Color Foreground,Color Background,bool IsBorderVi { Bitmap qrCodeImage = null; re: - //获取二维码要包含的url - string str = Http.GetBody("https://passport.bilibili.com/qrcode/getLoginUrl", null, "https://passport.bilibili.com/login",$"BiliAccount/{Config.Dll_Version}"); + string str = GetQrcodeUrl(); if (!string.IsNullOrEmpty(str)) { #if NETSTANDARD2_0 || NETCORE3_0 @@ -201,7 +236,10 @@ private static void MonitorCallback(object o) /// private static void RefresherCallback(object state) { - Linq.ByQRCode.RaiseQrCodeRefresh(GetQrcode((Color)((List)state)[0], (Color)((List)state)[1], (bool)((List)state)[2])); + if (state == null) + Linq.ByQRCode.RaiseQrCodeRefresh(GetQrcode()); + else + Linq.ByQRCode.RaiseQrCodeRefresh(GetQrcode((Color)((List)state)[0], (Color)((List)state)[1], (bool)((List)state)[2])); } #endregion Private Methods diff --git a/BiliAccount/Linq/ByQRCode.cs b/BiliAccount/Linq/ByQRCode.cs index 392dd31..8c8a157 100644 --- a/BiliAccount/Linq/ByQRCode.cs +++ b/BiliAccount/Linq/ByQRCode.cs @@ -30,6 +30,12 @@ public class ByQRCode /// 新二维码 public delegate void QrCodeRefresh_Handle(Bitmap newQrCode); + /// + /// 二维码刷新处理程序(仅登录url) + /// + /// 新二维码 + public delegate void QrCodeUrlRefresh_Handle(string newQrCodeUrl); + /// /// 二维码登录状态变更处理程序 /// @@ -46,6 +52,11 @@ public class ByQRCode /// public static event QrCodeRefresh_Handle QrCodeRefresh; + /// + /// 登录Url刷新事件 + /// + public static event QrCodeUrlRefresh_Handle QrCodeUrlRefresh; + /// /// 二维码登录状态变更事件 /// @@ -120,6 +131,16 @@ public static ImageSource GetQrCodeImageSource(Bitmap qrCodeImage) #endif + /// + /// 获取登录Url + /// + /// 登录Url + /// 传入了错误的颜色值 + public static string LoginByQrCodeUrl() + { + return Core.ByQRCode.GetQrcode(); + } + /// /// 获取二维码 /// @@ -168,6 +189,15 @@ internal static void RaiseQrCodeRefresh(Bitmap newQrCode) QrCodeRefresh?.Invoke(newQrCode); } + /// + /// 调起二维码刷新 + /// + /// 新二维码 + internal static void RaiseQrCodeRefresh(string newQrCodeUrl) + { + QrCodeUrlRefresh?.Invoke(newQrCodeUrl); + } + /// /// 调起二维码登录状态变更 ///