diff --git a/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteService.cs b/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteService.cs index 3add8387..37fca642 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteService.cs @@ -12,6 +12,7 @@ using Snap.Hutao.Model.Entity.Database; using Snap.Hutao.Service.Abstraction; using Snap.Hutao.Service.Game; using Snap.Hutao.Service.User; +using Snap.Hutao.Web.Hoyolab; using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord; using System.Collections.ObjectModel; using WebDailyNote = Snap.Hutao.Web.Hoyolab.Takumi.GameRecord.DailyNote.DailyNote; @@ -61,14 +62,27 @@ internal sealed class DailyNoteService : IDailyNoteService, IRecipient(); GameRecordClient gameRecordClient = scope.ServiceProvider.GetRequiredService(); + GameRecordClientOs gameRecordClientOs = scope.ServiceProvider.GetRequiredService(); if (!appDbContext.DailyNotes.Any(n => n.Uid == roleUid)) { DailyNoteEntry newEntry = DailyNoteEntry.Create(role); - Web.Response.Response dailyNoteResponse = await gameRecordClient + // 根据 Uid 的地区选择不同的 API + Web.Response.Response dailyNoteResponse; + PlayerUid playerUid = new(roleUid); + if (playerUid.Region == "cn_gf01" || playerUid.Region == "cn_qd01") + { + dailyNoteResponse = await gameRecordClient .GetDailyNoteAsync(role) .ConfigureAwait(false); + } + else + { + dailyNoteResponse = await gameRecordClientOs + .GetDailyNoteAsync(role) + .ConfigureAwait(false); + } if (dailyNoteResponse.IsOk()) { @@ -110,11 +124,13 @@ internal sealed class DailyNoteService : IDailyNoteService, IRecipient(); GameRecordClient gameRecordClient = scope.ServiceProvider.GetRequiredService(); + GameRecordClientOs gameRecordClientOs = scope.ServiceProvider.GetRequiredService(); bool isSilentMode = appDbContext.Settings .SingleOrAdd(SettingEntry.DailyNoteSilentWhenPlayingGame, Core.StringLiterals.False) .GetBoolean(); bool isGameRunning = scope.ServiceProvider.GetRequiredService().IsGameRunning(); + if (isSilentMode && isGameRunning) { // Prevent notify when we are in game && silent mode. @@ -123,9 +139,20 @@ internal sealed class DailyNoteService : IDailyNoteService, IRecipient n.User)) { - Web.Response.Response dailyNoteResponse = await gameRecordClient + Web.Response.Response dailyNoteResponse; + PlayerUid playerUid = new(entry.Uid); + if (playerUid.Region == "cn_gf01" || playerUid.Region == "cn_qd01") + { + dailyNoteResponse = await gameRecordClient .GetDailyNoteAsync(new(entry.User, entry.Uid)) .ConfigureAwait(false); + } + else + { + dailyNoteResponse = await gameRecordClientOs + .GetDailyNoteAsync(new(entry.User, entry.Uid)) + .ConfigureAwait(false); + } if (dailyNoteResponse.ReturnCode == 0) { diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/GameRecordClientOs.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/GameRecordClientOs.cs index 80bfddcf..63b25753 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/GameRecordClientOs.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/GameRecordClientOs.cs @@ -36,6 +36,24 @@ internal sealed class GameRecordClientOs this.logger = logger; } + /// + /// 异步获取实时便笺 + /// + /// 用户与角色 + /// 取消令牌 + /// 实时便笺 + [ApiInformation(Cookie = CookieType.Cookie, Salt = SaltType.OS)] + public async Task> GetDailyNoteAsync(UserAndUid userAndUid, CancellationToken token = default) + { + Response? resp = await httpClient + .SetUser(userAndUid.User, CookieType.Cookie) + .UseDynamicSecret(DynamicSecretVersion.Gen1, SaltType.OS, false) + .TryCatchGetFromJsonAsync>(ApiOsEndpoints.GameRecordDailyNote(userAndUid.Uid.Value), options, logger, token) + .ConfigureAwait(false); + + return Response.Response.DefaultIfNull(resp); + } + /// /// 获取玩家基础信息 ///