mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
fixup some code style phase 1
This commit is contained in:
@@ -11,7 +11,7 @@ using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Snap.Hutao.SourceGeneration.DedendencyInjection;
|
||||
namespace Snap.Hutao.SourceGeneration.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// 注入HttpClient代码生成器
|
||||
@@ -21,10 +21,10 @@ namespace Snap.Hutao.SourceGeneration.DedendencyInjection;
|
||||
[Generator]
|
||||
public class HttpClientGenerator : ISourceGenerator
|
||||
{
|
||||
private const string DefaultName = "Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient.HttpClientConfigration.Default";
|
||||
private const string XRpcName = "Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient.HttpClientConfigration.XRpc";
|
||||
private const string XRpc2Name = "Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient.HttpClientConfigration.XRpc2";
|
||||
private const string XRpc3Name = "Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient.HttpClientConfigration.XRpc3";
|
||||
private const string DefaultName = "Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient.HttpClientConfiguration.Default";
|
||||
private const string XRpcName = "Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient.HttpClientConfiguration.XRpc";
|
||||
private const string XRpc2Name = "Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient.HttpClientConfiguration.XRpc2";
|
||||
private const string XRpc3Name = "Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient.HttpClientConfiguration.XRpc3";
|
||||
|
||||
private const string PrimaryHttpMessageHandlerAttributeName = "Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient.PrimaryHttpMessageHandlerAttribute";
|
||||
private const string DynamicSecretAttributeName = "Snap.Hutao.Web.Hoyolab.DynamicSecret.UseDynamicSecretAttribute";
|
||||
@@ -49,29 +49,34 @@ public class HttpClientGenerator : ISourceGenerator
|
||||
|
||||
StringBuilder sourceCodeBuilder = new();
|
||||
|
||||
sourceCodeBuilder.Append($@"// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
// This class is generated by Snap.Hutao.SourceGeneration
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Snap.Hutao.Web.Hoyolab.DynamicSecret;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace Snap.Hutao.Core.DependencyInjection;
|
||||
|
||||
internal static partial class IocHttpClientConfiguration
|
||||
{{
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(""{toolName}"",""1.0.0.0"")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public static partial IServiceCollection AddHttpClients(this IServiceCollection services)
|
||||
{{");
|
||||
sourceCodeBuilder.Append($$"""
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
// This class is generated by Snap.Hutao.SourceGeneration
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Snap.Hutao.Web.Hoyolab.DynamicSecret;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace Snap.Hutao.Core.DependencyInjection;
|
||||
|
||||
internal static partial class IocHttpClientConfiguration
|
||||
{
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("{{toolName}}","1.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public static partial IServiceCollection AddHttpClients(this IServiceCollection services)
|
||||
{
|
||||
""");
|
||||
|
||||
FillWithInjectionServices(receiver, sourceCodeBuilder);
|
||||
sourceCodeBuilder.Append(@"
|
||||
return services;
|
||||
}
|
||||
}");
|
||||
|
||||
sourceCodeBuilder.Append("""
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
""");
|
||||
|
||||
context.AddSource("IocHttpClientConfiguration.g.cs", SourceText.From(sourceCodeBuilder.ToString(), Encoding.UTF8));
|
||||
}
|
||||
@@ -110,7 +115,7 @@ internal static partial class IocHttpClientConfiguration
|
||||
lineBuilder.Append("XRpc3Configuration)");
|
||||
break;
|
||||
default:
|
||||
throw new InvalidOperationException($"非法的HttpClientConfigration值: [{injectAsName}]");
|
||||
throw new InvalidOperationException($"非法的 HttpClientConfiguration 值: [{injectAsName}]");
|
||||
}
|
||||
|
||||
AttributeData? handlerInfo = classSymbol
|
||||
@@ -124,11 +129,11 @@ internal static partial class IocHttpClientConfiguration
|
||||
|
||||
foreach (KeyValuePair<string, TypedConstant> property in properties)
|
||||
{
|
||||
lineBuilder.Append(" ");
|
||||
lineBuilder.Append(' ');
|
||||
lineBuilder.Append(property.Key);
|
||||
lineBuilder.Append(" = ");
|
||||
lineBuilder.Append(property.Value.ToCSharpString());
|
||||
lineBuilder.Append(",");
|
||||
lineBuilder.Append(',');
|
||||
}
|
||||
|
||||
lineBuilder.Append(" })");
|
||||
@@ -139,7 +144,7 @@ internal static partial class IocHttpClientConfiguration
|
||||
lineBuilder.Append(".AddHttpMessageHandler<DynamicSecretHandler>()");
|
||||
}
|
||||
|
||||
lineBuilder.Append(";");
|
||||
lineBuilder.Append(';');
|
||||
|
||||
lines.Add(lineBuilder.ToString());
|
||||
}
|
||||
@@ -11,7 +11,7 @@ using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Snap.Hutao.SourceGeneration.DedendencyInjection;
|
||||
namespace Snap.Hutao.SourceGeneration.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// 注入代码生成器
|
||||
@@ -44,27 +44,30 @@ public class InjectionGenerator : ISourceGenerator
|
||||
string toolName = this.GetGeneratorType().FullName;
|
||||
|
||||
StringBuilder sourceCodeBuilder = new();
|
||||
sourceCodeBuilder.Append($@"// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
// This class is generated by Snap.Hutao.SourceGeneration
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Snap.Hutao.Core.DependencyInjection;
|
||||
|
||||
internal static partial class ServiceCollectionExtension
|
||||
{{
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(""{toolName}"",""1.0.0.0"")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public static partial IServiceCollection AddInjections(this IServiceCollection services)
|
||||
{{");
|
||||
sourceCodeBuilder.Append($$"""
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
// This class is generated by Snap.Hutao.SourceGeneration
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Snap.Hutao.Core.DependencyInjection;
|
||||
|
||||
internal static partial class ServiceCollectionExtension
|
||||
{
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("{{toolName}}","1.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public static partial IServiceCollection AddInjections(this IServiceCollection services)
|
||||
{
|
||||
""");
|
||||
|
||||
FillWithInjectionServices(receiver, sourceCodeBuilder);
|
||||
sourceCodeBuilder.Append(@"
|
||||
return services;
|
||||
}
|
||||
}");
|
||||
sourceCodeBuilder.Append("""
|
||||
return services;
|
||||
}
|
||||
}
|
||||
""");
|
||||
|
||||
context.AddSource("ServiceCollectionExtension.g.cs", SourceText.From(sourceCodeBuilder.ToString(), Encoding.UTF8));
|
||||
}
|
||||
@@ -153,4 +156,4 @@ internal static partial class ServiceCollectionExtension
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ namespace Snap.Hutao.Core.Caching;
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[Injection(InjectAs.Singleton, typeof(IImageCache))]
|
||||
[HttpClient(HttpClientConfigration.Default)]
|
||||
[HttpClient(HttpClientConfiguration.Default)]
|
||||
[PrimaryHttpMessageHandler(MaxConnectionsPerServer = 8)]
|
||||
internal sealed class ImageCache : IImageCache, IImageCacheFilePathOperation
|
||||
{
|
||||
|
||||
@@ -24,21 +24,31 @@ internal static class CoreEnvironment
|
||||
/// </summary>
|
||||
public const string HoyolabUA = $"Mozilla/5.0 (Windows NT 10.0; Win64; x64) miHoYoBBS/{HoyolabXrpcVersion}";
|
||||
|
||||
/// <summary>
|
||||
/// Hoyolab请求UA
|
||||
/// </summary>
|
||||
public const string HoyolabOsUA = $"Mozilla/5.0 (Windows NT 10.0; Win64; x64) miHoYoBBSOversea/{HoyolabOsXrpcVersion}";
|
||||
|
||||
/// <summary>
|
||||
/// 米游社移动端请求UA
|
||||
/// </summary>
|
||||
public const string HoyolabMobileUA = $"Mozilla/5.0 (Linux; Android 12) Mobile miHoYoBBS/{HoyolabXrpcVersion}";
|
||||
|
||||
/// <summary>
|
||||
/// Hoyolab iPhone 移动端请求UA
|
||||
/// Hoyolab 移动端请求UA
|
||||
/// </summary>
|
||||
public const string HoyolabOsMobileUA = "Mozilla/5.0 (iPhone; CPU iPhone OS 16_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) miHoYoBBSOversea/2.28.0";
|
||||
public const string HoyolabOsMobileUA = $"Mozilla/5.0 (Linux; Android 12) Mobile miHoYoBBSOversea/{HoyolabOsXrpcVersion}";
|
||||
|
||||
/// <summary>
|
||||
/// 米游社 Rpc 版本
|
||||
/// </summary>
|
||||
public const string HoyolabXrpcVersion = "2.44.1";
|
||||
|
||||
/// <summary>
|
||||
/// Hoyolab Rpc 版本
|
||||
/// </summary>
|
||||
public const string HoyolabOsXrpcVersion = "2.28.0";
|
||||
|
||||
/// <summary>
|
||||
/// 盐
|
||||
/// </summary>
|
||||
@@ -50,6 +60,8 @@ internal static class CoreEnvironment
|
||||
[SaltType.X4] = "xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs",
|
||||
[SaltType.X6] = "t0qEgfub6cvueAPgR5m9aQWWVciEer7v",
|
||||
[SaltType.PROD] = "JwYDpKvLj6MrMqqYU6jTKF17KNO2PXoS",
|
||||
|
||||
// This SALT is not reliable
|
||||
[SaltType.OS] = "6cqshh5dhw73bzxn20oexa9k516chk7s",
|
||||
}.ToImmutableDictionary();
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ internal sealed class HttpClientAttribute : Attribute
|
||||
/// 构造一个新的特性
|
||||
/// </summary>
|
||||
/// <param name="configration">配置</param>
|
||||
public HttpClientAttribute(HttpClientConfigration configration)
|
||||
public HttpClientAttribute(HttpClientConfiguration configration)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient;
|
||||
/// Http客户端配置
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal enum HttpClientConfigration
|
||||
internal enum HttpClientConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
/// 默认配置
|
||||
@@ -12,6 +12,8 @@ namespace Snap.Hutao.Core.DependencyInjection;
|
||||
[HighQuality]
|
||||
internal static partial class IocHttpClientConfiguration
|
||||
{
|
||||
private const string ApplicationJson = "application/json";
|
||||
|
||||
/// <summary>
|
||||
/// 添加 <see cref="HttpClient"/>
|
||||
/// </summary>
|
||||
@@ -37,7 +39,7 @@ internal static partial class IocHttpClientConfiguration
|
||||
{
|
||||
client.Timeout = Timeout.InfiniteTimeSpan;
|
||||
client.DefaultRequestHeaders.UserAgent.ParseAdd(CoreEnvironment.HoyolabUA);
|
||||
client.DefaultRequestHeaders.Accept.ParseAdd("application/json");
|
||||
client.DefaultRequestHeaders.Accept.ParseAdd(ApplicationJson);
|
||||
client.DefaultRequestHeaders.Add("x-rpc-app_version", CoreEnvironment.HoyolabXrpcVersion);
|
||||
client.DefaultRequestHeaders.Add("x-rpc-client_type", "5");
|
||||
client.DefaultRequestHeaders.Add("x-rpc-device_id", CoreEnvironment.HoyolabDeviceId);
|
||||
@@ -51,7 +53,7 @@ internal static partial class IocHttpClientConfiguration
|
||||
{
|
||||
client.Timeout = Timeout.InfiniteTimeSpan;
|
||||
client.DefaultRequestHeaders.UserAgent.ParseAdd(CoreEnvironment.HoyolabUA);
|
||||
client.DefaultRequestHeaders.Accept.ParseAdd("application/json");
|
||||
client.DefaultRequestHeaders.Accept.ParseAdd(ApplicationJson);
|
||||
client.DefaultRequestHeaders.Add("x-rpc-aigis", string.Empty);
|
||||
client.DefaultRequestHeaders.Add("x-rpc-app_id", "bll8iq97cem8");
|
||||
client.DefaultRequestHeaders.Add("x-rpc-app_version", CoreEnvironment.HoyolabXrpcVersion);
|
||||
@@ -69,8 +71,8 @@ internal static partial class IocHttpClientConfiguration
|
||||
private static void XRpc3Configuration(HttpClient client)
|
||||
{
|
||||
client.Timeout = Timeout.InfiniteTimeSpan;
|
||||
client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36");
|
||||
client.DefaultRequestHeaders.Accept.ParseAdd("application/json");
|
||||
client.DefaultRequestHeaders.UserAgent.ParseAdd(CoreEnvironment.HoyolabOsUA);
|
||||
client.DefaultRequestHeaders.Accept.ParseAdd(ApplicationJson);
|
||||
client.DefaultRequestHeaders.Add("x-rpc-app_version", "1.5.0");
|
||||
client.DefaultRequestHeaders.Add("x-rpc-client_type", "4");
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Snap.Hutao.Migrations;
|
||||
using Snap.Hutao.Web.Hoyolab;
|
||||
using Snap.Hutao.Web.Hoyolab.Bbs.User;
|
||||
using Snap.Hutao.Web.Hoyolab.Passport;
|
||||
@@ -104,20 +103,13 @@ internal sealed class User : ObservableObject
|
||||
internal static async Task<User> ResumeAsync(EntityUser inner, CancellationToken token = default)
|
||||
{
|
||||
User user = new(inner);
|
||||
bool isOk = false;
|
||||
|
||||
if (!user.Entity.IsOversea)
|
||||
{
|
||||
isOk = await user.InitializeCoreAsync(token).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
isOk = await user.InitializeCoreOsAsync(token).ConfigureAwait(false);
|
||||
}
|
||||
bool isOk = user.Entity.IsOversea
|
||||
? await user.InitializeCoreOsAsync(token).ConfigureAwait(false)
|
||||
: await user.InitializeCoreAsync(token).ConfigureAwait(false);
|
||||
|
||||
if (!isOk)
|
||||
{
|
||||
user.UserInfo = new UserInfo() { Nickname = "网络异常" };
|
||||
user.UserInfo = new() { Nickname = SH.ModelBindingUserInitializationFailed };
|
||||
user.UserGameRoles = new();
|
||||
}
|
||||
|
||||
@@ -137,7 +129,6 @@ internal sealed class User : ObservableObject
|
||||
|
||||
entity.Aid = cookie.GetValueOrDefault(Cookie.STUID);
|
||||
entity.Mid = cookie.GetValueOrDefault(Cookie.MID);
|
||||
entity.IsOversea = false;
|
||||
|
||||
if (entity.Aid != null && entity.Mid != null)
|
||||
{
|
||||
@@ -153,20 +144,20 @@ internal sealed class User : ObservableObject
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建并初始化国际服用户(临时)
|
||||
/// 创建并初始化国际服用户
|
||||
/// </summary>
|
||||
/// <param name="cookie">cookie</param>
|
||||
/// <param name="token">取消令牌</param>
|
||||
/// <returns>用户</returns>
|
||||
internal static async Task<User?> CreateOsUserAsync(Cookie cookie, CancellationToken token = default)
|
||||
internal static async Task<User?> CreateOsAsync(Cookie cookie, CancellationToken token = default)
|
||||
{
|
||||
// 这里只负责创建实体用户,稍后在用户服务中保存到数据库
|
||||
EntityUser entity = EntityUser.CreateOs(cookie);
|
||||
|
||||
entity.Aid = cookie.GetValueOrDefault(Cookie.STUID);
|
||||
|
||||
// Note: Currently we dont know how to get "mid" for hoyolab user,
|
||||
// mid is set as the same value of ltuid(stuid/user id)
|
||||
// Note: Currently we don't know how to get "mid" for hoyolab user,
|
||||
// mid is set as the same value of ltuid/stuid
|
||||
entity.Mid = entity.Aid;
|
||||
|
||||
entity.IsOversea = true;
|
||||
@@ -224,6 +215,88 @@ internal sealed class User : ObservableObject
|
||||
return isInitialized = true;
|
||||
}
|
||||
|
||||
private async Task<bool> InitializeCoreOsAsync(CancellationToken token = default)
|
||||
{
|
||||
if (isInitialized)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (SToken == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
using (IServiceScope scope = Ioc.Default.CreateScope())
|
||||
{
|
||||
// 自动填充 Ltoken
|
||||
if (LToken == null)
|
||||
{
|
||||
Response<LtokenWrapper> ltokenResponse = await scope.ServiceProvider
|
||||
.GetRequiredService<PassportClientOs>()
|
||||
.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;
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch user info
|
||||
Response<UserFullInfoWrapper> response = await scope.ServiceProvider
|
||||
.GetRequiredService<UserClient>()
|
||||
.GetOsUserFullInfoAsync(Entity, token)
|
||||
.ConfigureAwait(false);
|
||||
UserInfo = response.Data?.UserInfo;
|
||||
|
||||
// 自动填充 CookieToken
|
||||
if (CookieToken == null)
|
||||
{
|
||||
Response<UidCookieToken> cookieTokenResponse = await scope.ServiceProvider
|
||||
.GetRequiredService<PassportClientOs>()
|
||||
.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;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取游戏角色
|
||||
Response<ListWrapper<UserGameRole>> userGameRolesResponse = await scope.ServiceProvider
|
||||
.GetRequiredService<BindingClient>()
|
||||
.GetOsUserGameRolesByCookieAsync(Entity, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (userGameRolesResponse.IsOk())
|
||||
{
|
||||
UserGameRoles = userGameRolesResponse.Data.List;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
SelectedUserGameRole = UserGameRoles.FirstOrFirstOrDefault(role => role.IsChosen);
|
||||
|
||||
isInitialized = true;
|
||||
|
||||
return UserInfo != null && UserGameRoles.Any();
|
||||
}
|
||||
|
||||
private async Task<bool> TrySetLTokenAsync(IServiceProvider provider, CancellationToken token)
|
||||
{
|
||||
if (LToken != null)
|
||||
@@ -311,87 +384,4 @@ internal sealed class User : ObservableObject
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<bool> InitializeCoreOsAsync(CancellationToken token = default)
|
||||
{
|
||||
if (isInitialized)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (SToken == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
using (IServiceScope scope = Ioc.Default.CreateScope())
|
||||
{
|
||||
|
||||
// 自动填充 Ltoken
|
||||
if (LToken == null)
|
||||
{
|
||||
Response<LtokenWrapper> ltokenResponse = await scope.ServiceProvider
|
||||
.GetRequiredService<PassportClientOs>()
|
||||
.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;
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch user info
|
||||
Response<UserFullInfoWrapper> response = await scope.ServiceProvider
|
||||
.GetRequiredService<UserClient>()
|
||||
.GetOsUserFullInfoAsync(Entity, token)
|
||||
.ConfigureAwait(false);
|
||||
UserInfo = response.Data?.UserInfo;
|
||||
|
||||
// 自动填充 CookieToken
|
||||
if (CookieToken == null)
|
||||
{
|
||||
Response<UidCookieToken> cookieTokenResponse = await scope.ServiceProvider
|
||||
.GetRequiredService<PassportClientOs>()
|
||||
.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;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取游戏角色
|
||||
Response<ListWrapper<UserGameRole>> userGameRolesResponse = await scope.ServiceProvider
|
||||
.GetRequiredService<BindingClient>()
|
||||
.GetOsUserGameRolesByCookieAsync(Entity, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (userGameRolesResponse.IsOk())
|
||||
{
|
||||
UserGameRoles = userGameRolesResponse.Data.List;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
SelectedUserGameRole = UserGameRoles.FirstOrFirstOrDefault(role => role.IsChosen);
|
||||
|
||||
isInitialized = true;
|
||||
|
||||
return UserInfo != null && UserGameRoles.Any();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ internal sealed class User : ISelectable
|
||||
/// <returns>新创建的用户</returns>
|
||||
public static User CreateOs(Cookie cookie)
|
||||
{
|
||||
_ = cookie.TryGetAsStokenV1(out Cookie? stoken);
|
||||
_ = cookie.TryGetAsLegacyStoken(out Cookie? stoken);
|
||||
_ = cookie.TryGetAsLtoken(out Cookie? ltoken);
|
||||
_ = cookie.TryGetAsCookieToken(out Cookie? cookieToken);
|
||||
|
||||
|
||||
@@ -411,6 +411,15 @@ namespace Snap.Hutao.Resource.Localization {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 网络异常 的本地化字符串。
|
||||
/// </summary>
|
||||
internal static string ModelBindingUserInitializationFailed {
|
||||
get {
|
||||
return ResourceManager.GetString("ModelBindingUserInitializationFailed", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 第 {0} 期 的本地化字符串。
|
||||
/// </summary>
|
||||
|
||||
@@ -1806,4 +1806,7 @@
|
||||
<data name="ViewServiceHutaoUserLoginOrRegisterHint" xml:space="preserve">
|
||||
<value>立即登录或注册</value>
|
||||
</data>
|
||||
<data name="ModelBindingUserInitializationFailed" xml:space="preserve">
|
||||
<value>网络异常</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -16,7 +16,7 @@ namespace Snap.Hutao.Service.Game.Package;
|
||||
/// 游戏文件包转换器
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[HttpClient(HttpClientConfigration.Default)]
|
||||
[HttpClient(HttpClientConfiguration.Default)]
|
||||
internal sealed class PackageConverter
|
||||
{
|
||||
private readonly JsonSerializerOptions options;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Snap.Hutao.Service.Metadata;
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[Injection(InjectAs.Singleton, typeof(IMetadataService))]
|
||||
[HttpClient(HttpClientConfigration.Default)]
|
||||
[HttpClient(HttpClientConfiguration.Default)]
|
||||
internal sealed partial class MetadataService : IMetadataService, IMetadataServiceInitialization
|
||||
{
|
||||
private const string MetaFileName = "Meta.json";
|
||||
|
||||
@@ -329,7 +329,7 @@ internal class UserService : IUserService
|
||||
// 判断是否为国际服
|
||||
if (isOversea)
|
||||
{
|
||||
newUser = await BindingUser.CreateOsUserAsync(cookie).ConfigureAwait(false);
|
||||
newUser = await BindingUser.CreateOsAsync(cookie).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -49,7 +49,7 @@ internal sealed partial class SignInWebViewDialog : ContentDialog
|
||||
|
||||
if (user.Entity.IsOversea)
|
||||
{
|
||||
coreWebView2.SetCookie(user.CookieToken, user.LToken, null).SetOsMobileUserAgent();
|
||||
coreWebView2.SetCookie(user.CookieToken, user.LToken, null).SetMobileOsUserAgent();
|
||||
signInJsInterface = new(coreWebView2, scope.ServiceProvider);
|
||||
coreWebView2.Navigate("https://act.hoyolab.com/ys/event/signin-sea-v3/index.html?act_id=e202102251931481&hyl_presentation_style=fullscreen");
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@ internal static class CoreWebView2Extension
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置 移动端UA
|
||||
/// 设置 移动端OsUA
|
||||
/// </summary>
|
||||
/// <param name="webView">webview2</param>
|
||||
/// <returns>链式调用的WebView2</returns>
|
||||
public static CoreWebView2 SetOsMobileUserAgent(this CoreWebView2 webView)
|
||||
public static CoreWebView2 SetMobileOsUserAgent(this CoreWebView2 webView)
|
||||
{
|
||||
webView.Settings.UserAgent = Core.CoreEnvironment.HoyolabOsMobileUA;
|
||||
return webView;
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Snap.Hutao.Web.Enka;
|
||||
/// Enka API 客户端
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[HttpClient(HttpClientConfigration.Default)]
|
||||
[HttpClient(HttpClientConfiguration.Default)]
|
||||
internal sealed class EnkaClient
|
||||
{
|
||||
private const string EnkaAPI = "https://enka.network/api/uid/{0}";
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Snap.Hutao.Web.Geetest;
|
||||
/// 极验客户端
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[HttpClient(HttpClientConfigration.Default)]
|
||||
[HttpClient(HttpClientConfiguration.Default)]
|
||||
internal sealed class GeetestClient
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Snap.Hutao.Web.Hoyolab.App.Account;
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[UseDynamicSecret]
|
||||
[HttpClient(HttpClientConfigration.XRpc)]
|
||||
[HttpClient(HttpClientConfiguration.XRpc)]
|
||||
internal sealed class AccountClient
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Snap.Hutao.Web.Hoyolab.Bbs.User;
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[UseDynamicSecret]
|
||||
[HttpClient(HttpClientConfigration.XRpc)]
|
||||
[HttpClient(HttpClientConfiguration.XRpc)]
|
||||
internal sealed class UserClient
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
@@ -122,7 +122,7 @@ internal sealed partial class Cookie
|
||||
/// </summary>
|
||||
/// <param name="cookie">A cookie contains stoken and stuid, without mid.</param>
|
||||
/// <returns>是否获取成功</returns>
|
||||
public bool TryGetAsStokenV1([NotNullWhen(true)] out Cookie? cookie)
|
||||
public bool TryGetAsLegacyStoken([NotNullWhen(true)] out Cookie? cookie)
|
||||
{
|
||||
bool hasStoken = TryGetValue(STOKEN, out string? stoken);
|
||||
bool hasStuid = TryGetValue(STUID, out string? stuid);
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Snap.Hutao.Web.Hoyolab.Hk4e.Common.Announcement;
|
||||
/// <summary>
|
||||
/// 公告客户端
|
||||
/// </summary>
|
||||
[HttpClient(HttpClientConfigration.Default)]
|
||||
[HttpClient(HttpClientConfiguration.Default)]
|
||||
internal sealed class AnnouncementClient
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Snap.Hutao.Web.Hoyolab.Hk4e.Event.GachaInfo;
|
||||
/// 祈愿记录客户端
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[HttpClient(HttpClientConfigration.Default)]
|
||||
[HttpClient(HttpClientConfiguration.Default)]
|
||||
internal sealed class GachaInfoClient
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Snap.Hutao.Web.Hoyolab.Passport;
|
||||
/// 通行证客户端
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[HttpClient(HttpClientConfigration.Default)]
|
||||
[HttpClient(HttpClientConfiguration.Default)]
|
||||
internal sealed class PassportClient
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Snap.Hutao.Web.Hoyolab.Passport;
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[UseDynamicSecret]
|
||||
[HttpClient(HttpClientConfigration.XRpc2)]
|
||||
[HttpClient(HttpClientConfiguration.XRpc2)]
|
||||
internal sealed class PassportClient2
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Snap.Hutao.Web.Hoyolab.Passport;
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[UseDynamicSecret]
|
||||
[HttpClient(HttpClientConfigration.XRpc3)]
|
||||
[HttpClient(HttpClientConfiguration.XRpc3)]
|
||||
internal sealed class PassportClientOs
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher;
|
||||
/// 游戏资源客户端
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[HttpClient(HttpClientConfigration.Default)]
|
||||
[HttpClient(HttpClientConfiguration.Default)]
|
||||
internal sealed class ResourceClient
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Snap.Hutao.Web.Hoyolab.Takumi.Auth;
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[UseDynamicSecret]
|
||||
[HttpClient(HttpClientConfigration.Default)]
|
||||
[HttpClient(HttpClientConfiguration.Default)]
|
||||
internal sealed class AuthClient
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Snap.Hutao.Web.Hoyolab.Takumi.Auth;
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[UseDynamicSecret]
|
||||
[HttpClient(HttpClientConfigration.Default)]
|
||||
[HttpClient(HttpClientConfiguration.Default)]
|
||||
internal sealed class AuthClientOs
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Snap.Hutao.Web.Hoyolab.Takumi.Binding;
|
||||
/// 绑定客户端
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[HttpClient(HttpClientConfigration.Default)]
|
||||
[HttpClient(HttpClientConfiguration.Default)]
|
||||
internal sealed class BindingClient
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Snap.Hutao.Web.Hoyolab.Takumi.Binding;
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[UseDynamicSecret]
|
||||
[HttpClient(HttpClientConfigration.XRpc)]
|
||||
[HttpClient(HttpClientConfiguration.XRpc)]
|
||||
internal sealed class BindingClient2
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate;
|
||||
/// 养成计算器客户端
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[HttpClient(HttpClientConfigration.Default)]
|
||||
[HttpClient(HttpClientConfiguration.Default)]
|
||||
internal sealed class CalculateClient
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Snap.Hutao.Web.Hoyolab.Takumi.GameRecord;
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[UseDynamicSecret]
|
||||
[HttpClient(HttpClientConfigration.XRpc)]
|
||||
[HttpClient(HttpClientConfiguration.XRpc)]
|
||||
internal sealed class CardClient
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Snap.Hutao.Web.Hoyolab.Takumi.GameRecord;
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[UseDynamicSecret]
|
||||
[HttpClient(HttpClientConfigration.XRpc)]
|
||||
[HttpClient(HttpClientConfiguration.XRpc)]
|
||||
[PrimaryHttpMessageHandler(UseCookies = false)]
|
||||
internal sealed class GameRecordClient
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Snap.Hutao.Web.Hoyolab.Takumi.GameRecord;
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[UseDynamicSecret]
|
||||
[HttpClient(HttpClientConfigration.XRpc3)]
|
||||
[HttpClient(HttpClientConfiguration.XRpc3)]
|
||||
[PrimaryHttpMessageHandler(UseCookies = false)]
|
||||
internal sealed class GameRecordClientOs
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Snap.Hutao.Web.Hutao;
|
||||
/// 胡桃日志客户端
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[HttpClient(HttpClientConfigration.Default)]
|
||||
[HttpClient(HttpClientConfiguration.Default)]
|
||||
internal sealed class HomaLogUploadClient
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Snap.Hutao.Web.Hutao;
|
||||
/// 胡桃通行证客户端
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[HttpClient(HttpClientConfigration.Default)]
|
||||
[HttpClient(HttpClientConfiguration.Default)]
|
||||
internal sealed class HomaPassportClient
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Snap.Hutao.Web.Hutao;
|
||||
/// 胡桃API客户端
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[HttpClient(HttpClientConfigration.Default)]
|
||||
[HttpClient(HttpClientConfiguration.Default)]
|
||||
internal sealed class HomaSpiralAbyssClient
|
||||
{
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
Reference in New Issue
Block a user