This commit is contained in:
Lightczx
2024-04-16 17:28:15 +08:00
parent 80d6d5eb2b
commit 8703c3a598
20 changed files with 95 additions and 341 deletions

View File

@@ -15,9 +15,6 @@ using System.Net.Sockets;
namespace Snap.Hutao.Web.Enka;
/// <summary>
/// Enka API 客户端
/// </summary>
[HighQuality]
[ConstructorGenerated(ResolveHttpClient = true)]
[HttpClient(HttpClientConfiguration.Default)]
@@ -26,26 +23,14 @@ internal sealed partial class EnkaClient
private const string EnkaAPI = "https://enka.network/api/uid/{0}";
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly IHttpClientFactory httpClientFactory;
private readonly JsonSerializerOptions options;
private readonly HttpClient httpClient;
/// <summary>
/// 异步获取转发的 Enka API 响应
/// </summary>
/// <param name="playerUid">玩家Uid</param>
/// <param name="token">取消令牌</param>
/// <returns>Enka API 响应</returns>
public ValueTask<EnkaResponse?> GetForwardDataAsync(in PlayerUid playerUid, CancellationToken token = default)
{
return TryGetEnkaResponseCoreAsync(HutaoEndpoints.Enka(playerUid), token);
}
/// <summary>
/// 异步获取 Enka API 响应
/// </summary>
/// <param name="playerUid">玩家Uid</param>
/// <param name="token">取消令牌</param>
/// <returns>Enka API 响应</returns>
public ValueTask<EnkaResponse?> GetDataAsync(in PlayerUid playerUid, CancellationToken token = default)
{
return TryGetEnkaResponseCoreAsync(string.Format(CultureInfo.CurrentCulture, EnkaAPI, playerUid), token);
@@ -59,34 +44,37 @@ internal sealed partial class EnkaClient
.SetRequestUri(url)
.Get();
using (HttpResponseMessage response = await httpClient.SendAsync(builder.HttpRequestMessage, HttpCompletionOption.ResponseHeadersRead, token).ConfigureAwait(false))
using (HttpClient httpClient = httpClientFactory.CreateClient(nameof(EnkaClient)))
{
if (response.IsSuccessStatusCode)
using (HttpResponseMessage response = await httpClient.SendAsync(builder.HttpRequestMessage, HttpCompletionOption.ResponseHeadersRead, token).ConfigureAwait(false))
{
return await response.Content.ReadFromJsonAsync<EnkaResponse>(options, token).ConfigureAwait(false);
}
else
{
// https://github.com/yoimiya-kokomi/miao-plugin/pull/441
// Additionally, HTTP codes for UID requests:
// 400 = wrong UID format
// 404 = player does not exist(MHY server told that)
// 429 = rate - limit
// 424 = game maintenance / everything is broken after the update
// 500 = general server error
// 503 = I screwed up massively
string message = response.StatusCode switch
if (response.IsSuccessStatusCode)
{
HttpStatusCode.BadRequest => SH.WebEnkaResponseStatusCode400,
HttpStatusCode.NotFound => SH.WebEnkaResponseStatusCode404,
HttpStatusCode.FailedDependency => SH.WebEnkaResponseStatusCode424,
HttpStatusCode.TooManyRequests => SH.WebEnkaResponseStatusCode429,
HttpStatusCode.InternalServerError => SH.WebEnkaResponseStatusCode500,
HttpStatusCode.ServiceUnavailable => SH.WebEnkaResponseStatusCode503,
_ => SH.WebEnkaResponseStatusCodeUnknown,
};
return await response.Content.ReadFromJsonAsync<EnkaResponse>(options, token).ConfigureAwait(false);
}
else
{
// https://github.com/yoimiya-kokomi/miao-plugin/pull/441
// Additionally, HTTP codes for UID requests:
// 400 = wrong UID format
// 404 = player does not exist(MHY server told that)
// 429 = rate - limit
// 424 = game maintenance / everything is broken after the update
// 500 = general server error
// 503 = I screwed up massively
string message = response.StatusCode switch
{
HttpStatusCode.BadRequest => SH.WebEnkaResponseStatusCode400,
HttpStatusCode.NotFound => SH.WebEnkaResponseStatusCode404,
HttpStatusCode.FailedDependency => SH.WebEnkaResponseStatusCode424,
HttpStatusCode.TooManyRequests => SH.WebEnkaResponseStatusCode429,
HttpStatusCode.InternalServerError => SH.WebEnkaResponseStatusCode500,
HttpStatusCode.ServiceUnavailable => SH.WebEnkaResponseStatusCode503,
_ => SH.WebEnkaResponseStatusCodeUnknown,
};
return new() { Message = message, };
return new() { Message = message, };
}
}
}
}

View File

@@ -10,6 +10,7 @@ namespace Snap.Hutao.Web.Hoyolab.Annotation;
/// 指示此API 已经经过验证,且明确其调用
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
[Obsolete("不再使用此特性")]
internal sealed class ApiInformationAttribute : Attribute
{
/// <summary>

View File

@@ -13,26 +13,15 @@ using System.Net.Http;
namespace Snap.Hutao.Web.Hoyolab.App.Account;
/// <summary>
/// 账户客户端
/// </summary>
[HighQuality]
[ConstructorGenerated(ResolveHttpClient = true)]
[HttpClient(HttpClientConfiguration.XRpc)]
internal sealed partial class AccountClient
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly IHttpClientFactory httpClientFactory;
private readonly ILogger<AccountClient> logger;
private readonly HttpClient httpClient;
/// <summary>
/// 异步生成米游社操作验证密钥
/// </summary>
/// <param name="user">用户</param>
/// <param name="data">提交数据</param>
/// <param name="token">取消令牌</param>
/// <returns>用户角色信息</returns>
[ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.K2)]
public async ValueTask<Response<GameAuthKey>> GenerateAuthenticationKeyAsync(User user, GenAuthKeyData data, CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
@@ -44,7 +33,7 @@ internal sealed partial class AccountClient
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen1, SaltType.K2, false).ConfigureAwait(false);
Response<GameAuthKey>? resp = await builder
.TryCatchSendAsync<Response<GameAuthKey>>(httpClient, logger, token)
.TryCatchSendAsync<Response<GameAuthKey>>(httpClientFactory.CreateClient(nameof(AccountClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);

View File

@@ -9,24 +9,15 @@ using System.Net.Http;
namespace Snap.Hutao.Web.Hoyolab.Bbs.User;
/// <summary>
/// 用户信息客户端 DS版
/// </summary>
[HighQuality]
[ConstructorGenerated(ResolveHttpClient = true)]
[HttpClient(HttpClientConfiguration.XRpc)]
internal sealed partial class UserClient : IUserClient
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly IHttpClientFactory httpClientFactory;
private readonly ILogger<UserClient> logger;
private readonly HttpClient httpClient;
/// <summary>
/// 获取当前用户详细信息
/// </summary>
/// <param name="user">用户</param>
/// <param name="token">取消令牌</param>
/// <returns>详细信息</returns>
public async ValueTask<Response<UserFullInfoWrapper>> GetUserFullInfoAsync(Model.Entity.User user, CancellationToken token = default)
{
ArgumentException.ThrowIfNullOrEmpty(user.Aid);
@@ -37,7 +28,7 @@ internal sealed partial class UserClient : IUserClient
.Get();
Response<UserFullInfoWrapper>? resp = await builder
.TryCatchSendAsync<Response<UserFullInfoWrapper>>(httpClient, logger, token)
.TryCatchSendAsync<Response<UserFullInfoWrapper>>(httpClientFactory.CreateClient(nameof(UserClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);

View File

@@ -10,9 +10,6 @@ using System.Net.Http;
namespace Snap.Hutao.Web.Hoyolab.Bbs.User;
/// <summary>
/// 用户信息客户端 Hoyolab版
/// </summary>
[ConstructorGenerated(ResolveHttpClient = true)]
[HttpClient(HttpClientConfiguration.Default)]
internal sealed partial class UserClientOversea : IUserClient
@@ -21,13 +18,6 @@ internal sealed partial class UserClientOversea : IUserClient
private readonly ILogger<UserClientOversea> logger;
private readonly HttpClient httpClient;
/// <summary>
/// 获取当前用户详细信息,使用 LToken
/// </summary>
/// <param name="user">用户</param>
/// <param name="token">取消令牌</param>
/// <returns>详细信息</returns>
[ApiInformation(Cookie = CookieType.LToken)]
public async ValueTask<Response<UserFullInfoWrapper>> GetUserFullInfoAsync(Model.Entity.User user, CancellationToken token = default)
{
ArgumentException.ThrowIfNullOrEmpty(user.Aid);

View File

@@ -9,24 +9,14 @@ using System.Net.Http;
namespace Snap.Hutao.Web.Hoyolab.Hk4e.Common.Announcement;
/// <summary>
/// 公告客户端
/// </summary>
[ConstructorGenerated(ResolveHttpClient = true)]
[HttpClient(HttpClientConfiguration.Default)]
internal sealed partial class AnnouncementClient
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly IHttpClientFactory httpClientFactory;
private readonly ILogger<AnnouncementClient> logger;
private readonly HttpClient httpClient;
/// <summary>
/// 异步获取公告列表
/// </summary>
/// <param name="languageCode">语言代码</param>
/// <param name="region">服务器</param>
/// <param name="token">取消令牌</param>
/// <returns>公告列表</returns>
public async ValueTask<Response<AnnouncementWrapper>> GetAnnouncementsAsync(string languageCode, Region region, CancellationToken token = default)
{
string annListUrl = region.IsOversea()
@@ -38,19 +28,12 @@ internal sealed partial class AnnouncementClient
.Get();
Response<AnnouncementWrapper>? resp = await builder
.TryCatchSendAsync<Response<AnnouncementWrapper>>(httpClient, logger, token)
.TryCatchSendAsync<Response<AnnouncementWrapper>>(httpClientFactory.CreateClient(nameof(AnnouncementClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
}
/// <summary>
/// 异步获取公告内容列表
/// </summary>
/// <param name="languageCode">语言代码</param>
/// <param name="region">服务器</param>
/// <param name="token">取消令牌</param>
/// <returns>公告内容列表</returns>
public async ValueTask<Response<ListWrapper<AnnouncementContent>>> GetAnnouncementContentsAsync(string languageCode, Region region, CancellationToken token = default)
{
string annContentUrl = region.IsOversea()
@@ -62,7 +45,7 @@ internal sealed partial class AnnouncementClient
.Get();
Response<ListWrapper<AnnouncementContent>>? resp = await builder
.TryCatchSendAsync<Response<ListWrapper<AnnouncementContent>>>(httpClient, logger, token)
.TryCatchSendAsync<Response<ListWrapper<AnnouncementContent>>>(httpClientFactory.CreateClient(nameof(AnnouncementClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);

View File

@@ -18,8 +18,8 @@ namespace Snap.Hutao.Web.Hoyolab.Hk4e.Event.GachaInfo;
internal sealed partial class GachaInfoClient
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly IHttpClientFactory httpClientFactory;
private readonly ILogger<GachaInfoClient> logger;
private readonly HttpClient httpClient;
/// <summary>
/// 获取记录页面
@@ -40,7 +40,7 @@ internal sealed partial class GachaInfoClient
.Get();
Response<GachaLogPage>? resp = await builder
.TryCatchSendAsync<Response<GachaLogPage>>(httpClient, logger, token)
.TryCatchSendAsync<Response<GachaLogPage>>(httpClientFactory.CreateClient(nameof(GachaInfoClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);

View File

@@ -14,8 +14,8 @@ namespace Snap.Hutao.Web.Hoyolab.Hk4e.Sdk.Combo;
internal sealed partial class PandaClient
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly IHttpClientFactory httpClientFactory;
private readonly ILogger<PandaClient> logger;
private readonly HttpClient httpClient;
public async ValueTask<Response<UrlWrapper>> QRCodeFetchAsync(CancellationToken token = default)
{
@@ -28,7 +28,7 @@ internal sealed partial class PandaClient
.PostJson(options);
Response<UrlWrapper>? resp = await builder
.TryCatchSendAsync<Response<UrlWrapper>>(httpClient, logger, token)
.TryCatchSendAsync<Response<UrlWrapper>>(httpClientFactory.CreateClient(nameof(PandaClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
@@ -44,7 +44,7 @@ internal sealed partial class PandaClient
.PostJson(options);
Response<GameLoginResult>? resp = await builder
.TryCatchSendAsync<Response<GameLoginResult>>(httpClient, logger, token)
.TryCatchSendAsync<Response<GameLoginResult>>(httpClientFactory.CreateClient(nameof(PandaClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);

View File

@@ -12,25 +12,15 @@ using System.Net.Http;
namespace Snap.Hutao.Web.Hoyolab.Passport;
/// <summary>
/// 通行证客户端 XRPC 版
/// </summary>
[HighQuality]
[ConstructorGenerated(ResolveHttpClient = true)]
[HttpClient(HttpClientConfiguration.XRpc2)]
internal sealed partial class PassportClient : IPassportClient
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly IHttpClientFactory httpClientFactory;
private readonly ILogger<PassportClient2> logger;
private readonly HttpClient httpClient;
/// <summary>
/// 异步获取 CookieToken
/// </summary>
/// <param name="user">用户</param>
/// <param name="token">取消令牌</param>
/// <returns>cookie token</returns>
[ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.PROD)]
public async ValueTask<Response<UidCookieToken>> GetCookieAccountInfoBySTokenAsync(User user, CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
@@ -41,19 +31,12 @@ internal sealed partial class PassportClient : IPassportClient
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen2, SaltType.PROD, true).ConfigureAwait(false);
Response<UidCookieToken>? resp = await builder
.TryCatchSendAsync<Response<UidCookieToken>>(httpClient, logger, token)
.TryCatchSendAsync<Response<UidCookieToken>>(httpClientFactory.CreateClient(nameof(PassportClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
}
/// <summary>
/// 异步获取 LToken
/// </summary>
/// <param name="user">用户</param>
/// <param name="token">取消令牌</param>
/// <returns>uid 与 cookie token</returns>
[ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.PROD)]
public async ValueTask<Response<LTokenWrapper>> GetLTokenBySTokenAsync(User user, CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
@@ -64,7 +47,7 @@ internal sealed partial class PassportClient : IPassportClient
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen2, SaltType.PROD, true).ConfigureAwait(false);
Response<LTokenWrapper>? resp = await builder
.TryCatchSendAsync<Response<LTokenWrapper>>(httpClient, logger, token)
.TryCatchSendAsync<Response<LTokenWrapper>>(httpClientFactory.CreateClient(nameof(PassportClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);

View File

@@ -13,25 +13,15 @@ using System.Net.Http;
namespace Snap.Hutao.Web.Hoyolab.Passport;
/// <summary>
/// 通行证客户端
/// </summary>
[HighQuality]
[ConstructorGenerated(ResolveHttpClient = true)]
[HttpClient(HttpClientConfiguration.XRpc2)]
internal sealed partial class PassportClient2
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly IHttpClientFactory httpClientFactory;
private readonly ILogger<PassportClient2> logger;
private readonly HttpClient httpClient;
/// <summary>
/// 异步验证 LToken
/// </summary>
/// <param name="user">用户</param>
/// <param name="token">取消令牌</param>
/// <returns>验证信息</returns>
[ApiInformation(Cookie = CookieType.LToken)]
public async ValueTask<Response<UserInfoWrapper>> VerifyLtokenAsync(User user, CancellationToken token)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
@@ -40,19 +30,12 @@ internal sealed partial class PassportClient2
.PostJson(new Timestamp());
Response<UserInfoWrapper>? resp = await builder
.TryCatchSendAsync<Response<UserInfoWrapper>>(httpClient, logger, token)
.TryCatchSendAsync<Response<UserInfoWrapper>>(httpClientFactory.CreateClient(nameof(PassportClient2)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
}
/// <summary>
/// V1 SToken 登录
/// </summary>
/// <param name="stokenV1">v1 SToken</param>
/// <param name="token">取消令牌</param>
/// <returns>登录数据</returns>
[ApiInformation(Salt = SaltType.PROD)]
public async ValueTask<Response<LoginResult>> LoginBySTokenAsync(Cookie stokenV1, CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
@@ -63,7 +46,7 @@ internal sealed partial class PassportClient2
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen2, SaltType.PROD, true).ConfigureAwait(false);
Response<LoginResult>? resp = await builder
.TryCatchSendAsync<Response<LoginResult>>(httpClient, logger, token)
.TryCatchSendAsync<Response<LoginResult>>(httpClientFactory.CreateClient(nameof(PassportClient2)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
@@ -83,7 +66,7 @@ internal sealed partial class PassportClient2
.PostJson(data);
Response<LoginResult>? resp = await builder
.TryCatchSendAsync<Response<LoginResult>>(httpClient, logger, token)
.TryCatchSendAsync<Response<LoginResult>>(httpClientFactory.CreateClient(nameof(PassportClient2)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);

View File

@@ -11,24 +11,14 @@ using System.Net.Http;
namespace Snap.Hutao.Web.Hoyolab.Passport;
/// <summary>
/// 通行证客户端 XRPC 版
/// </summary>
[ConstructorGenerated(ResolveHttpClient = true)]
[HttpClient(HttpClientConfiguration.XRpc3)]
internal sealed partial class PassportClientOversea : IPassportClient
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly ILogger<PassportClientOversea> logger;
private readonly HttpClient httpClient;
private readonly IHttpClientFactory httpClientFactory;
/// <summary>
/// 异步获取 CookieToken
/// </summary>
/// <param name="user">用户</param>
/// <param name="token">取消令牌</param>
/// <returns>cookie token</returns>
[ApiInformation(Cookie = CookieType.SToken)]
public async ValueTask<Response<UidCookieToken>> GetCookieAccountInfoBySTokenAsync(User user, CancellationToken token = default)
{
string? stoken = user.SToken?.GetValueOrDefault(Cookie.STOKEN);
@@ -42,19 +32,12 @@ internal sealed partial class PassportClientOversea : IPassportClient
.PostJson(data);
Response<UidCookieToken>? resp = await builder
.TryCatchSendAsync<Response<UidCookieToken>>(httpClient, logger, token)
.TryCatchSendAsync<Response<UidCookieToken>>(httpClientFactory.CreateClient(nameof(PassportClientOversea)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
}
/// <summary>
/// 异步获取 LToken
/// </summary>
/// <param name="user">用户</param>
/// <param name="token">取消令牌</param>
/// <returns>uid 与 cookie token</returns>
[ApiInformation(Cookie = CookieType.SToken)]
public async ValueTask<Response<LTokenWrapper>> GetLTokenBySTokenAsync(User user, CancellationToken token = default)
{
string? stoken = user.SToken?.GetValueOrDefault(Cookie.STOKEN);
@@ -68,7 +51,7 @@ internal sealed partial class PassportClientOversea : IPassportClient
.PostJson(data);
Response<LTokenWrapper>? resp = await builder
.TryCatchSendAsync<Response<LTokenWrapper>>(httpClient, logger, token)
.TryCatchSendAsync<Response<LTokenWrapper>>(httpClientFactory.CreateClient(nameof(PassportClientOversea)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);

View File

@@ -14,7 +14,7 @@ namespace Snap.Hutao.Web.Hoyolab.PublicData.DeviceFp;
internal sealed partial class DeviceFpClient
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly HttpClient httpClient;
private readonly IHttpClientFactory httpClientFactory;
private readonly ILogger<DeviceFpClient> logger;
public async ValueTask<Response<DeviceFpWrapper>> GetFingerprintAsync(DeviceFpData data, CancellationToken token)
@@ -24,7 +24,7 @@ internal sealed partial class DeviceFpClient
.PostJson(data);
Response<DeviceFpWrapper>? resp = await builder
.TryCatchSendAsync<Response<DeviceFpWrapper>>(httpClient, logger, token)
.TryCatchSendAsync<Response<DeviceFpWrapper>>(httpClientFactory.CreateClient(nameof(DeviceFpClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);

View File

@@ -8,30 +8,19 @@ using Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource;
using Snap.Hutao.Web.Request.Builder;
using Snap.Hutao.Web.Request.Builder.Abstraction;
using Snap.Hutao.Web.Response;
using System.IO;
using System.Net.Http;
using System.Text;
namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher;
/// <summary>
/// 游戏资源客户端
/// </summary>
[HighQuality]
[ConstructorGenerated(ResolveHttpClient = true)]
[HttpClient(HttpClientConfiguration.Default)]
internal sealed partial class ResourceClient
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly HttpClient httpClient;
private readonly IHttpClientFactory httpClientFactory;
private readonly ILogger<ResourceClient> logger;
/// <summary>
/// 异步获取游戏资源
/// </summary>
/// <param name="scheme">方案</param>
/// <param name="token">取消令牌</param>
/// <returns>游戏资源</returns>
public async ValueTask<Response<GameResource>> GetResourceAsync(LaunchScheme scheme, CancellationToken token = default)
{
string url = scheme.IsOversea
@@ -43,7 +32,7 @@ internal sealed partial class ResourceClient
.Get();
Response<GameResource>? resp = await builder
.TryCatchSendAsync<Response<GameResource>>(httpClient, logger, token)
.TryCatchSendAsync<Response<GameResource>>(httpClientFactory.CreateClient(nameof(ResourceClient)), logger, token)
.ConfigureAwait(false);
// 最新版完整包
@@ -72,7 +61,7 @@ internal sealed partial class ResourceClient
.Get();
Response<GameContent>? resp = await builder
.TryCatchSendAsync<Response<GameContent>>(httpClient, logger, token)
.TryCatchSendAsync<Response<GameContent>>(httpClientFactory.CreateClient(nameof(ResourceClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);

View File

@@ -13,19 +13,15 @@ using System.Net.Http;
namespace Snap.Hutao.Web.Hoyolab.Takumi.Auth;
/// <summary>
/// 授权客户端
/// </summary>
[HighQuality]
[ConstructorGenerated(ResolveHttpClient = true)]
[HttpClient(HttpClientConfiguration.Default)]
internal sealed partial class AuthClient
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly IHttpClientFactory httpClientFactory;
private readonly ILogger<BindingClient> logger;
private readonly HttpClient httpClient;
[ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.K2)]
public async ValueTask<Response<ActionTicketWrapper>> GetActionTicketBySTokenAsync(string action, User user, CancellationToken token = default)
{
ArgumentException.ThrowIfNullOrEmpty(user.Aid);
@@ -39,19 +35,12 @@ internal sealed partial class AuthClient
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen1, SaltType.K2, true).ConfigureAwait(false);
Response<ActionTicketWrapper>? resp = await builder
.TryCatchSendAsync<Response<ActionTicketWrapper>>(httpClient, logger, token)
.TryCatchSendAsync<Response<ActionTicketWrapper>>(httpClientFactory.CreateClient(nameof(AuthClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
}
/// <summary>
/// 获取 MultiToken
/// </summary>
/// <param name="cookie">login cookie</param>
/// <param name="isOversea">是否为国际服</param>
/// <param name="token">取消令牌</param>
/// <returns>包含token的字典</returns>
public async ValueTask<Response<ListWrapper<NameToken>>> GetMultiTokenByLoginTicketAsync(Cookie cookie, bool isOversea, CancellationToken token = default)
{
Response<ListWrapper<NameToken>>? resp = null;
@@ -69,7 +58,7 @@ internal sealed partial class AuthClient
.Get();
resp = await builder
.TryCatchSendAsync<Response<ListWrapper<NameToken>>>(httpClient, logger, token)
.TryCatchSendAsync<Response<ListWrapper<NameToken>>>(httpClientFactory.CreateClient(nameof(AuthClient)), logger, token)
.ConfigureAwait(false);
}

View File

@@ -1,6 +1,7 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Microsoft.Extensions.Http;
using Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient;
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Web.Hoyolab.Annotation;
@@ -12,26 +13,16 @@ using System.Net.Http;
namespace Snap.Hutao.Web.Hoyolab.Takumi.Binding;
/// <summary>
/// 绑定客户端
/// </summary>
[HighQuality]
[ConstructorGenerated(ResolveHttpClient = true)]
[HttpClient(HttpClientConfiguration.Default)]
internal sealed partial class BindingClient
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly IHttpClientFactory httpClientFactory;
private readonly IServiceProvider serviceProvider;
private readonly ILogger<BindingClient> logger;
private readonly HttpClient httpClient;
/// <summary>
/// 异步获取用户角色信息
/// 自动判断是否为国际服
/// </summary>
/// <param name="user">用户</param>
/// <param name="token">取消令牌</param>
/// <returns>用户角色信息</returns>
public async ValueTask<Response<ListWrapper<UserGameRole>>> GetUserGameRolesOverseaAwareAsync(User user, CancellationToken token = default)
{
if (user.IsOversea)
@@ -55,14 +46,6 @@ internal sealed partial class BindingClient
}
}
/// <summary>
/// 异步获取用户角色信息
/// </summary>
/// <param name="actionTicket">操作凭证</param>
/// <param name="user">用户</param>
/// <param name="token">取消令牌</param>
/// <returns>用户角色信息</returns>
[ApiInformation(Cookie = CookieType.LToken)]
public async ValueTask<Response<ListWrapper<UserGameRole>>> GetUserGameRolesByActionTicketAsync(string actionTicket, User user, CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
@@ -71,19 +54,12 @@ internal sealed partial class BindingClient
.Get();
Response<ListWrapper<UserGameRole>>? resp = await builder
.TryCatchSendAsync<Response<ListWrapper<UserGameRole>>>(httpClient, logger, token)
.TryCatchSendAsync<Response<ListWrapper<UserGameRole>>>(httpClientFactory.CreateClient(nameof(BindingClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
}
/// <summary>
/// 异步获取国际服用户角色信息
/// </summary>
/// <param name="user">用户</param>
/// <param name="token">取消令牌</param>
/// <returns>用户角色信息</returns>
[ApiInformation(Cookie = CookieType.LToken)]
public async ValueTask<Response<ListWrapper<UserGameRole>>> GetOverseaUserGameRolesByCookieAsync(User user, CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
@@ -92,7 +68,7 @@ internal sealed partial class BindingClient
.Get();
Response<ListWrapper<UserGameRole>>? resp = await builder
.TryCatchSendAsync<Response<ListWrapper<UserGameRole>>>(httpClient, logger, token)
.TryCatchSendAsync<Response<ListWrapper<UserGameRole>>>(httpClientFactory.CreateClient(nameof(BindingClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);

View File

@@ -12,9 +12,6 @@ using System.Net.Http;
namespace Snap.Hutao.Web.Hoyolab.Takumi.Binding;
/// <summary>
/// SToken绑定客户端
/// </summary>
[HighQuality]
[ConstructorGenerated(ResolveHttpClient = true)]
[HttpClient(HttpClientConfiguration.XRpc)]
@@ -22,16 +19,9 @@ namespace Snap.Hutao.Web.Hoyolab.Takumi.Binding;
internal sealed partial class BindingClient2
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly IHttpClientFactory httpClientFactory;
private readonly ILogger<BindingClient2> logger;
private readonly HttpClient httpClient;
/// <summary>
/// 获取用户角色信息
/// </summary>
/// <param name="user">用户</param>
/// <param name="token">取消令牌</param>
/// <returns>用户角色信息</returns>
[ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.LK2)]
public async ValueTask<Response<ListWrapper<UserGameRole>>> GetUserGameRolesBySTokenAsync(User user, CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
@@ -43,21 +33,12 @@ internal sealed partial class BindingClient2
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen1, SaltType.LK2, true).ConfigureAwait(false);
Response<ListWrapper<UserGameRole>>? resp = await builder
.TryCatchSendAsync<Response<ListWrapper<UserGameRole>>>(httpClient, logger, token)
.TryCatchSendAsync<Response<ListWrapper<UserGameRole>>>(httpClientFactory.CreateClient(nameof(BindingClient2)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
}
/// <summary>
/// 异步生成祈愿验证密钥
/// 需要 SToken
/// </summary>
/// <param name="user">用户</param>
/// <param name="data">提交数据</param>
/// <param name="token">取消令牌</param>
/// <returns>用户角色信息</returns>
[ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.LK2)]
public async ValueTask<Response<GameAuthKey>> GenerateAuthenticationKeyAsync(User user, GenAuthKeyData data, CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
@@ -69,7 +50,7 @@ internal sealed partial class BindingClient2
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen1, SaltType.LK2, true).ConfigureAwait(false);
Response<GameAuthKey>? resp = await builder
.TryCatchSendAsync<Response<GameAuthKey>>(httpClient, logger, token)
.TryCatchSendAsync<Response<GameAuthKey>>(httpClientFactory.CreateClient(nameof(BindingClient2)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);

View File

@@ -13,19 +13,16 @@ using System.Net.Http;
namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.BbsSignReward;
/// <summary>
/// 签到客户端
/// </summary>
[ConstructorGenerated(ResolveHttpClient = true)]
[HttpClient(HttpClientConfiguration.XRpc)]
[PrimaryHttpMessageHandler(UseCookies = false)]
internal sealed partial class SignInClient : ISignInClient
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly IHttpClientFactory httpClientFactory;
private readonly HomaGeetestClient homaGeetestClient;
private readonly CultureOptions cultureOptions;
private readonly ILogger<SignInClient> logger;
private readonly HttpClient httpClient;
public async ValueTask<Response<ExtraAwardInfo>> GetExtraAwardInfoAsync(UserAndUid userAndUid, CancellationToken token = default)
{
@@ -38,7 +35,7 @@ internal sealed partial class SignInClient : ISignInClient
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen1, SaltType.LK2, true).ConfigureAwait(false);
Response<ExtraAwardInfo>? resp = await builder
.TryCatchSendAsync<Response<ExtraAwardInfo>>(httpClient, logger, token)
.TryCatchSendAsync<Response<ExtraAwardInfo>>(httpClientFactory.CreateClient(nameof(SignInClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
@@ -55,7 +52,7 @@ internal sealed partial class SignInClient : ISignInClient
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen1, SaltType.LK2, true).ConfigureAwait(false);
Response<SignInRewardInfo>? resp = await builder
.TryCatchSendAsync<Response<SignInRewardInfo>>(httpClient, logger, token)
.TryCatchSendAsync<Response<SignInRewardInfo>>(httpClientFactory.CreateClient(nameof(SignInClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
@@ -72,7 +69,7 @@ internal sealed partial class SignInClient : ISignInClient
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen1, SaltType.LK2, true).ConfigureAwait(false);
Response<SignInRewardReSignInfo>? resp = await builder
.TryCatchSendAsync<Response<SignInRewardReSignInfo>>(httpClient, logger, token)
.TryCatchSendAsync<Response<SignInRewardReSignInfo>>(httpClientFactory.CreateClient(nameof(SignInClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
@@ -87,7 +84,7 @@ internal sealed partial class SignInClient : ISignInClient
.Get();
Response<Reward>? resp = await builder
.TryCatchSendAsync<Response<Reward>>(httpClient, logger, token)
.TryCatchSendAsync<Response<Reward>>(httpClientFactory.CreateClient(nameof(SignInClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
@@ -104,7 +101,7 @@ internal sealed partial class SignInClient : ISignInClient
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen1, SaltType.LK2, true).ConfigureAwait(false);
Response<SignInResult>? resp = await builder
.TryCatchSendAsync<Response<SignInResult>>(httpClient, logger, token)
.TryCatchSendAsync<Response<SignInResult>>(httpClientFactory.CreateClient(nameof(SignInClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
@@ -121,7 +118,7 @@ internal sealed partial class SignInClient : ISignInClient
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen1, SaltType.LK2, true).ConfigureAwait(false);
Response<SignInResult>? resp = await builder
.TryCatchSendAsync<Response<SignInResult>>(httpClient, logger, token)
.TryCatchSendAsync<Response<SignInResult>>(httpClientFactory.CreateClient(nameof(SignInClient)), logger, token)
.ConfigureAwait(false);
if (resp is { Data: { Success: 1, Gt: string gt, Challenge: string originChallenge } })
@@ -140,7 +137,7 @@ internal sealed partial class SignInClient : ISignInClient
await verifiedBuilder.SignDataAsync(DataSignAlgorithmVersion.Gen1, SaltType.LK2, true).ConfigureAwait(false);
resp = await verifiedBuilder
.TryCatchSendAsync<Response<SignInResult>>(httpClient, logger, token)
.TryCatchSendAsync<Response<SignInResult>>(httpClientFactory.CreateClient(nameof(SignInClient)), logger, token)
.ConfigureAwait(false);
}
else

View File

@@ -11,18 +11,15 @@ using System.Net.Http;
namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.BbsSignReward;
/// <summary>
/// Global签到客户端
/// </summary>
[ConstructorGenerated(ResolveHttpClient = true)]
[HttpClient(HttpClientConfiguration.Default)]
[PrimaryHttpMessageHandler(UseCookies = false)]
internal sealed partial class SignInClientOversea : ISignInClient
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly IHttpClientFactory httpClientFactory;
private readonly HomaGeetestClient homaGeetestClient;
private readonly ILogger<SignInClient> logger;
private readonly HttpClient httpClient;
public async ValueTask<Response<SignInRewardInfo>> GetInfoAsync(UserAndUid userAndUid, CancellationToken token = default(CancellationToken))
{
@@ -32,7 +29,7 @@ internal sealed partial class SignInClientOversea : ISignInClient
.Get();
Response<SignInRewardInfo>? resp = await builder
.TryCatchSendAsync<Response<SignInRewardInfo>>(httpClient, logger, token)
.TryCatchSendAsync<Response<SignInRewardInfo>>(httpClientFactory.CreateClient(nameof(SignInClientOversea)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
@@ -46,7 +43,7 @@ internal sealed partial class SignInClientOversea : ISignInClient
.Get();
Response<Reward>? resp = await builder
.TryCatchSendAsync<Response<Reward>>(httpClient, logger, token)
.TryCatchSendAsync<Response<Reward>>(httpClientFactory.CreateClient(nameof(SignInClientOversea)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
@@ -60,7 +57,7 @@ internal sealed partial class SignInClientOversea : ISignInClient
.PostJson(new SignInData(userAndUid.Uid, true));
Response<SignInResult>? resp = await builder
.TryCatchSendAsync<Response<SignInResult>>(httpClient, logger, token)
.TryCatchSendAsync<Response<SignInResult>>(httpClientFactory.CreateClient(nameof(SignInClientOversea)), logger, token)
.ConfigureAwait(false);
if (resp is { Data: { Success: 1, Gt: string gt, Challenge: string originChallenge } })
@@ -76,7 +73,7 @@ internal sealed partial class SignInClientOversea : ISignInClient
.PostJson(new SignInData(userAndUid.Uid, true));
resp = await verifiedBuilder
.TryCatchSendAsync<Response<SignInResult>>(httpClient, logger, token)
.TryCatchSendAsync<Response<SignInResult>>(httpClientFactory.CreateClient(nameof(SignInClientOversea)), logger, token)
.ConfigureAwait(false);
}
else

View File

@@ -11,26 +11,15 @@ using System.Net.Http;
namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate;
/// <summary>
/// 养成计算器客户端
/// </summary>
[HighQuality]
[ConstructorGenerated(ResolveHttpClient = true)]
[HttpClient(HttpClientConfiguration.Default)]
internal sealed partial class CalculateClient
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly IHttpClientFactory httpClientFactory;
private readonly ILogger<CalculateClient> logger;
private readonly HttpClient httpClient;
/// <summary>
/// 异步计算结果
/// </summary>
/// <param name="user">用户</param>
/// <param name="delta">差异</param>
/// <param name="token">取消令牌</param>
/// <returns>消耗结果</returns>
[ApiInformation(Cookie = CookieType.Cookie)]
public async ValueTask<Response<Consumption>> ComputeAsync(Model.Entity.User user, AvatarPromotionDelta delta, CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
@@ -40,18 +29,12 @@ internal sealed partial class CalculateClient
.PostJson(delta);
Response<Consumption>? resp = await builder
.TryCatchSendAsync<Response<Consumption>>(httpClient, logger, token)
.TryCatchSendAsync<Response<Consumption>>(httpClientFactory.CreateClient(nameof(CalculateClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
}
/// <summary>
/// 异步获取角色列表
/// </summary>
/// <param name="userAndUid">用户与角色</param>
/// <param name="token">取消令牌</param>
/// <returns>角色列表</returns>
public async ValueTask<List<Avatar>> GetAvatarsAsync(UserAndUid userAndUid, CancellationToken token = default)
{
int currentPage = 1;
@@ -71,7 +54,7 @@ internal sealed partial class CalculateClient
.PostJson(filter);
resp = await builder
.TryCatchSendAsync<Response<ListWrapper<Avatar>>>(httpClient, logger, token)
.TryCatchSendAsync<Response<ListWrapper<Avatar>>>(httpClientFactory.CreateClient(nameof(CalculateClient)), logger, token)
.ConfigureAwait(false);
if (resp is not null && resp.IsOk())
@@ -91,13 +74,6 @@ internal sealed partial class CalculateClient
return avatars;
}
/// <summary>
/// 异步获取角色详情
/// </summary>
/// <param name="userAndUid">用户与角色</param>
/// <param name="avatar">角色</param>
/// <param name="token">取消令牌</param>
/// <returns>角色详情</returns>
public async ValueTask<Response<AvatarDetail>> GetAvatarDetailAsync(UserAndUid userAndUid, Avatar avatar, CancellationToken token = default)
{
string url = userAndUid.User.IsOversea
@@ -111,19 +87,12 @@ internal sealed partial class CalculateClient
.Get();
Response<AvatarDetail>? resp = await builder
.TryCatchSendAsync<Response<AvatarDetail>>(httpClient, logger, token)
.TryCatchSendAsync<Response<AvatarDetail>>(httpClientFactory.CreateClient(nameof(CalculateClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
}
/// <summary>
/// 异步获取摹本的家具列表
/// </summary>
/// <param name="user">用户</param>
/// <param name="shareCode">摹本码</param>
/// <param name="token">取消令牌</param>
/// <returns>家具列表</returns>
public async ValueTask<Response<FurnitureListWrapper>> FurnitureBlueprintAsync(Model.Entity.User user, string shareCode, CancellationToken token)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
@@ -133,19 +102,12 @@ internal sealed partial class CalculateClient
.Get();
Response<FurnitureListWrapper>? resp = await builder
.TryCatchSendAsync<Response<FurnitureListWrapper>>(httpClient, logger, token)
.TryCatchSendAsync<Response<FurnitureListWrapper>>(httpClientFactory.CreateClient(nameof(CalculateClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
}
/// <summary>
/// 家具数量计算
/// </summary>
/// <param name="user">用户</param>
/// <param name="items">物品</param>
/// <param name="token">取消令牌</param>
/// <returns>消耗</returns>
public async ValueTask<Response<ListWrapper<Item>>> FurnitureComputeAsync(Model.Entity.User user, List<Item> items, CancellationToken token)
{
ListWrapper<IdCount> data = new() { List = items.Select(i => new IdCount { Id = i.Id, Count = i.Num }).ToList() };
@@ -157,7 +119,7 @@ internal sealed partial class CalculateClient
.PostJson(data);
Response<ListWrapper<Item>>? resp = await builder
.TryCatchSendAsync<Response<ListWrapper<Item>>>(httpClient, logger, token)
.TryCatchSendAsync<Response<ListWrapper<Item>>>(httpClientFactory.CreateClient(nameof(CalculateClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);

View File

@@ -14,9 +14,6 @@ using System.Net.Http;
namespace Snap.Hutao.Web.Hoyolab.Takumi.GameRecord;
/// <summary>
/// 游戏记录提供器
/// </summary>
[HighQuality]
[ConstructorGenerated(ResolveHttpClient = true)]
[HttpClient(HttpClientConfiguration.XRpc)]
@@ -24,11 +21,10 @@ namespace Snap.Hutao.Web.Hoyolab.Takumi.GameRecord;
internal sealed partial class GameRecordClient : IGameRecordClient
{
private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory;
private readonly IHttpClientFactory httpClientFactory;
private readonly IServiceProvider serviceProvider;
private readonly ILogger<GameRecordClient> logger;
private readonly HttpClient httpClient;
[ApiInformation(Cookie = CookieType.Cookie, Salt = SaltType.X4)]
public async ValueTask<Response<DailyNote.DailyNote>> GetDailyNoteAsync(UserAndUid userAndUid, CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
@@ -40,7 +36,7 @@ internal sealed partial class GameRecordClient : IGameRecordClient
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen2, SaltType.X4, false).ConfigureAwait(false);
Response<DailyNote.DailyNote>? resp = await builder
.TryCatchSendAsync<Response<DailyNote.DailyNote>>(httpClient, logger, token)
.TryCatchSendAsync<Response<DailyNote.DailyNote>>(httpClientFactory.CreateClient(nameof(GameRecordClient)), logger, token)
.ConfigureAwait(false);
// We have a verification procedure to handle
@@ -64,7 +60,7 @@ internal sealed partial class GameRecordClient : IGameRecordClient
await verifiedbuilder.SignDataAsync(DataSignAlgorithmVersion.Gen2, SaltType.X4, false).ConfigureAwait(false);
resp = await verifiedbuilder
.TryCatchSendAsync<Response<DailyNote.DailyNote>>(httpClient, logger, token)
.TryCatchSendAsync<Response<DailyNote.DailyNote>>(httpClientFactory.CreateClient(nameof(GameRecordClient)), logger, token)
.ConfigureAwait(false);
}
}
@@ -72,7 +68,6 @@ internal sealed partial class GameRecordClient : IGameRecordClient
return Response.Response.DefaultIfNull(resp);
}
[ApiInformation(Cookie = CookieType.LToken, Salt = SaltType.X4)]
public async ValueTask<Response<PlayerInfo>> GetPlayerInfoAsync(UserAndUid userAndUid, CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
@@ -84,7 +79,7 @@ internal sealed partial class GameRecordClient : IGameRecordClient
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen2, SaltType.X4, false).ConfigureAwait(false);
Response<PlayerInfo>? resp = await builder
.TryCatchSendAsync<Response<PlayerInfo>>(httpClient, logger, token)
.TryCatchSendAsync<Response<PlayerInfo>>(httpClientFactory.CreateClient(nameof(GameRecordClient)), logger, token)
.ConfigureAwait(false);
// We have a verification procedure to handle
@@ -108,7 +103,7 @@ internal sealed partial class GameRecordClient : IGameRecordClient
await verifiedbuilder.SignDataAsync(DataSignAlgorithmVersion.Gen2, SaltType.X4, false).ConfigureAwait(false);
resp = await verifiedbuilder
.TryCatchSendAsync<Response<PlayerInfo>>(httpClient, logger, token)
.TryCatchSendAsync<Response<PlayerInfo>>(httpClientFactory.CreateClient(nameof(GameRecordClient)), logger, token)
.ConfigureAwait(false);
}
}
@@ -116,14 +111,6 @@ internal sealed partial class GameRecordClient : IGameRecordClient
return Response.Response.DefaultIfNull(resp);
}
/// <summary>
/// 获取玩家深渊信息
/// </summary>
/// <param name="userAndUid">用户</param>
/// <param name="schedule">1当期2上期</param>
/// <param name="token">取消令牌</param>
/// <returns>深渊信息</returns>
[ApiInformation(Cookie = CookieType.Cookie, Salt = SaltType.X4)]
public async ValueTask<Response<SpiralAbyss.SpiralAbyss>> GetSpiralAbyssAsync(UserAndUid userAndUid, SpiralAbyssSchedule schedule, CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
@@ -135,7 +122,7 @@ internal sealed partial class GameRecordClient : IGameRecordClient
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen2, SaltType.X4, false).ConfigureAwait(false);
Response<SpiralAbyss.SpiralAbyss>? resp = await builder
.TryCatchSendAsync<Response<SpiralAbyss.SpiralAbyss>>(httpClient, logger, token)
.TryCatchSendAsync<Response<SpiralAbyss.SpiralAbyss>>(httpClientFactory.CreateClient(nameof(GameRecordClient)), logger, token)
.ConfigureAwait(false);
// We have a verification procedure to handle
@@ -159,7 +146,7 @@ internal sealed partial class GameRecordClient : IGameRecordClient
await verifiedbuilder.SignDataAsync(DataSignAlgorithmVersion.Gen2, SaltType.X4, false).ConfigureAwait(false);
resp = await verifiedbuilder
.TryCatchSendAsync<Response<SpiralAbyss.SpiralAbyss>>(httpClient, logger, token)
.TryCatchSendAsync<Response<SpiralAbyss.SpiralAbyss>>(httpClientFactory.CreateClient(nameof(GameRecordClient)), logger, token)
.ConfigureAwait(false);
}
}
@@ -167,13 +154,6 @@ internal sealed partial class GameRecordClient : IGameRecordClient
return Response.Response.DefaultIfNull(resp);
}
/// <summary>
/// 异步获取角色基本信息
/// </summary>
/// <param name="userAndUid">用户与角色</param>
/// <param name="token">取消令牌</param>
/// <returns>角色基本信息</returns>
[ApiInformation(Cookie = CookieType.LToken, Salt = SaltType.X4)]
public async ValueTask<Response<BasicRoleInfo>> GetRoleBasicInfoAsync(UserAndUid userAndUid, CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
@@ -185,20 +165,12 @@ internal sealed partial class GameRecordClient : IGameRecordClient
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen2, SaltType.X4, false).ConfigureAwait(false);
Response<BasicRoleInfo>? resp = await builder
.TryCatchSendAsync<Response<BasicRoleInfo>>(httpClient, logger, token)
.TryCatchSendAsync<Response<BasicRoleInfo>>(httpClientFactory.CreateClient(nameof(GameRecordClient)), logger, token)
.ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
}
/// <summary>
/// 获取玩家角色详细信息
/// </summary>
/// <param name="userAndUid">用户与角色</param>
/// <param name="playerInfo">玩家的基础信息</param>
/// <param name="token">取消令牌</param>
/// <returns>角色列表</returns>
[ApiInformation(Cookie = CookieType.LToken, Salt = SaltType.X4)]
public async ValueTask<Response<CharacterWrapper>> GetCharactersAsync(UserAndUid userAndUid, PlayerInfo playerInfo, CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
@@ -210,7 +182,7 @@ internal sealed partial class GameRecordClient : IGameRecordClient
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen2, SaltType.X4, false).ConfigureAwait(false);
Response<CharacterWrapper>? resp = await builder
.TryCatchSendAsync<Response<CharacterWrapper>>(httpClient, logger, token)
.TryCatchSendAsync<Response<CharacterWrapper>>(httpClientFactory.CreateClient(nameof(GameRecordClient)), logger, token)
.ConfigureAwait(false);
// We have a verification procedure to handle
@@ -234,7 +206,7 @@ internal sealed partial class GameRecordClient : IGameRecordClient
await verifiedBuilder.SignDataAsync(DataSignAlgorithmVersion.Gen2, SaltType.X4, false).ConfigureAwait(false);
resp = await verifiedBuilder
.TryCatchSendAsync<Response<CharacterWrapper>>(httpClient, logger, token)
.TryCatchSendAsync<Response<CharacterWrapper>>(httpClientFactory.CreateClient(nameof(GameRecordClient)), logger, token)
.ConfigureAwait(false);
}
}