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

Commit

Permalink
修复二维码登录 (#1776)
Browse files Browse the repository at this point in the history
  • Loading branch information
Richasy authored Oct 30, 2023
1 parent 23706da commit bd5d405
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

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 Down Expand Up @@ -241,7 +239,7 @@ internal async Task<BitmapImage> GetQRImageAsync()
{ Query.LocalId, _guid },
};
var httpProvider = Locator.Instance.GetService<IHttpProvider>();
var request = await httpProvider.GetRequestMessageAsync(HttpMethod.Post, Passport.QRCode, queryParameters);
var request = await httpProvider.GetRequestMessageAsync(HttpMethod.Post, Passport.QRCode, queryParameters, RequestClientType.Login);
var response = await httpProvider.SendAsync(request);
var result = await httpProvider.ParseAsync<ServerResponse<QRInfo>>(response);

Expand Down Expand Up @@ -305,25 +303,19 @@ private async void OnQRTimerTickAsync(object sender, object e)
{
{ Query.AuthCode, _internalQRAuthCode },
{ Query.LocalId, _guid },
{ "guid", Guid.NewGuid().ToString() },
};

try
{
var httpProvider = Locator.Instance.GetService<IHttpProvider>();
var request = await httpProvider.GetRequestMessageAsync(HttpMethod.Post, Passport.QRCodeCheck, queryParameters);
var request = await httpProvider.GetRequestMessageAsync(HttpMethod.Post, Passport.QRCodeCheck, queryParameters, RequestClientType.Login);
var response = await httpProvider.SendAsync(request, _qrPollCancellationTokenSource.Token);
var result = await httpProvider.ParseAsync<ServerResponse<TokenInfo>>(response);

// 保存cookie
SaveCookie(result.Data.CookieInfo);

// 获取确认链接
var confirmUrl = await GetCookieToAccessKeyConfirmUrlAsync();

// 获取新的访问令牌
var accessKey = await GetAccessKeyAsync(confirmUrl);
result.Data.AccessToken = accessKey;

SaveAuthorizeResult(result.Data);
QRCodeStatusChanged?.Invoke(this, new Tuple<QRCodeStatus, TokenInfo>(QRCodeStatus.Success, result.Data));
}
catch (ServiceException se)
Expand All @@ -336,7 +328,7 @@ private async void OnQRTimerTickAsync(object sender, object e)
if (se.Error != null)
{
QRCodeStatus qrStatus = default;
if (se.Error.Code == 86039)
if (se.Error.Code == 86039 || se.Error.Code == 86090)
{
qrStatus = QRCodeStatus.NotConfirm;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Models/Models.App/Constants/ServiceConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public static class Keys
public const string IOSSecret = "c2ed53a74eeefe3cf99fbd01d8c9c375";
public const string WebKey = "84956560bc028eb7";
public const string WebSecret = "94aba54af9065f71de72f5508f1cd42e";
public const string LoginKey = "4409e2ce8ffd12b8";
public const string LoginSecret = "59b43e04ad6965f34319062b478f83dd";
public const string LoginKey = "27eb53fc9058f8c3";
public const string LoginSecret = "c2ed53a74eeefe3cf99fbd01d8c9c375";
}

public static class Query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ private async Task<bool> InternalSignInAsync(bool isSlientOnly = false)
if (isTokenValid)
{
isSuccess = true;
State = AuthorizeState.SignedIn;
HandleLogged();
}
else if (!isSlientOnly)
Expand Down Expand Up @@ -62,6 +63,13 @@ await _dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async
State = AuthorizeState.SignedIn;
});
}
else
{
await _dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
{
await SignOutAsync();
});
}
});
}
}
Expand Down

0 comments on commit bd5d405

Please sign in to comment.