mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
impl #1112 (part 1)
This commit is contained in:
@@ -14,7 +14,8 @@ internal interface IAnnouncementService
|
||||
/// <summary>
|
||||
/// 异步获取游戏公告与活动,通常会进行缓存
|
||||
/// </summary>
|
||||
/// <param name="languageCode">语言代码</param>
|
||||
/// <param name="cancellationToken">取消令牌</param>
|
||||
/// <returns>公告包装器</returns>
|
||||
ValueTask<AnnouncementWrapper> GetAnnouncementWrapperAsync(CancellationToken cancellationToken = default);
|
||||
ValueTask<AnnouncementWrapper> GetAnnouncementWrapperAsync(string languageCode, CancellationToken cancellationToken = default);
|
||||
}
|
||||
@@ -25,7 +25,7 @@ internal sealed partial class AnnouncementService : IAnnouncementService
|
||||
private readonly IMemoryCache memoryCache;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async ValueTask<AnnouncementWrapper> GetAnnouncementWrapperAsync(CancellationToken cancellationToken = default)
|
||||
public async ValueTask<AnnouncementWrapper> GetAnnouncementWrapperAsync(string languageCode, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// 缓存中存在记录,直接返回
|
||||
if (memoryCache.TryGetRequiredValue(CacheKey, out AnnouncementWrapper? cache))
|
||||
@@ -35,7 +35,7 @@ internal sealed partial class AnnouncementService : IAnnouncementService
|
||||
|
||||
await taskContext.SwitchToBackgroundAsync();
|
||||
Response<AnnouncementWrapper> announcementWrapperResponse = await announcementClient
|
||||
.GetAnnouncementsAsync(cancellationToken)
|
||||
.GetAnnouncementsAsync(languageCode, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (!announcementWrapperResponse.IsOk())
|
||||
@@ -45,7 +45,7 @@ internal sealed partial class AnnouncementService : IAnnouncementService
|
||||
|
||||
AnnouncementWrapper wrapper = announcementWrapperResponse.Data;
|
||||
Response<ListWrapper<AnnouncementContent>> announcementContentResponse = await announcementClient
|
||||
.GetAnnouncementContentsAsync(cancellationToken)
|
||||
.GetAnnouncementContentsAsync(languageCode, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (!announcementContentResponse.IsOk())
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
using Snap.Hutao.Core.Setting;
|
||||
using Snap.Hutao.Service.Abstraction;
|
||||
using Snap.Hutao.Service.Hutao;
|
||||
using Snap.Hutao.Service.Metadata;
|
||||
using Snap.Hutao.View.Card;
|
||||
using Snap.Hutao.View.Card.Primitive;
|
||||
using Snap.Hutao.Web.Hoyolab.Hk4e.Common.Announcement;
|
||||
@@ -23,6 +24,7 @@ internal sealed partial class AnnouncementViewModel : Abstraction.ViewModel
|
||||
private readonly IAnnouncementService announcementService;
|
||||
private readonly HutaoUserOptions hutaoUserOptions;
|
||||
private readonly ITaskContext taskContext;
|
||||
private readonly MetadataOptions metadataOptions;
|
||||
|
||||
private AnnouncementWrapper? announcement;
|
||||
private string greetingText = SH.ViewPageHomeGreetingTextDefault;
|
||||
@@ -61,7 +63,7 @@ internal sealed partial class AnnouncementViewModel : Abstraction.ViewModel
|
||||
{
|
||||
try
|
||||
{
|
||||
AnnouncementWrapper announcementWrapper = await announcementService.GetAnnouncementWrapperAsync(CancellationToken).ConfigureAwait(false);
|
||||
AnnouncementWrapper announcementWrapper = await announcementService.GetAnnouncementWrapperAsync(metadataOptions.LanguageCode, CancellationToken).ConfigureAwait(false);
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
Announcement = announcementWrapper;
|
||||
}
|
||||
@@ -138,4 +140,4 @@ internal sealed partial class AnnouncementViewModel : Abstraction.ViewModel
|
||||
|
||||
Cards = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,6 +189,32 @@ internal static class ApiOsEndpoints
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Hk4eApiOsAnnouncementApi
|
||||
|
||||
/// <summary>
|
||||
/// 公告列表
|
||||
/// </summary>
|
||||
/// <param name="languageCode">语言代码</param>
|
||||
/// <param name="region">服务器</param>
|
||||
/// <returns>公告列表Url</returns>
|
||||
public static string AnnList(string languageCode, string region)
|
||||
{
|
||||
return $"{Hk4eApiOsAnnouncementApi}/getAnnList?{AnnouncementQuery(languageCode, region)}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 公告内容
|
||||
/// </summary>
|
||||
/// <param name="languageCode">语言代码</param>
|
||||
/// <param name="region">服务器</param>
|
||||
/// <returns>公告内容Url</returns>
|
||||
public static string AnnContent(string languageCode, string region)
|
||||
{
|
||||
return $"{Hk4eApiOsAnnouncementApi}/getAnnContent?{AnnouncementQuery(languageCode, region)}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SgPublicApi
|
||||
|
||||
/// <summary>
|
||||
@@ -307,6 +333,7 @@ internal static class ApiOsEndpoints
|
||||
private const string BbsApiOsGameRecordAppApi = $"{BbsApiOs}/game_record/app/genshin/api";
|
||||
|
||||
private const string Hk4eApiOs = "https://hk4e-api-os.hoyoverse.com";
|
||||
private const string Hk4eApiOsAnnouncementApi = $"{Hk4eApiOs}/common/hk4e_global/announcement/api";
|
||||
private const string Hk4eApiOsGachaInfoApi = $"{Hk4eApiOs}/gacha_info/api";
|
||||
|
||||
private const string SdkOsStatic = "https://sdk-os-static.mihoyo.com";
|
||||
@@ -333,5 +360,10 @@ internal static class ApiOsEndpoints
|
||||
/// </summary>
|
||||
public const string AppHoyolabReferer = "https://app.hoyolab.com/";
|
||||
|
||||
private static string AnnouncementQuery(string languageCode, string region)
|
||||
{
|
||||
return $"game=hk4e&game_biz=hk4e_global&lang={languageCode}&bundle_id=hk4e_global&platform=pc®ion={region}&level=55&uid=100000000";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -23,12 +23,16 @@ internal sealed partial class AnnouncementClient
|
||||
/// <summary>
|
||||
/// 异步获取公告列表
|
||||
/// </summary>
|
||||
/// <param name="languageCode">语言代码</param>
|
||||
/// <param name="token">取消令牌</param>
|
||||
/// <returns>公告列表</returns>
|
||||
public async ValueTask<Response<AnnouncementWrapper>> GetAnnouncementsAsync(CancellationToken token = default)
|
||||
public async ValueTask<Response<AnnouncementWrapper>> GetAnnouncementsAsync(string languageCode, CancellationToken token = default)
|
||||
{
|
||||
// ApiOsEndpoints.AnnList(languageCode, region)
|
||||
string annListUrl = ApiEndpoints.AnnList;
|
||||
|
||||
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
|
||||
.SetRequestUri(ApiEndpoints.AnnList)
|
||||
.SetRequestUri(annListUrl)
|
||||
.Get();
|
||||
|
||||
Response<AnnouncementWrapper>? resp = await builder
|
||||
@@ -41,12 +45,16 @@ internal sealed partial class AnnouncementClient
|
||||
/// <summary>
|
||||
/// 异步获取公告内容列表
|
||||
/// </summary>
|
||||
/// <param name="languageCode">语言代码</param>
|
||||
/// <param name="token">取消令牌</param>
|
||||
/// <returns>公告内容列表</returns>
|
||||
public async ValueTask<Response<ListWrapper<AnnouncementContent>>> GetAnnouncementContentsAsync(CancellationToken token = default)
|
||||
public async ValueTask<Response<ListWrapper<AnnouncementContent>>> GetAnnouncementContentsAsync(string languageCode, CancellationToken token = default)
|
||||
{
|
||||
// ApiOsEndpoints.AnnContent(languageCode, region)
|
||||
string annContentUrl = ApiEndpoints.AnnContent;
|
||||
|
||||
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
|
||||
.SetRequestUri(ApiEndpoints.AnnContent)
|
||||
.SetRequestUri(annContentUrl)
|
||||
.Get();
|
||||
|
||||
Response<ListWrapper<AnnouncementContent>>? resp = await builder
|
||||
|
||||
Reference in New Issue
Block a user