Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
修复二维码登录并更新证书 (#1773)
Browse files Browse the repository at this point in the history
  • Loading branch information
Richasy committed Sep 24, 2023
1 parent 11f6cf6 commit 23706da
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/App/App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>
<PackageCertificateKeyFile>App_TemporaryKey.pfx</PackageCertificateKeyFile>
<AppxSymbolPackageEnabled>False</AppxSymbolPackageEnabled>
<PackageCertificateThumbprint>C3B9A35BB185E430F381F524A644B2598DDF2500</PackageCertificateThumbprint>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
Expand Down
Binary file modified src/App/App_TemporaryKey.pfx
Binary file not shown.
31 changes: 19 additions & 12 deletions src/Lib/SignIn.Uwp/AuthorizeProvider/AuthorizeProvider.Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Runtime.InteropServices.WindowsRuntime;
Expand All @@ -17,13 +19,13 @@
using Bili.Models.Enums;
using Bili.Toolkit.Interfaces;
using Newtonsoft.Json.Linq;
using QRCoder;
using Windows.Security.Cryptography.Core;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media.Imaging;
using Windows.Web.Http.Filters;
using ZXing;
using ZXing.Common;
using static Bili.Models.App.Constants.ApiConstants;
using static Bili.Models.App.Constants.ServiceConstants;

Expand Down Expand Up @@ -229,7 +231,7 @@ internal async Task<string> GetConfirmUriAsync()
return null;
}

internal async Task<WriteableBitmap> GetQRImageAsync()
internal async Task<BitmapImage> GetQRImageAsync()
{
try
{
Expand All @@ -244,17 +246,22 @@ internal async Task<WriteableBitmap> GetQRImageAsync()
var result = await httpProvider.ParseAsync<ServerResponse<QRInfo>>(response);

_internalQRAuthCode = result.Data.AuthCode;
var barcodeWriter = new BarcodeWriter();
barcodeWriter.Format = BarcodeFormat.QR_CODE;
barcodeWriter.Options = new EncodingOptions()
var generator = new QRCodeGenerator();
var data = generator.CreateQrCode(result.Data.Url, QRCodeGenerator.ECCLevel.Q);
var code = new BitmapByteQRCode(data);
var image = code.GetGraphic(20);
using (var stream = new InMemoryRandomAccessStream())
{
Margin = 1,
Height = 200,
Width = 200,
};
using (var writer = new DataWriter(stream.GetOutputStreamAt(0)))
{
writer.WriteBytes(image);
await writer.StoreAsync();
}

var img = barcodeWriter.Write(result.Data.Url);
return img;
var bitmap = new BitmapImage();
await bitmap.SetSourceAsync(stream);
return bitmap;
}
}
catch
{
Expand Down
6 changes: 3 additions & 3 deletions src/Lib/SignIn.Uwp/SignIn.Uwp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.14</Version>
</PackageReference>
<PackageReference Include="QRCoder">
<Version>1.4.3</Version>
</PackageReference>
<PackageReference Include="QueryString.NET">
<Version>1.0.0</Version>
</PackageReference>
<PackageReference Include="ZXing.Net">
<Version>0.16.8</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Page Include="SignInDialog.xaml">
Expand Down
7 changes: 4 additions & 3 deletions src/Lib/SignIn.Uwp/SignInDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,12 @@ private async Task LoadQRCodeAsync()
{
HideQRTip();
QRLoadingRing.IsActive = true;
var imgSource = await _authorizeProvider.GetQRImageAsync();
if (imgSource != null)
var bitmapImage = await _authorizeProvider.GetQRImageAsync();
if (bitmapImage != null)
{
QRCodeImage.Source = imgSource;
QRCodeImage.Source = bitmapImage;
_authorizeProvider.StartQRLoginListener();
QRTipBlock.Visibility = Visibility.Visible;
}
else
{
Expand Down
5 changes: 3 additions & 2 deletions src/Models/Models.App/Constants/ApiConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class ApiConstants
public const string _vcBase = "https://api.vc.bilibili.com";
public const string _liveBase = "https://api.live.bilibili.com";
public const string _passBase = "https://passport.bilibili.com";
public const string _passSnmBase = "https://passport.snm0516.aisee.tv";
public const string _bangumiBase = "https://bangumi.bilibili.com";
public const string _grpcBase = "https://grpc.biliapi.net";

Expand Down Expand Up @@ -50,12 +51,12 @@ public static class Passport
/// <summary>
/// 获取登录二维码.
/// </summary>
public const string QRCode = _passBase + "/x/passport-tv-login/qrcode/auth_code";
public const string QRCode = _passSnmBase + "/x/passport-tv-login/qrcode/auth_code";

/// <summary>
/// 登录二维码轮询状态.
/// </summary>
public const string QRCodeCheck = _passBase + "/x/passport-tv-login/qrcode/poll";
public const string QRCodeCheck = _passSnmBase + "/x/passport-tv-login/qrcode/poll";

/// <summary>
/// cookie转访问令牌.
Expand Down

0 comments on commit 23706da

Please sign in to comment.