mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
fix #720
This commit is contained in:
@@ -95,5 +95,13 @@ public class CSharpLanguageFeatureTest
|
||||
Assert.AreEqual(3, count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void RangeTrimLastOne()
|
||||
{
|
||||
int[] array = { 1, 2, 3, 4 };
|
||||
|
||||
Assert.AreEqual(3, array[..^1].Length);
|
||||
}
|
||||
|
||||
public static Guid UUID { get => Guid.NewGuid(); }
|
||||
}
|
||||
@@ -21,7 +21,7 @@
|
||||
<Button
|
||||
Margin="16"
|
||||
HorizontalAlignment="Right"
|
||||
Click="CookieButtonClick"
|
||||
Command="{x:Bind HandleCurrentCookieCommand}"
|
||||
Content="{shcm:ResourceString Name=ViewPageLoginMihoyoUserLoggedInAction}"/>
|
||||
<WebView2 x:Name="WebView" Grid.Row="2"/>
|
||||
</Grid>
|
||||
|
||||
@@ -70,7 +70,8 @@ internal sealed partial class LoginHoyoverseUserPage : Microsoft.UI.Xaml.Control
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleCurrentCookieAsync(CancellationToken token = default)
|
||||
[Command("HandleCurrentCookieCommand")]
|
||||
private async Task HandleCurrentCookieAsync()
|
||||
{
|
||||
CoreWebView2CookieManager manager = WebView.CoreWebView2.CookieManager;
|
||||
IReadOnlyList<CoreWebView2Cookie> cookies = await manager.GetCookiesAsync("https://account.hoyoverse.com");
|
||||
@@ -78,13 +79,13 @@ internal sealed partial class LoginHoyoverseUserPage : Microsoft.UI.Xaml.Control
|
||||
IInfoBarService infoBarService = Ioc.Default.GetRequiredService<IInfoBarService>();
|
||||
|
||||
Cookie loginTicketCookie = Cookie.FromCoreWebView2Cookies(cookies);
|
||||
string uid = await GetUidFromCookieAsync(Ioc.Default, loginTicketCookie, token).ConfigureAwait(false);
|
||||
string uid = await GetUidFromCookieAsync(Ioc.Default, loginTicketCookie).ConfigureAwait(false);
|
||||
loginTicketCookie[Cookie.LOGIN_UID] = uid;
|
||||
|
||||
// 使用 loginTicket 获取 stoken
|
||||
Response<ListWrapper<NameToken>> multiTokenResponse = await Ioc.Default
|
||||
.GetRequiredService<AuthClient>()
|
||||
.GetMultiTokenByLoginTicketAsync(loginTicketCookie, true, token)
|
||||
.GetMultiTokenByLoginTicketAsync(loginTicketCookie, true)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (!multiTokenResponse.IsOk())
|
||||
@@ -109,11 +110,6 @@ internal sealed partial class LoginHoyoverseUserPage : Microsoft.UI.Xaml.Control
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private void CookieButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
HandleCurrentCookieAsync().SafeForget();
|
||||
}
|
||||
|
||||
private sealed class WebApiResponse<TData>
|
||||
{
|
||||
[JsonPropertyName("code")]
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<Button
|
||||
Margin="16"
|
||||
HorizontalAlignment="Right"
|
||||
Click="CookieButtonClick"
|
||||
Command="{x:Bind HandleCurrentCookieCommand, Mode=OneWay}"
|
||||
Content="{shcm:ResourceString Name=ViewPageLoginMihoyoUserLoggedInAction}"/>
|
||||
<WebView2 x:Name="WebView" Grid.Row="2"/>
|
||||
</Grid>
|
||||
|
||||
@@ -49,7 +49,8 @@ internal sealed partial class LoginMihoyoUserPage : Microsoft.UI.Xaml.Controls.P
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleCurrentCookieAsync(CancellationToken token = default)
|
||||
[Command("HandleCurrentCookieCommand")]
|
||||
private async Task HandleCurrentCookieAsync()
|
||||
{
|
||||
CoreWebView2CookieManager manager = WebView.CoreWebView2.CookieManager;
|
||||
IReadOnlyList<CoreWebView2Cookie> cookies = await manager.GetCookiesAsync("https://user.mihoyo.com");
|
||||
@@ -57,7 +58,7 @@ internal sealed partial class LoginMihoyoUserPage : Microsoft.UI.Xaml.Controls.P
|
||||
Cookie loginTicketCookie = Cookie.FromCoreWebView2Cookies(cookies);
|
||||
Response<ListWrapper<NameToken>> multiTokenResponse = await Ioc.Default
|
||||
.GetRequiredService<AuthClient>()
|
||||
.GetMultiTokenByLoginTicketAsync(loginTicketCookie, false, token)
|
||||
.GetMultiTokenByLoginTicketAsync(loginTicketCookie, false)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (!multiTokenResponse.IsOk())
|
||||
@@ -71,7 +72,7 @@ internal sealed partial class LoginMihoyoUserPage : Microsoft.UI.Xaml.Controls.P
|
||||
|
||||
Response<LoginResult> loginResultResponse = await Ioc.Default
|
||||
.GetRequiredService<PassportClient>()
|
||||
.LoginBySTokenAsync(stokenV1, token)
|
||||
.LoginBySTokenAsync(stokenV1)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (!loginResultResponse.IsOk())
|
||||
@@ -92,9 +93,4 @@ internal sealed partial class LoginMihoyoUserPage : Microsoft.UI.Xaml.Controls.P
|
||||
.HandleUserOptionResultAsync(result, nickname)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private void CookieButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
HandleCurrentCookieAsync().SafeForget();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ internal sealed partial class PassportClient
|
||||
/// <param name="token">取消令牌</param>
|
||||
/// <returns>登录数据</returns>
|
||||
[ApiInformation(Salt = SaltType.PROD)]
|
||||
public async Task<Response<LoginResult>> LoginBySTokenAsync(Cookie stokenV1, CancellationToken token)
|
||||
public async Task<Response<LoginResult>> LoginBySTokenAsync(Cookie stokenV1, CancellationToken token = default)
|
||||
{
|
||||
HttpResponseMessage message = await httpClient
|
||||
.SetHeader("Cookie", stokenV1.ToString())
|
||||
|
||||
@@ -51,7 +51,7 @@ internal sealed partial class AuthClient
|
||||
/// <param name="isOversea">是否为国际服</param>
|
||||
/// <param name="token">取消令牌</param>
|
||||
/// <returns>包含token的字典</returns>
|
||||
public async Task<Response<ListWrapper<NameToken>>> GetMultiTokenByLoginTicketAsync(Cookie cookie, bool isOversea, CancellationToken token)
|
||||
public async Task<Response<ListWrapper<NameToken>>> GetMultiTokenByLoginTicketAsync(Cookie cookie, bool isOversea, CancellationToken token = default)
|
||||
{
|
||||
string loginTicket = cookie[Cookie.LOGIN_TICKET];
|
||||
string loginUid = cookie[Cookie.LOGIN_UID];
|
||||
|
||||
Reference in New Issue
Block a user