mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
refactor user initialization
This commit is contained in:
@@ -75,18 +75,18 @@ internal sealed class User : ObservableObject
|
||||
set => inner.CookieToken = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="EntityUser.Ltoken"/>
|
||||
public Cookie? Ltoken
|
||||
/// <inheritdoc cref="EntityUser.LToken"/>
|
||||
public Cookie? LToken
|
||||
{
|
||||
get => inner.Ltoken;
|
||||
set => inner.Ltoken = value;
|
||||
get => inner.LToken;
|
||||
set => inner.LToken = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="EntityUser.Stoken"/>
|
||||
public Cookie? Stoken
|
||||
/// <inheritdoc cref="EntityUser.SToken"/>
|
||||
public Cookie? SToken
|
||||
{
|
||||
get => inner.Stoken;
|
||||
set => inner.Stoken = value;
|
||||
get => inner.SToken;
|
||||
set => inner.SToken = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -145,93 +145,127 @@ internal sealed class User : ObservableObject
|
||||
{
|
||||
if (isInitialized)
|
||||
{
|
||||
// Prevent multiple initialization.
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Stoken == null)
|
||||
if (SToken == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
using (IServiceScope scope = Ioc.Default.CreateScope())
|
||||
{
|
||||
Response<UserFullInfoWrapper> response = await scope.ServiceProvider
|
||||
.GetRequiredService<UserClient>()
|
||||
.GetUserFullInfoAsync(Entity, token)
|
||||
.ConfigureAwait(false);
|
||||
UserInfo = response.Data?.UserInfo;
|
||||
|
||||
// 自动填充 Ltoken
|
||||
if (Ltoken == null)
|
||||
if (!await TrySetUserInfoAsync(scope.ServiceProvider, token).ConfigureAwait(false))
|
||||
{
|
||||
Response<LtokenWrapper> ltokenResponse = await scope.ServiceProvider
|
||||
.GetRequiredService<PassportClient2>()
|
||||
.GetLtokenBySTokenAsync(Entity, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (ltokenResponse.IsOk())
|
||||
{
|
||||
Cookie ltokenCookie = Cookie.Parse($"ltuid={Entity.Aid};ltoken={ltokenResponse.Data.Ltoken}");
|
||||
Entity.Ltoken = ltokenCookie;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Response<ActionTicketWrapper> actionTicketResponse = await scope.ServiceProvider
|
||||
if (!await TrySetLTokenAsync(scope.ServiceProvider, token).ConfigureAwait(false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!await TrySetUserGameRolesAsync(scope.ServiceProvider, token).ConfigureAwait(false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (await TrySetCookieTokenAsync(scope.ServiceProvider, token).ConfigureAwait(false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
SelectedUserGameRole = UserGameRoles.FirstOrFirstOrDefault(role => role.IsChosen);
|
||||
return isInitialized = true;
|
||||
}
|
||||
|
||||
private async Task<bool> TrySetLTokenAsync(IServiceProvider provider, CancellationToken token)
|
||||
{
|
||||
if (LToken != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Response<LtokenWrapper> lTokenResponse = await provider
|
||||
.GetRequiredService<PassportClient2>()
|
||||
.GetLTokenBySTokenAsync(Entity, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (lTokenResponse.IsOk())
|
||||
{
|
||||
LToken = Cookie.Parse($"{Cookie.LTUID}={Entity.Aid};{Cookie.LTOKEN}={lTokenResponse.Data.Ltoken}");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<bool> TrySetCookieTokenAsync(IServiceProvider provider, CancellationToken token)
|
||||
{
|
||||
if (CookieToken != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Response<UidCookieToken> cookieTokenResponse = await provider
|
||||
.GetRequiredService<PassportClient2>()
|
||||
.GetCookieAccountInfoBySTokenAsync(Entity, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (cookieTokenResponse.IsOk())
|
||||
{
|
||||
CookieToken = Cookie.Parse($"{Cookie.ACCOUNT_ID}={Entity.Aid};{Cookie.COOKIE_TOKEN}={cookieTokenResponse.Data.CookieToken}");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<bool> TrySetUserInfoAsync(IServiceProvider provider, CancellationToken token)
|
||||
{
|
||||
Response<UserFullInfoWrapper> response = await provider
|
||||
.GetRequiredService<UserClient>()
|
||||
.GetUserFullInfoAsync(Entity, token)
|
||||
.ConfigureAwait(false);
|
||||
UserInfo = response.Data?.UserInfo;
|
||||
return UserInfo != null;
|
||||
}
|
||||
|
||||
private async Task<bool> TrySetUserGameRolesAsync(IServiceProvider provider, CancellationToken token)
|
||||
{
|
||||
Response<ActionTicketWrapper> actionTicketResponse = await provider
|
||||
.GetRequiredService<AuthClient>()
|
||||
.GetActionTicketByStokenAsync("game_role", Entity)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (actionTicketResponse.IsOk())
|
||||
if (actionTicketResponse.IsOk())
|
||||
{
|
||||
string actionTicket = actionTicketResponse.Data.Ticket;
|
||||
|
||||
Response<ListWrapper<UserGameRole>> userGameRolesResponse = await provider
|
||||
.GetRequiredService<BindingClient>()
|
||||
.GetUserGameRolesByActionTicketAsync(actionTicket, Entity, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (userGameRolesResponse.IsOk())
|
||||
{
|
||||
string actionTicket = actionTicketResponse.Data.Ticket;
|
||||
|
||||
Response<ListWrapper<UserGameRole>> userGameRolesResponse = await scope.ServiceProvider
|
||||
.GetRequiredService<BindingClient>()
|
||||
.GetUserGameRolesByActionTicketAsync(actionTicket, Entity, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (userGameRolesResponse.IsOk())
|
||||
{
|
||||
UserGameRoles = userGameRolesResponse.Data.List;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
UserGameRoles = userGameRolesResponse.Data.List;
|
||||
return UserGameRoles.Any();
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 自动填充 CookieToken
|
||||
if (CookieToken == null)
|
||||
{
|
||||
Response<UidCookieToken> cookieTokenResponse = await scope.ServiceProvider
|
||||
.GetRequiredService<PassportClient2>()
|
||||
.GetCookieAccountInfoBySTokenAsync(Entity, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (cookieTokenResponse.IsOk())
|
||||
{
|
||||
Cookie cookieTokenCookie = Cookie.Parse($"account_id={Entity.Aid};cookie_token={cookieTokenResponse.Data.CookieToken}");
|
||||
Entity.CookieToken = cookieTokenCookie;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SelectedUserGameRole = UserGameRoles.FirstOrFirstOrDefault(role => role.IsChosen);
|
||||
|
||||
isInitialized = true;
|
||||
|
||||
return UserInfo != null && UserGameRoles.Any();
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,11 +20,11 @@ internal sealed class UserConfiguration : IEntityTypeConfiguration<User>
|
||||
.HasColumnType("TEXT")
|
||||
.HasConversion(e => e!.ToString(), e => Cookie.Parse(e));
|
||||
|
||||
builder.Property(e => e.Ltoken)
|
||||
builder.Property(e => e.LToken)
|
||||
.HasColumnType("TEXT")
|
||||
.HasConversion(e => e!.ToString(), e => Cookie.Parse(e));
|
||||
|
||||
builder.Property(e => e.Stoken)
|
||||
builder.Property(e => e.SToken)
|
||||
.HasColumnType("TEXT")
|
||||
.HasConversion(e => e!.ToString(), e => Cookie.Parse(e));
|
||||
}
|
||||
|
||||
@@ -43,14 +43,16 @@ internal sealed class User : ISelectable
|
||||
public Cookie? CookieToken { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户的 Ltoken
|
||||
/// 用户的 LToken
|
||||
/// </summary>
|
||||
public Cookie? Ltoken { get; set; }
|
||||
[Column("Ltoken")] // DO NOT RENAME
|
||||
public Cookie? LToken { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户的 Stoken V2
|
||||
/// 用户的 SToken V2
|
||||
/// </summary>
|
||||
public Cookie? Stoken { get; set; }
|
||||
[Column("Stoken")] // DO NOT RENAME
|
||||
public Cookie? SToken { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为国际服账号
|
||||
@@ -68,6 +70,6 @@ internal sealed class User : ISelectable
|
||||
_ = cookie.TryGetAsLtoken(out Cookie? ltoken);
|
||||
_ = cookie.TryGetAsCookieToken(out Cookie? cookieToken);
|
||||
|
||||
return new() { Stoken = stoken, Ltoken = ltoken, CookieToken = cookieToken };
|
||||
return new() { SToken = stoken, LToken = ltoken, CookieToken = cookieToken };
|
||||
}
|
||||
}
|
||||
@@ -210,8 +210,8 @@ internal class UserService : IUserService
|
||||
|
||||
if (cookie.TryGetAsStoken(out Cookie? stoken))
|
||||
{
|
||||
user.Stoken = stoken;
|
||||
user.Ltoken = cookie.TryGetAsLtoken(out Cookie? ltoken) ? ltoken : user.Ltoken;
|
||||
user.SToken = stoken;
|
||||
user.LToken = cookie.TryGetAsLtoken(out Cookie? ltoken) ? ltoken : user.LToken;
|
||||
user.CookieToken = cookie.TryGetAsCookieToken(out Cookie? cookieToken) ? cookieToken : user.CookieToken;
|
||||
|
||||
await appDbContext.Users.UpdateAndSaveAsync(user.Entity).ConfigureAwait(false);
|
||||
|
||||
@@ -49,7 +49,7 @@ internal sealed partial class AdoptCalculatorDialog : ContentDialog
|
||||
return;
|
||||
}
|
||||
|
||||
coreWebView2.SetCookie(user.CookieToken, user.Ltoken, null).SetMobileUserAgent();
|
||||
coreWebView2.SetCookie(user.CookieToken, user.LToken, null).SetMobileUserAgent();
|
||||
jsInterface = new(coreWebView2, scope.ServiceProvider);
|
||||
jsInterface.ClosePageRequested += OnClosePageRequested;
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ internal sealed partial class CommunityGameRecordDialog : ContentDialog
|
||||
return;
|
||||
}
|
||||
|
||||
coreWebView2.SetCookie(user.CookieToken, user.Ltoken, null).SetMobileUserAgent();
|
||||
coreWebView2.SetCookie(user.CookieToken, user.LToken, null).SetMobileUserAgent();
|
||||
jsInterface = new(coreWebView2, scope.ServiceProvider);
|
||||
jsInterface.ClosePageRequested += OnClosePageRequested;
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ internal sealed partial class DailyNoteVerificationDialog : ContentDialog
|
||||
CoreWebView2 coreWebView2 = WebView.CoreWebView2;
|
||||
|
||||
Model.Entity.User user = userAndUid.User;
|
||||
coreWebView2.SetCookie(user.CookieToken, user.Ltoken, null).SetMobileUserAgent();
|
||||
coreWebView2.SetCookie(user.CookieToken, user.LToken, null).SetMobileUserAgent();
|
||||
jsInterface = new(coreWebView2, scope.ServiceProvider);
|
||||
jsInterface.ClosePageRequested += OnClosePageRequested;
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ internal sealed partial class SignInWebViewDialog : ContentDialog
|
||||
return;
|
||||
}
|
||||
|
||||
coreWebView2.SetCookie(user.CookieToken, user.Ltoken, null).SetMobileUserAgent();
|
||||
coreWebView2.SetCookie(user.CookieToken, user.LToken, null).SetMobileUserAgent();
|
||||
signInJsInterface = new(coreWebView2, scope.ServiceProvider);
|
||||
coreWebView2.Navigate("https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?act_id=e202009291139501");
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Control;
|
||||
using Snap.Hutao.ViewModel;
|
||||
using Snap.Hutao.ViewModel.SpiralAbyss;
|
||||
|
||||
namespace Snap.Hutao.View.Page;
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Binding;
|
||||
using Snap.Hutao.Model.Intrinsic;
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
|
||||
namespace Snap.Hutao.Model.Binding.SpiralAbyss;
|
||||
namespace Snap.Hutao.ViewModel.SpiralAbyss;
|
||||
|
||||
/// <summary>
|
||||
/// 角色视图
|
||||
@@ -16,11 +17,11 @@ internal class AvatarView : INameIconSide
|
||||
/// 构造一个新的角色视图
|
||||
/// </summary>
|
||||
/// <param name="metaAvatar">角色</param>
|
||||
public AvatarView(Metadata.Avatar.Avatar metaAvatar)
|
||||
public AvatarView(Model.Metadata.Avatar.Avatar metaAvatar)
|
||||
{
|
||||
Name = metaAvatar.Name;
|
||||
Icon = Metadata.Converter.AvatarIconConverter.IconNameToUri(metaAvatar.Icon);
|
||||
SideIcon = Metadata.Converter.AvatarIconConverter.IconNameToUri(metaAvatar.SideIcon);
|
||||
Icon = Model.Metadata.Converter.AvatarIconConverter.IconNameToUri(metaAvatar.Icon);
|
||||
SideIcon = Model.Metadata.Converter.AvatarIconConverter.IconNameToUri(metaAvatar.SideIcon);
|
||||
Quality = metaAvatar.Quality;
|
||||
}
|
||||
|
||||
@@ -29,7 +30,7 @@ internal class AvatarView : INameIconSide
|
||||
/// </summary>
|
||||
/// <param name="avatarId">角色Id</param>
|
||||
/// <param name="idAvatarMap">Id角色映射</param>
|
||||
public AvatarView(AvatarId avatarId, Dictionary<AvatarId, Metadata.Avatar.Avatar> idAvatarMap)
|
||||
public AvatarView(AvatarId avatarId, Dictionary<AvatarId, Model.Metadata.Avatar.Avatar> idAvatarMap)
|
||||
: this(idAvatarMap[avatarId])
|
||||
{
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord.SpiralAbyss;
|
||||
|
||||
namespace Snap.Hutao.Model.Binding.SpiralAbyss;
|
||||
namespace Snap.Hutao.ViewModel.SpiralAbyss;
|
||||
|
||||
/// <summary>
|
||||
/// 上下半视图
|
||||
@@ -17,7 +17,7 @@ internal sealed class BattleView
|
||||
/// </summary>
|
||||
/// <param name="battle">战斗</param>
|
||||
/// <param name="idAvatarMap">Id角色映射</param>
|
||||
public BattleView(Battle battle, Dictionary<AvatarId, Metadata.Avatar.Avatar> idAvatarMap)
|
||||
public BattleView(Battle battle, Dictionary<AvatarId, Model.Metadata.Avatar.Avatar> idAvatarMap)
|
||||
{
|
||||
Time = DateTimeOffset.FromUnixTimeSeconds(battle.Timestamp).ToLocalTime().ToString("yyyy.MM.dd HH:mm:ss");
|
||||
Avatars = battle.Avatars.Select(a => new AvatarView(a.Id, idAvatarMap)).ToList();
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
|
||||
namespace Snap.Hutao.Model.Binding.SpiralAbyss;
|
||||
namespace Snap.Hutao.ViewModel.SpiralAbyss;
|
||||
|
||||
/// <summary>
|
||||
/// 层视图
|
||||
@@ -16,7 +16,7 @@ internal sealed class FloorView
|
||||
/// </summary>
|
||||
/// <param name="floor">层</param>
|
||||
/// <param name="idAvatarMap">Id角色映射</param>
|
||||
public FloorView(Web.Hoyolab.Takumi.GameRecord.SpiralAbyss.Floor floor, Dictionary<AvatarId, Metadata.Avatar.Avatar> idAvatarMap)
|
||||
public FloorView(Web.Hoyolab.Takumi.GameRecord.SpiralAbyss.Floor floor, Dictionary<AvatarId, Model.Metadata.Avatar.Avatar> idAvatarMap)
|
||||
{
|
||||
Index = string.Format(SH.ModelBindingHutaoComplexRankFloor, floor.Index);
|
||||
SettleTime = $"{DateTimeOffset.FromUnixTimeSeconds(floor.SettleTime).ToLocalTime():yyyy.MM.dd HH:mm:ss}";
|
||||
@@ -4,7 +4,7 @@
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord.SpiralAbyss;
|
||||
|
||||
namespace Snap.Hutao.Model.Binding.SpiralAbyss;
|
||||
namespace Snap.Hutao.ViewModel.SpiralAbyss;
|
||||
|
||||
/// <summary>
|
||||
/// 间视图
|
||||
@@ -17,7 +17,7 @@ internal sealed class LevelView
|
||||
/// </summary>
|
||||
/// <param name="level">间</param>
|
||||
/// <param name="idAvatarMap">Id角色映射</param>
|
||||
public LevelView(Level level, Dictionary<AvatarId, Metadata.Avatar.Avatar> idAvatarMap)
|
||||
public LevelView(Level level, Dictionary<AvatarId, Model.Metadata.Avatar.Avatar> idAvatarMap)
|
||||
{
|
||||
Index = string.Format(SH.ModelBindingHutaoComplexRankLevel, level.Index);
|
||||
Star = level.Star;
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
|
||||
namespace Snap.Hutao.Model.Binding.SpiralAbyss;
|
||||
namespace Snap.Hutao.ViewModel.SpiralAbyss;
|
||||
|
||||
/// <summary>
|
||||
/// 排行角色
|
||||
@@ -17,7 +17,7 @@ internal sealed class RankAvatar : AvatarView
|
||||
/// <param name="value">值</param>
|
||||
/// <param name="avatarId">角色Id</param>
|
||||
/// <param name="idAvatarMap">Id角色映射</param>
|
||||
public RankAvatar(int value, AvatarId avatarId, Dictionary<AvatarId, Metadata.Avatar.Avatar> idAvatarMap)
|
||||
public RankAvatar(int value, AvatarId avatarId, Dictionary<AvatarId, Model.Metadata.Avatar.Avatar> idAvatarMap)
|
||||
: base(avatarId, idAvatarMap)
|
||||
{
|
||||
Value = value;
|
||||
@@ -5,7 +5,6 @@ using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Snap.Hutao.Message;
|
||||
using Snap.Hutao.Model.Binding.SpiralAbyss;
|
||||
using Snap.Hutao.Model.Binding.User;
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Model.Metadata;
|
||||
@@ -18,7 +17,7 @@ using Snap.Hutao.Web.Hutao;
|
||||
using Snap.Hutao.Web.Hutao.Model.Post;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Snap.Hutao.ViewModel;
|
||||
namespace Snap.Hutao.ViewModel.SpiralAbyss;
|
||||
|
||||
/// <summary>
|
||||
/// 深渊记录视图模型
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
|
||||
namespace Snap.Hutao.Model.Binding.SpiralAbyss;
|
||||
namespace Snap.Hutao.ViewModel.SpiralAbyss;
|
||||
|
||||
/// <summary>
|
||||
/// 深渊视图
|
||||
@@ -16,7 +16,7 @@ internal sealed class SpiralAbyssView
|
||||
/// </summary>
|
||||
/// <param name="spiralAbyss">深渊信息</param>
|
||||
/// <param name="idAvatarMap">Id角色映射</param>
|
||||
public SpiralAbyssView(Web.Hoyolab.Takumi.GameRecord.SpiralAbyss.SpiralAbyss spiralAbyss, Dictionary<AvatarId, Metadata.Avatar.Avatar> idAvatarMap)
|
||||
public SpiralAbyssView(Web.Hoyolab.Takumi.GameRecord.SpiralAbyss.SpiralAbyss spiralAbyss, Dictionary<AvatarId, Model.Metadata.Avatar.Avatar> idAvatarMap)
|
||||
{
|
||||
Schedule = string.Format(SH.ModelEntitySpiralAbyssScheduleFormat, spiralAbyss.ScheduleId);
|
||||
TotalBattleTimes = spiralAbyss.TotalBattleTimes;
|
||||
@@ -194,10 +194,10 @@ internal sealed class UserViewModel : ObservableObject
|
||||
try
|
||||
{
|
||||
string cookieString = new StringBuilder()
|
||||
.Append(user!.Stoken)
|
||||
.AppendIf(user.Stoken != null, ';')
|
||||
.Append(user.Ltoken)
|
||||
.AppendIf(user.Ltoken != null, ';')
|
||||
.Append(user!.SToken)
|
||||
.AppendIf(user.SToken != null, ';')
|
||||
.Append(user.LToken)
|
||||
.AppendIf(user.LToken != null, ';')
|
||||
.Append(user.CookieToken)
|
||||
.ToString();
|
||||
|
||||
|
||||
@@ -105,8 +105,8 @@ internal class MiHoYoJSInterface
|
||||
{
|
||||
Data = new()
|
||||
{
|
||||
[Cookie.LTUID] = user.Ltoken![Cookie.LTUID],
|
||||
[Cookie.LTOKEN] = user.Ltoken[Cookie.LTOKEN],
|
||||
[Cookie.LTUID] = user.LToken![Cookie.LTUID],
|
||||
[Cookie.LTOKEN] = user.LToken[Cookie.LTOKEN],
|
||||
[Cookie.LOGIN_TICKET] = string.Empty,
|
||||
},
|
||||
};
|
||||
@@ -203,7 +203,7 @@ internal class MiHoYoJSInterface
|
||||
}
|
||||
|
||||
await ThreadHelper.SwitchToMainThreadAsync();
|
||||
webView.SetCookie(user.CookieToken, user.Ltoken);
|
||||
webView.SetCookie(user.CookieToken, user.LToken);
|
||||
return new() { Data = new() { [Cookie.COOKIE_TOKEN] = user.CookieToken![Cookie.COOKIE_TOKEN] } };
|
||||
}
|
||||
|
||||
|
||||
@@ -43,11 +43,11 @@ internal sealed class AccountClient
|
||||
/// <param name="data">提交数据</param>
|
||||
/// <param name="token">取消令牌</param>
|
||||
/// <returns>用户角色信息</returns>
|
||||
[ApiInformation(Cookie = CookieType.Stoken, Salt = SaltType.K2)]
|
||||
[ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.K2)]
|
||||
public async Task<Response<GameAuthKey>> GenerateAuthenticationKeyAsync(User user, GenAuthKeyData data, CancellationToken token = default)
|
||||
{
|
||||
Response<GameAuthKey>? resp = await httpClient
|
||||
.SetUser(user, CookieType.Stoken)
|
||||
.SetUser(user, CookieType.SToken)
|
||||
.SetReferer(ApiEndpoints.AppMihoyoReferer)
|
||||
.UseDynamicSecret(DynamicSecretVersion.Gen1, SaltType.K2, false)
|
||||
.TryCatchPostAsJsonAsync<GenAuthKeyData, Response<GameAuthKey>>(ApiEndpoints.AppAuthGenAuthKey, data, options, logger, token)
|
||||
|
||||
@@ -40,11 +40,11 @@ internal sealed class UserClient
|
||||
/// <param name="user">用户</param>
|
||||
/// <param name="token">取消令牌</param>
|
||||
/// <returns>详细信息</returns>
|
||||
[ApiInformation(Cookie = CookieType.Stoken, Salt = SaltType.K2)]
|
||||
[ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.K2)]
|
||||
public async Task<Response<UserFullInfoWrapper>> GetUserFullInfoAsync(Model.Entity.User user, CancellationToken token = default)
|
||||
{
|
||||
Response<UserFullInfoWrapper>? resp = await httpClient
|
||||
.SetUser(user, CookieType.Stoken)
|
||||
.SetUser(user, CookieType.SToken)
|
||||
.SetReferer(ApiEndpoints.BbsReferer)
|
||||
.UseDynamicSecret(DynamicSecretVersion.Gen1, SaltType.K2, true)
|
||||
.TryCatchGetFromJsonAsync<Response<UserFullInfoWrapper>>(ApiEndpoints.UserFullInfoQuery(user.Aid!), options, logger, token)
|
||||
|
||||
@@ -23,15 +23,15 @@ internal enum CookieType
|
||||
/// <summary>
|
||||
/// 需要 Ltoken
|
||||
/// </summary>
|
||||
Ltoken = 0B0010,
|
||||
LToken = 0B0010,
|
||||
|
||||
/// <summary>
|
||||
/// 需要 CookieToken 与 Ltoken
|
||||
/// 需要 CookieToken 与 LToken
|
||||
/// </summary>
|
||||
Cookie = CookieToken | Ltoken,
|
||||
Cookie = CookieToken | LToken,
|
||||
|
||||
/// <summary>
|
||||
/// 需要 Stoken
|
||||
/// 需要 SToken
|
||||
/// </summary>
|
||||
Stoken = 0B0100,
|
||||
SToken = 0B0100,
|
||||
}
|
||||
@@ -30,14 +30,14 @@ internal static class HoyolabHttpClientExtension
|
||||
stringBuilder.Append(user.CookieToken).AppendIf(user.CookieToken != null, ';');
|
||||
}
|
||||
|
||||
if (cookie.HasFlag(CookieType.Ltoken))
|
||||
if (cookie.HasFlag(CookieType.LToken))
|
||||
{
|
||||
stringBuilder.Append(user.Ltoken).AppendIf(user.Ltoken != null, ';');
|
||||
stringBuilder.Append(user.LToken).AppendIf(user.LToken != null, ';');
|
||||
}
|
||||
|
||||
if (cookie.HasFlag(CookieType.Stoken))
|
||||
if (cookie.HasFlag(CookieType.SToken))
|
||||
{
|
||||
stringBuilder.Append(user.Stoken).AppendIf(user.Stoken != null, ';');
|
||||
stringBuilder.Append(user.SToken).AppendIf(user.SToken != null, ';');
|
||||
}
|
||||
|
||||
string result = stringBuilder.ToString();
|
||||
|
||||
@@ -39,11 +39,11 @@ internal sealed class PassportClient
|
||||
/// <param name="user">用户</param>
|
||||
/// <param name="token">取消令牌</param>
|
||||
/// <returns>验证信息</returns>
|
||||
[ApiInformation(Cookie = CookieType.Ltoken)]
|
||||
[ApiInformation(Cookie = CookieType.LToken)]
|
||||
public async Task<Response<UserInfoWrapper>> VerifyLtokenAsync(User user, CancellationToken token)
|
||||
{
|
||||
Response<UserInfoWrapper>? response = await httpClient
|
||||
.SetUser(user, CookieType.Ltoken)
|
||||
.SetUser(user, CookieType.LToken)
|
||||
.TryCatchPostAsJsonAsync<Timestamp, Response<UserInfoWrapper>>(ApiEndpoints.AccountVerifyLtoken, new(), options, logger, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
|
||||
@@ -64,11 +64,11 @@ internal sealed class PassportClient2
|
||||
/// <param name="user">用户</param>
|
||||
/// <param name="token">取消令牌</param>
|
||||
/// <returns>cookie token</returns>
|
||||
[ApiInformation(Cookie = CookieType.Stoken, Salt = SaltType.PROD)]
|
||||
[ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.PROD)]
|
||||
public async Task<Response<UidCookieToken>> GetCookieAccountInfoBySTokenAsync(User user, CancellationToken token = default)
|
||||
{
|
||||
Response<UidCookieToken>? resp = await httpClient
|
||||
.SetUser(user, CookieType.Stoken)
|
||||
.SetUser(user, CookieType.SToken)
|
||||
.UseDynamicSecret(DynamicSecretVersion.Gen2, SaltType.PROD, true)
|
||||
.TryCatchGetFromJsonAsync<Response<UidCookieToken>>(ApiEndpoints.AccountGetCookieTokenBySToken, options, logger, token)
|
||||
.ConfigureAwait(false);
|
||||
@@ -82,11 +82,11 @@ internal sealed class PassportClient2
|
||||
/// <param name="user">用户</param>
|
||||
/// <param name="token">取消令牌</param>
|
||||
/// <returns>uid 与 cookie token</returns>
|
||||
[ApiInformation(Cookie = CookieType.Stoken, Salt = SaltType.PROD)]
|
||||
public async Task<Response<LtokenWrapper>> GetLtokenBySTokenAsync(User user, CancellationToken token)
|
||||
[ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.PROD)]
|
||||
public async Task<Response<LtokenWrapper>> GetLTokenBySTokenAsync(User user, CancellationToken token)
|
||||
{
|
||||
Response<LtokenWrapper>? resp = await httpClient
|
||||
.SetUser(user, CookieType.Stoken)
|
||||
.SetUser(user, CookieType.SToken)
|
||||
.UseDynamicSecret(DynamicSecretVersion.Gen2, SaltType.PROD, true)
|
||||
.TryCatchGetFromJsonAsync<Response<LtokenWrapper>>(ApiEndpoints.AccountGetLtokenByStoken, options, logger, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
@@ -42,13 +42,13 @@ internal sealed class AuthClient
|
||||
/// <param name="action">操作</param>
|
||||
/// <param name="user">用户</param>
|
||||
/// <returns>操作凭证</returns>
|
||||
[ApiInformation(Cookie = CookieType.Stoken, Salt = SaltType.K2)]
|
||||
[ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.K2)]
|
||||
public async Task<Response<ActionTicketWrapper>> GetActionTicketByStokenAsync(string action, User user)
|
||||
{
|
||||
Response<ActionTicketWrapper>? resp = await httpClient
|
||||
.SetUser(user, CookieType.Stoken)
|
||||
.SetUser(user, CookieType.SToken)
|
||||
.UseDynamicSecret(DynamicSecretVersion.Gen1, SaltType.K2, true)
|
||||
.TryCatchGetFromJsonAsync<Response<ActionTicketWrapper>>(ApiEndpoints.AuthActionTicket(action, user.Stoken?[Cookie.STOKEN] ?? string.Empty, user.Aid!), options, logger)
|
||||
.TryCatchGetFromJsonAsync<Response<ActionTicketWrapper>>(ApiEndpoints.AuthActionTicket(action, user.SToken?[Cookie.STOKEN] ?? string.Empty, user.Aid!), options, logger)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return Response.Response.DefaultIfNull(resp);
|
||||
|
||||
@@ -40,13 +40,13 @@ internal sealed class BindingClient
|
||||
/// <param name="user">用户</param>
|
||||
/// <param name="token">取消令牌</param>
|
||||
/// <returns>用户角色信息</returns>
|
||||
[ApiInformation(Cookie = CookieType.Ltoken)]
|
||||
[ApiInformation(Cookie = CookieType.LToken)]
|
||||
public async Task<Response<ListWrapper<UserGameRole>>> GetUserGameRolesByActionTicketAsync(string actionTicket, User user, CancellationToken token = default)
|
||||
{
|
||||
string url = ApiEndpoints.UserGameRolesByActionTicket(actionTicket);
|
||||
|
||||
Response<ListWrapper<UserGameRole>>? resp = await httpClient
|
||||
.SetUser(user, CookieType.Ltoken)
|
||||
.SetUser(user, CookieType.LToken)
|
||||
.TryCatchGetFromJsonAsync<Response<ListWrapper<UserGameRole>>>(url, options, logger, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
|
||||
@@ -41,11 +41,11 @@ internal sealed class BindingClient2
|
||||
/// <param name="user">用户</param>
|
||||
/// <param name="token">取消令牌</param>
|
||||
/// <returns>用户角色信息</returns>
|
||||
[ApiInformation(Cookie = CookieType.Stoken, Salt = SaltType.LK2)]
|
||||
[ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.LK2)]
|
||||
public async Task<List<UserGameRole>> GetUserGameRolesByStokenAsync(User user, CancellationToken token = default)
|
||||
{
|
||||
Response<ListWrapper<UserGameRole>>? resp = await httpClient
|
||||
.SetUser(user, CookieType.Stoken)
|
||||
.SetUser(user, CookieType.SToken)
|
||||
.UseDynamicSecret(DynamicSecretVersion.Gen1, SaltType.LK2, true)
|
||||
.TryCatchGetFromJsonAsync<Response<ListWrapper<UserGameRole>>>(ApiEndpoints.UserGameRolesByStoken, options, logger, token)
|
||||
.ConfigureAwait(false);
|
||||
@@ -61,11 +61,11 @@ internal sealed class BindingClient2
|
||||
/// <param name="data">提交数据</param>
|
||||
/// <param name="token">取消令牌</param>
|
||||
/// <returns>用户角色信息</returns>
|
||||
[ApiInformation(Cookie = CookieType.Stoken, Salt = SaltType.LK2)]
|
||||
[ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.LK2)]
|
||||
public async Task<Response<GameAuthKey>> GenerateAuthenticationKeyAsync(User user, GenAuthKeyData data, CancellationToken token = default)
|
||||
{
|
||||
Response<GameAuthKey>? resp = await httpClient
|
||||
.SetUser(user, CookieType.Stoken)
|
||||
.SetUser(user, CookieType.SToken)
|
||||
.SetReferer(ApiEndpoints.AppMihoyoReferer)
|
||||
.UseDynamicSecret(DynamicSecretVersion.Gen1, SaltType.LK2, true)
|
||||
.TryCatchPostAsJsonAsync<GenAuthKeyData, Response<GameAuthKey>>(ApiEndpoints.BindingGenAuthKey, data, options, logger, token)
|
||||
|
||||
@@ -45,7 +45,7 @@ internal sealed class CardClient
|
||||
public async Task<Response<VerificationRegistration>> CreateVerificationAsync(User user, CancellationToken token)
|
||||
{
|
||||
Response<VerificationRegistration>? resp = await httpClient
|
||||
.SetUser(user, CookieType.Ltoken)
|
||||
.SetUser(user, CookieType.LToken)
|
||||
.UseDynamicSecret(DynamicSecretVersion.Gen2, SaltType.X4, false)
|
||||
.TryCatchGetFromJsonAsync<Response<VerificationRegistration>>(ApiEndpoints.CardCreateVerification, options, logger, token)
|
||||
.ConfigureAwait(false);
|
||||
@@ -77,11 +77,11 @@ internal sealed class CardClient
|
||||
/// <param name="user">用户</param>
|
||||
/// <param name="token">取消令牌</param>
|
||||
/// <returns>桌面小组件数据</returns>
|
||||
[ApiInformation(Cookie = CookieType.Stoken, Salt = SaltType.X6)]
|
||||
[ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.X6)]
|
||||
public async Task<Response<DataWrapper<WidgetData>>> GetWidgetDataAsync(User user, CancellationToken token)
|
||||
{
|
||||
Response<DataWrapper<WidgetData>>? resp = await httpClient
|
||||
.SetUser(user, CookieType.Stoken)
|
||||
.SetUser(user, CookieType.SToken)
|
||||
.UseDynamicSecret(DynamicSecretVersion.Gen2, SaltType.X6, false)
|
||||
.TryCatchGetFromJsonAsync<Response<DataWrapper<WidgetData>>>(ApiEndpoints.CardWidgetData, options, logger, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
@@ -82,11 +82,11 @@ internal sealed class GameRecordClient
|
||||
/// <param name="userAndUid">用户与角色</param>
|
||||
/// <param name="token">取消令牌</param>
|
||||
/// <returns>玩家的基础信息</returns>
|
||||
[ApiInformation(Cookie = CookieType.Ltoken, Salt = SaltType.X4)]
|
||||
[ApiInformation(Cookie = CookieType.LToken, Salt = SaltType.X4)]
|
||||
public async Task<Response<PlayerInfo>> GetPlayerInfoAsync(UserAndUid userAndUid, CancellationToken token = default)
|
||||
{
|
||||
Response<PlayerInfo>? resp = await httpClient
|
||||
.SetUser(userAndUid.User, CookieType.Ltoken)
|
||||
.SetUser(userAndUid.User, CookieType.LToken)
|
||||
.UseDynamicSecret(DynamicSecretVersion.Gen2, SaltType.X4, false)
|
||||
.TryCatchGetFromJsonAsync<Response<PlayerInfo>>(ApiEndpoints.GameRecordIndex(userAndUid.Uid), options, logger, token)
|
||||
.ConfigureAwait(false);
|
||||
@@ -119,11 +119,11 @@ internal sealed class GameRecordClient
|
||||
/// <param name="userAndUid">用户与角色</param>
|
||||
/// <param name="token">取消令牌</param>
|
||||
/// <returns>角色基本信息</returns>
|
||||
[ApiInformation(Cookie = CookieType.Ltoken, Salt = SaltType.X4)]
|
||||
[ApiInformation(Cookie = CookieType.LToken, Salt = SaltType.X4)]
|
||||
public async Task<Response<BasicRoleInfo>> GetRoleBasicInfoAsync(UserAndUid userAndUid, CancellationToken token = default)
|
||||
{
|
||||
Response<BasicRoleInfo>? resp = await httpClient
|
||||
.SetUser(userAndUid.User, CookieType.Ltoken)
|
||||
.SetUser(userAndUid.User, CookieType.LToken)
|
||||
.UseDynamicSecret(DynamicSecretVersion.Gen2, SaltType.X4, false)
|
||||
.TryCatchGetFromJsonAsync<Response<BasicRoleInfo>>(ApiEndpoints.GameRecordRoleBasicInfo(userAndUid.Uid), options, logger, token)
|
||||
.ConfigureAwait(false);
|
||||
@@ -138,13 +138,13 @@ internal sealed class GameRecordClient
|
||||
/// <param name="playerInfo">玩家的基础信息</param>
|
||||
/// <param name="token">取消令牌</param>
|
||||
/// <returns>角色列表</returns>
|
||||
[ApiInformation(Cookie = CookieType.Ltoken, Salt = SaltType.X4)]
|
||||
[ApiInformation(Cookie = CookieType.LToken, Salt = SaltType.X4)]
|
||||
public async Task<Response<CharacterWrapper>> GetCharactersAsync(UserAndUid userAndUid, PlayerInfo playerInfo, CancellationToken token = default)
|
||||
{
|
||||
CharacterData data = new(userAndUid.Uid, playerInfo.Avatars.Select(x => x.Id));
|
||||
|
||||
Response<CharacterWrapper>? resp = await httpClient
|
||||
.SetUser(userAndUid.User, CookieType.Ltoken)
|
||||
.SetUser(userAndUid.User, CookieType.LToken)
|
||||
.UseDynamicSecret(DynamicSecretVersion.Gen2, SaltType.X4, false)
|
||||
.TryCatchPostAsJsonAsync<CharacterData, Response<CharacterWrapper>>(ApiEndpoints.GameRecordCharacter, data, options, logger, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
Reference in New Issue
Block a user