Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
[BiliAccount @ 2.5.5.27]
Browse files Browse the repository at this point in the history
* adds:
1. 新增 `Linq.ByQRCode.LoginByQrCodeUrl`。

* enhancements:
1. 更新引用库版本。
  • Loading branch information
LeoChen98 committed Jan 9, 2022
1 parent 6cc0fb7 commit f504dbc
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 10 deletions.
16 changes: 9 additions & 7 deletions BiliAccount/BiliAccount.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@
<RootNamespace>BiliAccount</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>BiliAccount</PackageId>
<Version>2.5.4.26</Version>
<Version>2.5.5.27</Version>
<Authors>LeoChen</Authors>
<Company>zhangbudademao.com</Company>
<Product>BiliAccount</Product>
<Description>用于处理B站账号类的操作</Description>
<Copyright>Copyright © 2020 zhangbudademao.com, all rights reserved.</Copyright>
<Copyright>Copyright © 2022 zhangbudademao.com, all rights reserved.</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/LeoChen98/BiliAccount</PackageProjectUrl>
<RepositoryUrl>https://github.com/LeoChen98/BiliAccount</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>bilibili bililive bililogin biliaccount</PackageTags>
<PackageIcon>favicon_4.png</PackageIcon>
<PackageReleaseNotes>
fixes:
1. 修复了由于破站改接口导致无法通过密码登录的问题。
adds:
1. 新增 `Linq.ByQRCode.LoginByQrCodeUrl`。
enhancements:
1. 更新引用库版本。
</PackageReleaseNotes>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
Expand Down Expand Up @@ -114,9 +116,9 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netstandard2.1' OR '$(TargetFramework)' == 'netcoreapp3.0' OR '$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="QRCoder" Version="1.4.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Drawing.Common" Version="5.0.0" />
<PackageReference Include="QRCoder" Version="1.4.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
44 changes: 41 additions & 3 deletions BiliAccount/Core/ByQRCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,42 @@ public static void CancelLogin()
Refresher.Dispose();
}

/// <summary>
/// 获取二维码要包含的登录url
/// </summary>
/// <returns>二维码要包含的登录url</returns>
public static string GetQrcodeUrl()
{
return Http.GetBody("https://passport.bilibili.com/qrcode/getLoginUrl", null, "https://passport.bilibili.com/login", $"BiliAccount/{Config.Dll_Version}");
}

/// <summary>
/// 获取二维码(只返回登录url)
/// </summary>
/// <returns>登录url</returns>
public static string GetQrcode()
{
re:
string str = GetQrcodeUrl();
if (!string.IsNullOrEmpty(str))
{
#if NETSTANDARD2_0 || NETCORE3_0
GetQrcode_DataTemplete obj = JsonConvert.DeserializeObject<GetQrcode_DataTemplete>(str);
#else
GetQrcode_DataTemplete obj = (new JavaScriptSerializer()).Deserialize<GetQrcode_DataTemplete>(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;
}

/// <summary>
/// 获取二维码
/// </summary>
Expand All @@ -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
Expand Down Expand Up @@ -201,7 +236,10 @@ private static void MonitorCallback(object o)
/// <param name="state"></param>
private static void RefresherCallback(object state)
{
Linq.ByQRCode.RaiseQrCodeRefresh(GetQrcode((Color)((List<object>)state)[0], (Color)((List<object>)state)[1], (bool)((List<object>)state)[2]));
if (state == null)
Linq.ByQRCode.RaiseQrCodeRefresh(GetQrcode());
else
Linq.ByQRCode.RaiseQrCodeRefresh(GetQrcode((Color)((List<object>)state)[0], (Color)((List<object>)state)[1], (bool)((List<object>)state)[2]));
}

#endregion Private Methods
Expand Down
30 changes: 30 additions & 0 deletions BiliAccount/Linq/ByQRCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public class ByQRCode
/// <param name="newQrCode">新二维码</param>
public delegate void QrCodeRefresh_Handle(Bitmap newQrCode);

/// <summary>
/// 二维码刷新处理程序(仅登录url)
/// </summary>
/// <param name="newQrCodeUrl">新二维码</param>
public delegate void QrCodeUrlRefresh_Handle(string newQrCodeUrl);

/// <summary>
/// 二维码登录状态变更处理程序
/// </summary>
Expand All @@ -46,6 +52,11 @@ public class ByQRCode
/// </summary>
public static event QrCodeRefresh_Handle QrCodeRefresh;

/// <summary>
/// 登录Url刷新事件
/// </summary>
public static event QrCodeUrlRefresh_Handle QrCodeUrlRefresh;

/// <summary>
/// 二维码登录状态变更事件
/// </summary>
Expand Down Expand Up @@ -120,6 +131,16 @@ public static ImageSource GetQrCodeImageSource(Bitmap qrCodeImage)

#endif

/// <summary>
/// 获取登录Url
/// </summary>
/// <returns>登录Url</returns>
/// <exception cref="Exceptions.InvalidColorValue">传入了错误的颜色值</exception>
public static string LoginByQrCodeUrl()
{
return Core.ByQRCode.GetQrcode();
}

/// <summary>
/// 获取二维码
/// </summary>
Expand Down Expand Up @@ -168,6 +189,15 @@ internal static void RaiseQrCodeRefresh(Bitmap newQrCode)
QrCodeRefresh?.Invoke(newQrCode);
}

/// <summary>
/// 调起二维码刷新
/// </summary>
/// <param name="newQrCodeUrl">新二维码</param>
internal static void RaiseQrCodeRefresh(string newQrCodeUrl)
{
QrCodeUrlRefresh?.Invoke(newQrCodeUrl);
}

/// <summary>
/// 调起二维码登录状态变更
/// </summary>
Expand Down

0 comments on commit f504dbc

Please sign in to comment.