From cef1ad3a6663c3647f79831cd3ecb44b1fc8a95d Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Thu, 1 Feb 2024 15:50:57 +0800 Subject: [PATCH] prepare combo qr login --- .../Snap.Hutao/View/Dialog/UserQRCodeDialog.xaml.cs | 8 ++++++++ .../Web/Hoyolab/Passport/ComboTokenWrapper.cs | 13 +++++++++++++ .../Snap.Hutao/Web/Hoyolab/Passport/UidGameToken.cs | 10 +++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/ComboTokenWrapper.cs diff --git a/src/Snap.Hutao/Snap.Hutao/View/Dialog/UserQRCodeDialog.xaml.cs b/src/Snap.Hutao/Snap.Hutao/View/Dialog/UserQRCodeDialog.xaml.cs index 32be4c21..d4659256 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Dialog/UserQRCodeDialog.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/View/Dialog/UserQRCodeDialog.xaml.cs @@ -145,6 +145,14 @@ internal sealed partial class UserQRCodeDialog : ContentDialog, IDisposable ArgumentNullException.ThrowIfNull(uidGameToken); return uidGameToken; } + + // only available when game id is 4 + else if (query is { ReturnCode: 0, Data: { Stat: "Confirmed", Payload.Proto: "Combo" } }) + { + ComboTokenWrapper? comboTokenWrapper = JsonSerializer.Deserialize(query.Data.Payload.Raw); + ArgumentNullException.ThrowIfNull(comboTokenWrapper); + return UidGameToken.From(comboTokenWrapper); + } else if (query.ReturnCode == (int)KnownReturnCode.QrCodeExpired) { break; diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/ComboTokenWrapper.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/ComboTokenWrapper.cs new file mode 100644 index 00000000..3b95d7df --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/ComboTokenWrapper.cs @@ -0,0 +1,13 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Web.Hoyolab.Passport; + +internal sealed class ComboTokenWrapper +{ + [JsonPropertyName("open_id")] + public string OpenId { get; set; } = default!; + + [JsonPropertyName("open_token")] + public string OpenToken { get; set; } = default!; +} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/UidGameToken.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/UidGameToken.cs index 7f2ffc47..be132edb 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/UidGameToken.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/UidGameToken.cs @@ -1,14 +1,22 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. +using Snap.Hutao.Core.Abstraction; + namespace Snap.Hutao.Web.Hoyolab.Passport; [HighQuality] -internal sealed class UidGameToken +internal sealed class UidGameToken : IMappingFrom { [JsonPropertyName("uid")] public string Uid { get; set; } = default!; [JsonPropertyName("token")] public string GameToken { get; set; } = default!; + + public static UidGameToken From(ComboTokenWrapper wrapper) => new() + { + Uid = wrapper.OpenId, + GameToken = wrapper.OpenToken, + }; }