From e8a9542b32ed9c7dca47abdc446bd2766d0e85fa Mon Sep 17 00:00:00 2001 From: DismissedLight <1686188646@qq.com> Date: Sat, 3 Sep 2022 13:26:25 +0800 Subject: [PATCH] remove DS1 --- .../Core/Diagnostics/ValueStopwatch.cs | 14 +- .../Snap.Hutao/Core/Logging/DatebaseLogger.cs | 17 +- .../Core/Logging/DatebaseLoggerProvider.cs | 46 +----- .../Snap.Hutao/Core/Logging/LogEntryQueue.cs | 119 ++++++++++++++ .../Core/Windowing/WindowSubclassManager.cs | 1 + src/Snap.Hutao/Snap.Hutao/MainWindow.xaml.cs | 4 - src/Snap.Hutao/Snap.Hutao/Program.cs | 21 ++- .../Snap.Hutao/Properties/launchSettings.json | 2 +- .../Snap.Hutao/Service/Sign/ISignService.cs | 18 --- .../Snap.Hutao/Service/Sign/SignResult.cs | 37 ----- .../Snap.Hutao/Service/Sign/SignService.cs | 117 -------------- src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj | 3 + .../Snap.Hutao/ViewModel/UserViewModel.cs | 2 +- .../Web/Hoyolab/Bbs/User/UserClient.cs | 2 - .../DynamicSecret/DynamicSecretProvider.cs | 44 ----- .../DynamicSecret/DynamicSecretProvider2.cs | 13 +- ...tpClient.cs => DynamicSecretHttpClient.cs} | 12 +- ...pClient.cs => IDynamicSecretHttpClient.cs} | 4 +- .../HttpClientDynamicSecretExtensions.cs | 19 +-- .../Takumi/Event/BbsSignReward/Award.cs | 28 ---- .../Takumi/Event/BbsSignReward/Reward.cs | 28 ---- .../Takumi/Event/BbsSignReward/SignClient.cs | 151 ------------------ .../Takumi/Event/BbsSignReward/SignInData.cs | 38 ----- .../Event/BbsSignReward/SignInResult.cs | 41 ----- .../Event/BbsSignReward/SignInRewardInfo.cs | 52 ------ .../BbsSignReward/SignInRewardReSignInfo.cs | 58 ------- .../Takumi/Event/BbsSignReward/UserRole.cs | 34 ---- .../Takumi/GameRecord/GameRecordClient.cs | 6 +- .../Web/Response/KnownReturnCode.cs | 24 ++- .../Snap.Hutao/Web/Response/Response.cs | 10 ++ 30 files changed, 211 insertions(+), 754 deletions(-) create mode 100644 src/Snap.Hutao/Snap.Hutao/Core/Logging/LogEntryQueue.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Service/Sign/ISignService.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Service/Sign/SignResult.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Service/Sign/SignService.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/DynamicSecretProvider.cs rename src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/Http/{DynamicSecret2HttpClient.cs => DynamicSecretHttpClient.cs} (83%) rename src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/Http/{IDynamicSecret2HttpClient.cs => IDynamicSecretHttpClient.cs} (93%) delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/Award.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/Reward.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignClient.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignInData.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignInResult.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignInRewardInfo.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignInRewardReSignInfo.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/UserRole.cs diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Diagnostics/ValueStopwatch.cs b/src/Snap.Hutao/Snap.Hutao/Core/Diagnostics/ValueStopwatch.cs index 0a6ec2c7..f90b30d0 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Diagnostics/ValueStopwatch.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Diagnostics/ValueStopwatch.cs @@ -41,7 +41,7 @@ internal struct ValueStopwatch /// /// 经过的时间 /// 当前的停表未合理的初始化 - public TimeSpan GetElapsedTime() + public long GetElapsedTimestamp() { // Start timestamp can't be zero in an initialized ValueStopwatch. // It would have to be literally the first thing executed when the machine boots to be 0. @@ -52,6 +52,16 @@ internal struct ValueStopwatch long timestampDelta = end - startTimestamp; long ticks = (long)(TimestampToTicks * timestampDelta); - return new TimeSpan(ticks); + return ticks; + } + + /// + /// 获取经过的时间 + /// + /// 经过的时间 + /// 当前的停表未合理的初始化 + public TimeSpan GetElapsedTime() + { + return new TimeSpan(GetElapsedTimestamp()); } } diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Logging/DatebaseLogger.cs b/src/Snap.Hutao/Snap.Hutao/Core/Logging/DatebaseLogger.cs index cceeef1b..26988044 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Logging/DatebaseLogger.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Logging/DatebaseLogger.cs @@ -11,8 +11,7 @@ namespace Snap.Hutao.Core.Logging; internal sealed partial class DatebaseLogger : ILogger { private readonly string name; - private readonly LogDbContext logDbContext; - private readonly object logDbContextLock; + private readonly LogEntryQueue logEntryQueue; /// /// Initializes a new instance of the class. @@ -20,11 +19,10 @@ internal sealed partial class DatebaseLogger : ILogger /// The name of the logger. /// 应用程序数据库上下文 /// 上下文锁 - public DatebaseLogger(string name, LogDbContext logDbContext, object logDbContextLock) + public DatebaseLogger(string name, LogEntryQueue logEntryQueue) { this.name = name; - this.logDbContext = logDbContext; - this.logDbContextLock = logDbContextLock; + this.logEntryQueue = logEntryQueue; } /// @@ -47,7 +45,7 @@ internal sealed partial class DatebaseLogger : ILogger return; } - string message = Must.NotNull(formatter)(state, exception); + string message = formatter(state, exception); if (string.IsNullOrEmpty(message)) { @@ -63,12 +61,7 @@ internal sealed partial class DatebaseLogger : ILogger Exception = exception?.ToString(), }; - // DbContext is not a thread safe class, so we have to lock the wirte procedure - lock (logDbContextLock) - { - logDbContext.Logs.Add(entry); - logDbContext.SaveChanges(); - } + logEntryQueue.Enqueue(entry); } /// diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Logging/DatebaseLoggerProvider.cs b/src/Snap.Hutao/Snap.Hutao/Core/Logging/DatebaseLoggerProvider.cs index 50601e68..3aabd840 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Logging/DatebaseLoggerProvider.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Logging/DatebaseLoggerProvider.cs @@ -1,12 +1,6 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. -using Microsoft.EntityFrameworkCore; -using Snap.Hutao.Context.Database; -using Snap.Hutao.Context.FileSystem; -using System.Diagnostics; -using System.Linq; - namespace Snap.Hutao.Core.Logging; /// @@ -15,49 +9,17 @@ namespace Snap.Hutao.Core.Logging; [ProviderAlias("Database")] public sealed class DatebaseLoggerProvider : ILoggerProvider { - private static readonly object LogDbContextLock = new(); - - // the provider is created per logger, we don't want to create too much - private static volatile LogDbContext? logDbContext; - - private static LogDbContext LogDbContext - { - get - { - if (logDbContext == null) - { - lock (LogDbContextLock) - { - // prevent re-entry call - if (logDbContext == null) - { - HutaoContext myDocument = new(new()); - logDbContext = LogDbContext.Create($"Data Source={myDocument.Locate("Log.db")}"); - if (logDbContext.Database.GetPendingMigrations().Any()) - { - Debug.WriteLine("[Debug] Performing LogDbContext Migrations"); - logDbContext.Database.Migrate(); - } - - logDbContext.Logs.RemoveRange(logDbContext.Logs); - logDbContext.SaveChanges(); - } - } - } - - return logDbContext; - } - } + private readonly LogEntryQueue logEntryQueue = new(); /// public ILogger CreateLogger(string name) { - return new DatebaseLogger(name, LogDbContext, LogDbContextLock); + return new DatebaseLogger(name, logEntryQueue); } /// public void Dispose() { - LogDbContext.Dispose(); + logEntryQueue.Dispose(); } -} +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Logging/LogEntryQueue.cs b/src/Snap.Hutao/Snap.Hutao/Core/Logging/LogEntryQueue.cs new file mode 100644 index 00000000..bacdacbd --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Core/Logging/LogEntryQueue.cs @@ -0,0 +1,119 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +using Microsoft.EntityFrameworkCore; +using Snap.Hutao.Context.Database; +using Snap.Hutao.Context.FileSystem; +using System.Collections.Concurrent; +using System.Diagnostics; +using System.Linq; + +namespace Snap.Hutao.Core.Logging; + +/// +/// 日志队列 +/// +public sealed class LogEntryQueue : IDisposable +{ + private static readonly object LogDbContextCreationLock = new(); + + private readonly ConcurrentQueue entryQueue = new(); + private readonly CancellationTokenSource disposeCancellationTokenSource = new(); + private readonly TaskCompletionSource writeDbTaskCompletionSource = new(); + + // the provider is created per logger, we don't want to create too much + private volatile LogDbContext? logDbContext; + + /// + /// 构造一个新的日志队列 + /// + public LogEntryQueue() + { + Execute(); + } + + private LogDbContext LogDbContext + { + get + { + if (logDbContext == null) + { + lock (LogDbContextCreationLock) + { + // prevent re-entry call + if (logDbContext == null) + { + HutaoContext myDocument = new(new()); + logDbContext = LogDbContext.Create($"Data Source={myDocument.Locate("Log.db")}"); + if (logDbContext.Database.GetPendingMigrations().Any()) + { + Debug.WriteLine("[Debug] Performing LogDbContext Migrations"); + logDbContext.Database.Migrate(); + } + + logDbContext.Logs.RemoveRange(logDbContext.Logs); + logDbContext.SaveChanges(); + } + } + } + + return logDbContext; + } + } + + /// + /// 将日志消息存入队列 + /// + /// 日志 + public void Enqueue(LogEntry logEntry) + { + entryQueue.Enqueue(logEntry); + } + + /// + [SuppressMessage("", "VSTHRD002")] + public void Dispose() + { + disposeCancellationTokenSource.Cancel(); + writeDbTaskCompletionSource.Task.GetAwaiter().GetResult(); + + LogDbContext.Dispose(); + } + + [SuppressMessage("", "VSTHRD100")] + private async void Execute() + { + await Task.Run(async () => await ExecuteCoreAsync(disposeCancellationTokenSource.Token)); + } + + private async Task ExecuteCoreAsync(CancellationToken token) + { + bool hasAdded = false; + while (true) + { + if (entryQueue.TryDequeue(out LogEntry? logEntry)) + { + LogDbContext.Logs.Add(logEntry); + hasAdded = true; + } + else + { + if (hasAdded) + { + LogDbContext.SaveChanges(); + hasAdded = false; + } + + if (token.IsCancellationRequested) + { + writeDbTaskCompletionSource.TrySetResult(); + break; + } + + await Task + .Delay(1000, CancellationToken.None) + .ConfigureAwait(false); + } + } + } +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowSubclassManager.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowSubclassManager.cs index b7153dc7..4874d8d8 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowSubclassManager.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowSubclassManager.cs @@ -1,6 +1,7 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. +using System.Diagnostics; using Windows.Win32.Foundation; using Windows.Win32.UI.Shell; using static Windows.Win32.PInvoke; diff --git a/src/Snap.Hutao/Snap.Hutao/MainWindow.xaml.cs b/src/Snap.Hutao/Snap.Hutao/MainWindow.xaml.cs index 91eb5612..1f196e64 100644 --- a/src/Snap.Hutao/Snap.Hutao/MainWindow.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/MainWindow.xaml.cs @@ -42,9 +42,5 @@ public sealed partial class MainWindow : Window messenger.Send(new MainWindowClosedMessage()); windowManager?.Dispose(); - - // save userdata datebase - int changes = appDbContext.SaveChanges(); - Verify.Operation(changes == 0, "存在未经处理的数据库记录更改"); } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Program.cs b/src/Snap.Hutao/Snap.Hutao/Program.cs index 6fb20333..c54d55aa 100644 --- a/src/Snap.Hutao/Snap.Hutao/Program.cs +++ b/src/Snap.Hutao/Snap.Hutao/Program.cs @@ -39,11 +39,13 @@ public static class Program XamlCheckProcessRequirements(); ComWrappersSupport.InitializeComWrappers(); - InitializeDependencyInjection(); - - // In a Desktop app this runs a message pump internally, - // and does not return until the application shuts down. - Application.Start(InitializeApp); + // by adding the using statement, we can dispose the injected services when we closing + using (InitializeDependencyInjection()) + { + // In a Desktop app this runs a message pump internally, + // and does not return until the application shuts down. + Application.Start(InitializeApp); + } } private static void InitializeApp(ApplicationInitializationCallbackParams param) @@ -55,9 +57,13 @@ public static class Program _ = Ioc.Default.GetRequiredService(); } - private static void InitializeDependencyInjection() + /// + /// 初始化依赖注入 + /// + /// The ServiceProvider, so that we can dispose it. + private static ServiceProvider InitializeDependencyInjection() { - IServiceProvider services = new ServiceCollection() + ServiceProvider services = new ServiceCollection() // Microsoft extension .AddLogging(builder => builder @@ -78,5 +84,6 @@ public static class Program .BuildServiceProvider(); Ioc.Default.ConfigureServices(services); + return services; } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Properties/launchSettings.json b/src/Snap.Hutao/Snap.Hutao/Properties/launchSettings.json index b8b51163..dc55a580 100644 --- a/src/Snap.Hutao/Snap.Hutao/Properties/launchSettings.json +++ b/src/Snap.Hutao/Snap.Hutao/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Snap.Hutao (Package)": { "commandName": "MsixPackage", - "nativeDebugging": true + "nativeDebugging": false }, "Snap.Hutao (Unpackaged)": { "commandName": "Project" diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Sign/ISignService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Sign/ISignService.cs deleted file mode 100644 index ffb62d82..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Service/Sign/ISignService.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Service.Sign; - -/// -/// 签到服务 -/// -[Obsolete("米游社官方限制了签到功能")] -public interface ISignService -{ - /// - /// 异步全部签到 - /// - /// 取消令牌 - /// 任务 - Task SignForAllAsync(CancellationToken token); -} diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Sign/SignResult.cs b/src/Snap.Hutao/Snap.Hutao/Service/Sign/SignResult.cs deleted file mode 100644 index 621f6fb6..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Service/Sign/SignResult.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Service.Sign; - -/// -/// 签到操作结果 -/// -public struct SignResult -{ - /// - /// 构造一个新的签到操作结果 - /// - /// 总次数 - /// 重试次数 - public SignResult(int totalCount, int retryCount, TimeSpan time) - { - TotalCount = totalCount; - RetryCount = retryCount; - Time = time; - } - - /// - /// 总次数 - /// - public int TotalCount { get; set; } - - /// - /// 重试次数 - /// - public int RetryCount { get; set; } - - /// - /// 用时 - /// - public TimeSpan Time { get; set; } -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Sign/SignService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Sign/SignService.cs deleted file mode 100644 index fb268991..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Service/Sign/SignService.cs +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -using Snap.Hutao.Core.Diagnostics; -using Snap.Hutao.Service.Abstraction; -using Snap.Hutao.Web.Hoyolab.Takumi.Binding; -using Snap.Hutao.Web.Hoyolab.Takumi.Event.BbsSignReward; -using Snap.Hutao.Web.Response; - -namespace Snap.Hutao.Service.Sign; - -/// -/// 签到服务 -/// -[Obsolete("米游社官方限制了签到功能")] -[Injection(InjectAs.Transient, typeof(ISignService))] -internal class SignService : ISignService -{ - private readonly IUserService userService; - private readonly IInfoBarService infoBarService; - private readonly SignClient signClient; - - /// - /// 构造一个新的签到服务 - /// - /// 用户服务 - /// 信息条服务 - /// 签到客户端 - public SignService(IUserService userService, IInfoBarService infoBarService, SignClient signClient) - { - this.userService = userService; - this.infoBarService = infoBarService; - this.signClient = signClient; - } - - /// - public async Task SignForAllAsync(CancellationToken token) - { - IEnumerable? users = await userService - .GetUserCollectionAsync() - .ConfigureAwait(false); - Queue userRolesQueue = GetSignQueue(users); - - int totalCount = 0; - int retryCount = 0; - ValueStopwatch stopwatch = ValueStopwatch.StartNew(); - - while (userRolesQueue.TryDequeue(out UserRole current)) - { - totalCount++; - Response? resp = await signClient - .SignAsync(current, token) - .ConfigureAwait(false); - - Must.NotNull(resp!); - - if (resp.Data != null) - { - Must.Argument(resp.ReturnCode == 0, "返回代码应为 0"); - - // Geetest applied - if (resp.Data.Success != 0) - { - userRolesQueue.Enqueue(current); - retryCount++; - } - else - { - infoBarService.Information($"[{current.Role}] 签到成功"); - } - } - else - { - switch ((KnownReturnCode)resp.ReturnCode) - { - case KnownReturnCode.OK: - infoBarService.Information($"[{current.Role}] 签到成功"); - break; - case KnownReturnCode.NotLoggedIn: - case KnownReturnCode.AlreadySignedIn: - infoBarService.Information($"[{current.Role}] {resp.Message}"); - break; - case KnownReturnCode.InvalidRequest: - infoBarService.Information("米游社SALT过期,请更新胡桃"); - break; - default: - throw Must.NeverHappen(); - } - } - - if (userRolesQueue.Count > 0) - { - int seconds = Random.Shared.Next(5, 15); - await Task - .Delay(TimeSpan.FromSeconds(seconds), token) - .ConfigureAwait(false); - } - } - - return new(totalCount, retryCount, stopwatch.GetElapsedTime()); - } - - private static Queue GetSignQueue(IEnumerable users) - { - Queue queue = new(); - - foreach (Model.Binding.User user in users) - { - foreach (UserGameRole role in user.UserGameRoles) - { - queue.Enqueue(new(user, role)); - } - } - - return queue; - } -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj b/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj index 7f19414f..eeb1106a 100644 --- a/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj +++ b/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj @@ -193,4 +193,7 @@ MSBuild:Compile + + + diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/UserViewModel.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/UserViewModel.cs index 119ecc69..5cb64e6a 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/UserViewModel.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/UserViewModel.cs @@ -176,7 +176,7 @@ internal class UserViewModel : ObservableObject DataPackage content = new(); content.SetText(Must.NotNull(user.Cookie!)); Clipboard.SetContent(content); - + Clipboard.Flush(); infoBarService.Success($"{user.UserInfo!.Nickname} 的 Cookie 复制成功"); } catch (Exception e) diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Bbs/User/UserClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Bbs/User/UserClient.cs index aa57db0d..1a497979 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Bbs/User/UserClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Bbs/User/UserClient.cs @@ -38,7 +38,6 @@ internal class UserClient public async Task GetUserFullInfoAsync(Model.Binding.User user, CancellationToken token = default) { Response? resp = await httpClient - .UsingDynamicSecret() .SetUser(user) .GetFromJsonAsync>(ApiEndpoints.UserFullInfo, jsonSerializerOptions, token) .ConfigureAwait(false); @@ -56,7 +55,6 @@ internal class UserClient public async Task GetUserFullInfoAsync(Model.Binding.User user, string uid, CancellationToken token = default) { Response? resp = await httpClient - .UsingDynamicSecret() .SetUser(user) .GetFromJsonAsync>(ApiEndpoints.UserFullInfoQuery(uid), jsonSerializerOptions, token) .ConfigureAwait(false); diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/DynamicSecretProvider.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/DynamicSecretProvider.cs deleted file mode 100644 index 44971748..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/DynamicSecretProvider.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -using Snap.Hutao.Core.Convert; -using System.Text; - -namespace Snap.Hutao.Web.Hoyolab.DynamicSecret; - -/// -/// 为MiHoYo接口请求器 提供动态密钥 -/// -internal abstract class DynamicSecretProvider : Md5Convert -{ - private const string RandomRange = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; - - /// - /// 创建动态密钥 - /// - /// 密钥 - public static string Create() - { - // unix timestamp - long t = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); - - string r = GetRandomString(); - - string check = ToHexString($"salt={Core.CoreEnvironment.DynamicSecret1Salt}&t={t}&r={r}").ToLowerInvariant(); - - return $"{t},{r},{check}"; - } - - private static string GetRandomString() - { - StringBuilder sb = new(6); - - for (int i = 0; i < 6; i++) - { - int pos = Random.Shared.Next(0, RandomRange.Length); - sb.Append(RandomRange[pos]); - } - - return sb.ToString(); - } -} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/DynamicSecretProvider2.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/DynamicSecretProvider2.cs index 9f605926..197bf6ce 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/DynamicSecretProvider2.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/DynamicSecretProvider2.cs @@ -9,7 +9,7 @@ namespace Snap.Hutao.Web.Hoyolab.DynamicSecret; /// /// 为MiHoYo接口请求器 提供2代动态密钥 /// -internal abstract class DynamicSecretProvider2 : Md5Convert +internal abstract class DynamicSecretProvider : Md5Convert { /// /// 创建动态密钥 @@ -24,7 +24,7 @@ internal abstract class DynamicSecretProvider2 : Md5Convert long t = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); // random - string r = GetRandomString(); + int r = GetRandom(); // body string b = postBody is null ? string.Empty : JsonSerializer.Serialize(postBody, options); @@ -38,7 +38,7 @@ internal abstract class DynamicSecretProvider2 : Md5Convert return $"{t},{r},{check}"; } - private static string GetRandomString() + private static int GetRandom() { // 原汁原味 // v16 = time(0LL); @@ -49,11 +49,6 @@ internal abstract class DynamicSecretProvider2 : Md5Convert // else // v18 = v17 + 542367; int rand = Random.Shared.Next(100000, 200000); - if (rand == 100000) - { - rand = 642367; - } - - return rand.ToString(); + return rand == 100000 ? 642367 : rand; } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/Http/DynamicSecret2HttpClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/Http/DynamicSecretHttpClient.cs similarity index 83% rename from src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/Http/DynamicSecret2HttpClient.cs rename to src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/Http/DynamicSecretHttpClient.cs index 9f4bd3fa..61c9088f 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/Http/DynamicSecret2HttpClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/Http/DynamicSecretHttpClient.cs @@ -10,7 +10,7 @@ namespace Snap.Hutao.Web.Hoyolab.DynamicSecret.Http; /// 使用动态密钥2的Http客户端默认实现 /// /// 请求提交的数据的的格式 -internal class DynamicSecret2HttpClient : IDynamicSecret2HttpClient +internal class DynamicSecretHttpClient : IDynamicSecretHttpClient { private readonly HttpClient httpClient; private readonly JsonSerializerOptions options; @@ -23,13 +23,13 @@ internal class DynamicSecret2HttpClient : IDynamicSecret2HttpClient /// Json序列化选项 /// url /// 请求的数据 - public DynamicSecret2HttpClient(HttpClient httpClient, JsonSerializerOptions options, string url) + public DynamicSecretHttpClient(HttpClient httpClient, JsonSerializerOptions options, string url) { this.httpClient = httpClient; this.options = options; this.url = url; - httpClient.DefaultRequestHeaders.Set("DS", DynamicSecretProvider2.Create(options, url, null)); + httpClient.DefaultRequestHeaders.Set("DS", DynamicSecretProvider.Create(options, url, null)); } /// @@ -44,7 +44,7 @@ internal class DynamicSecret2HttpClient : IDynamicSecret2HttpClient /// /// 请求提交的数据的的格式 [SuppressMessage("", "SA1402")] -internal class DynamicSecret2HttpClient : IDynamicSecret2HttpClient +internal class DynamicSecretHttpClient : IDynamicSecretHttpClient where TValue : class { private readonly HttpClient httpClient; @@ -59,14 +59,14 @@ internal class DynamicSecret2HttpClient : IDynamicSecret2HttpClientJson序列化选项 /// url /// 请求的数据 - public DynamicSecret2HttpClient(HttpClient httpClient, JsonSerializerOptions options, string url, TValue? data) + public DynamicSecretHttpClient(HttpClient httpClient, JsonSerializerOptions options, string url, TValue? data) { this.httpClient = httpClient; this.options = options; this.url = url; this.data = data; - httpClient.DefaultRequestHeaders.Set("DS", DynamicSecretProvider2.Create(options, url, data)); + httpClient.DefaultRequestHeaders.Set("DS", DynamicSecretProvider.Create(options, url, data)); } /// diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/Http/IDynamicSecret2HttpClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/Http/IDynamicSecretHttpClient.cs similarity index 93% rename from src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/Http/IDynamicSecret2HttpClient.cs rename to src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/Http/IDynamicSecretHttpClient.cs index ddfe3376..3231d907 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/Http/IDynamicSecret2HttpClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/Http/IDynamicSecretHttpClient.cs @@ -8,7 +8,7 @@ namespace Snap.Hutao.Web.Hoyolab.DynamicSecret.Http; /// /// 使用动态密钥2的Http客户端抽象 /// -internal interface IDynamicSecret2HttpClient +internal interface IDynamicSecretHttpClient { /// /// Sends a GET request to the specified Uri and returns the value that results from deserializing the response body as JSON in an asynchronous operation. @@ -23,7 +23,7 @@ internal interface IDynamicSecret2HttpClient /// 使用动态密钥2的Http客户端抽象 /// /// 请求数据的类型 -internal interface IDynamicSecret2HttpClient +internal interface IDynamicSecretHttpClient where TValue : class { /// diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/HttpClientDynamicSecretExtensions.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/HttpClientDynamicSecretExtensions.cs index 69deb591..40e03aa3 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/HttpClientDynamicSecretExtensions.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/DynamicSecret/HttpClientDynamicSecretExtensions.cs @@ -11,17 +11,6 @@ namespace Snap.Hutao.Web.Hoyolab.DynamicSecret; /// internal static class HttpClientDynamicSecretExtensions { - /// - /// 使用动态密钥执行 GET 操作 - /// - /// 请求器 - /// 响应 - public static HttpClient UsingDynamicSecret(this HttpClient httpClient) - { - httpClient.DefaultRequestHeaders.Set("DS", DynamicSecretProvider.Create()); - return httpClient; - } - /// /// 使用二代动态密钥执行 GET 操作 /// @@ -29,9 +18,9 @@ internal static class HttpClientDynamicSecretExtensions /// 选项 /// 地址 /// 响应 - public static IDynamicSecret2HttpClient UsingDynamicSecret2(this HttpClient httpClient, JsonSerializerOptions options, string url) + public static IDynamicSecretHttpClient UsingDynamicSecret(this HttpClient httpClient, JsonSerializerOptions options, string url) { - return new DynamicSecret2HttpClient(httpClient, options, url); + return new DynamicSecretHttpClient(httpClient, options, url); } /// @@ -43,9 +32,9 @@ internal static class HttpClientDynamicSecretExtensions /// 地址 /// post数据 /// 响应 - public static IDynamicSecret2HttpClient UsingDynamicSecret2(this HttpClient httpClient, JsonSerializerOptions options, string url, TValue data) + public static IDynamicSecretHttpClient UsingDynamicSecret(this HttpClient httpClient, JsonSerializerOptions options, string url, TValue data) where TValue : class { - return new DynamicSecret2HttpClient(httpClient, options, url, data); + return new DynamicSecretHttpClient(httpClient, options, url, data); } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/Award.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/Award.cs deleted file mode 100644 index c0da2cfd..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/Award.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.BbsSignReward; - -/// -/// 奖励物品 -/// -public class Award -{ - /// - /// 图标 - /// - [JsonPropertyName("icon")] - public string Icon { get; set; } = default!; - - /// - /// 名称 - /// - [JsonPropertyName("name")] - public string Name { get; set; } = default!; - - /// - /// 个数 - /// - [JsonPropertyName("cnt")] - public string Count { get; set; } = default!; -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/Reward.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/Reward.cs deleted file mode 100644 index 6a32974d..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/Reward.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.BbsSignReward; - -/// -/// 奖励 -/// -public class Reward -{ - /// - /// 月份 - /// - [JsonPropertyName("month")] - public string? Month { get; set; } - - /// - /// 奖励列表 - /// - [JsonPropertyName("awards")] - public List? Awards { get; set; } - - /// - /// 支持补签 - /// - [JsonPropertyName("resign")] - public bool Resign { get; set; } -} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignClient.cs deleted file mode 100644 index 9e030d3b..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignClient.cs +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -using Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient; -using Snap.Hutao.Model.Binding; -using Snap.Hutao.Web.Hoyolab.DynamicSecret; -using Snap.Hutao.Web.Hoyolab.Takumi.Binding; -using Snap.Hutao.Web.Response; -using System.Net.Http; -using System.Net.Http.Json; - -namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.BbsSignReward; - -/// -/// 签到客户端 -/// -[HttpClient(HttpClientConfigration.XRpc)] -internal class SignClient -{ - private readonly HttpClient httpClient; - private readonly JsonSerializerOptions options; - - /// - /// 构造一个新的签到客户端 - /// - /// http客户端 - /// 选项 - public SignClient(HttpClient httpClient, JsonSerializerOptions options) - { - this.httpClient = httpClient; - this.options = options; - } - - /// - /// 异步获取签到信息 - /// - /// 用户 - /// 角色 - /// 取消令牌 - /// 签到信息 - public async Task GetInfoAsync(User user, UserGameRole role, CancellationToken token = default) - { - Response? resp = await httpClient - .SetUser(user) - .UsingDynamicSecret() - .GetFromJsonAsync>(ApiEndpoints.SignInRewardInfo((PlayerUid)role), options, token) - .ConfigureAwait(false); - - return resp?.Data; - } - - /// - /// 异步获取签到信息 - /// - /// 用户 - /// 角色 - /// 取消令牌 - /// 签到信息 - public async Task GetResignInfoAsync(User user, UserGameRole role, CancellationToken token = default) - { - Response? resp = await httpClient - .SetUser(user) - .UsingDynamicSecret() - .GetFromJsonAsync>(ApiEndpoints.SignInRewardResignInfo((PlayerUid)role), options, token) - .ConfigureAwait(false); - - return resp?.Data; - } - - /// - /// 获取签到奖励 - /// - /// 用户 - /// 取消令牌 - /// 奖励信息 - public async Task GetRewardAsync(User user, CancellationToken token = default) - { - Response? resp = await httpClient - .SetUser(user) - .GetFromJsonAsync>(ApiEndpoints.SignInRewardHome, options, token) - .ConfigureAwait(false); - - return resp?.Data; - } - - /// - /// 补签 - /// - /// 用户角色 - /// 取消令牌 - /// 签到结果 - public Task?> ReSignAsync(UserRole userRole, CancellationToken token = default) - { - return ReSignAsync(userRole.User, userRole.Role, token); - } - - /// - /// 补签 - /// - /// 用户 - /// 角色 - /// 取消令牌 - /// 签到消息 - public async Task?> ReSignAsync(User user, UserGameRole role, CancellationToken token = default) - { - SignInData data = new((PlayerUid)role); - - HttpResponseMessage response = await httpClient - .SetUser(user) - .UsingDynamicSecret() - .PostAsJsonAsync(ApiEndpoints.SignInRewardReSign, data, options, token) - .ConfigureAwait(false); - Response? resp = await response.Content - .ReadFromJsonAsync>(options, token) - .ConfigureAwait(false); - - return resp; - } - - /// - /// 签到 - /// - /// 用户角色 - /// 取消令牌 - /// 签到结果 - public Task?> SignAsync(UserRole userRole, CancellationToken token = default) - { - return SignAsync(userRole.User, userRole.Role, token); - } - - /// - /// 签到 - /// - /// 用户 - /// 角色 - /// 取消令牌 - /// 签到结果 - public async Task?> SignAsync(User user, UserGameRole role, CancellationToken token = default) - { - HttpResponseMessage response = await httpClient - .SetUser(user) - .UsingDynamicSecret() - .PostAsJsonAsync(ApiEndpoints.SignInRewardSign, new SignInData((PlayerUid)role), options, token) - .ConfigureAwait(false); - Response? resp = await response.Content - .ReadFromJsonAsync>(options, token) - .ConfigureAwait(false); - - return resp; - } -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignInData.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignInData.cs deleted file mode 100644 index b09418b3..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignInData.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.BbsSignReward; - -/// -/// 签到提交数据 -/// -public class SignInData -{ - /// - /// 构造一个新的签到提交数据 - /// - /// uid - public SignInData(PlayerUid uid) - { - Region = uid.Region; - Uid = uid.Value; - } - - /// - /// 活动Id - /// - [JsonPropertyName("act_id")] - public string ActivityId { get; } = ApiEndpoints.SignInRewardActivityId; - - /// - /// 地区代码 - /// - [JsonPropertyName("region")] - public string Region { get; } - - /// - /// Uid - /// - [JsonPropertyName("uid")] - public string Uid { get; } -} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignInResult.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignInResult.cs deleted file mode 100644 index 30267896..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignInResult.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.BbsSignReward; - -/// -/// 签到结果 -/// https://docs.geetest.com/sensebot/apirefer/api/server -/// -public class SignInResult -{ - /// - /// ??? - /// - [JsonPropertyName("code")] - public string Code { get; set; } = default!; - - /// - /// 风控码 375 - /// - [JsonPropertyName("risk_code")] - public int RiskCode { get; set; } - - /// - /// geetest appid - /// - [JsonPropertyName("gt")] - public string Gt { get; set; } = default!; - - /// - /// geetest challenge id - /// - [JsonPropertyName("challenge")] - public string Challenge { get; set; } = default!; - - /// - /// geetest 服务状态 - /// - [JsonPropertyName("success")] - public int Success { get; set; } -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignInRewardInfo.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignInRewardInfo.cs deleted file mode 100644 index f35bdfba..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignInRewardInfo.cs +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.BbsSignReward; - -/// -/// 签到信息 -/// -public class SignInRewardInfo -{ - /// - /// 累积签到天数 - /// - [JsonPropertyName("total_sign_day")] - public int TotalSignDay { get; set; } - - /// - /// yyyy-MM-dd - /// - [JsonPropertyName("today")] - public string? Today { get; set; } - - /// - /// 今日是否已签到 - /// - [JsonPropertyName("is_sign")] - public bool IsSign { get; set; } - - /// - /// ? - /// - [JsonPropertyName("is_sub")] - public bool IsSub { get; set; } - - /// - /// 是否首次绑定 - /// - [JsonPropertyName("first_bind")] - public bool FirstBind { get; set; } - - /// - /// 是否为当月第一次 - /// - [JsonPropertyName("month_first")] - public bool MonthFirst { get; set; } - - /// - /// 漏签天数 - /// - [JsonPropertyName("sign_cnt_missed")] - public bool SignCountMissed { get; set; } -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignInRewardReSignInfo.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignInRewardReSignInfo.cs deleted file mode 100644 index 3276f6fb..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/SignInRewardReSignInfo.cs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.BbsSignReward; - -/// -/// 补签说明 -/// -public class SignInRewardReSignInfo -{ - /// - /// 当日补签次数 - /// - [JsonPropertyName("resign_cnt_daily")] - public bool ResignCountDaily { get; set; } - - /// - /// 当月补签次数 - /// - [JsonPropertyName("resign_cnt_monthly")] - public bool ResignCountMonthly { get; set; } - - /// - /// 当日补签次数限制 - /// - [JsonPropertyName("resign_limit_daily")] - public bool ResignLimitDaily { get; set; } - - /// - /// 当月补签次数限制 - /// - [JsonPropertyName("resign_limit_monthly")] - public bool ResignLimitMonthly { get; set; } - - /// - /// 漏签次数 - /// - [JsonPropertyName("sign_cnt_missed")] - public bool SignCountMissed { get; set; } - - /// - /// 米游币个数 - /// - [JsonPropertyName("coin_cnt")] - public bool CoinCount { get; set; } - - /// - /// 补签需要的米游币个数 - /// - [JsonPropertyName("coin_cost")] - public bool CoinCost { get; set; } - - /// - /// 规则 - /// - [JsonPropertyName("rule")] - public string Rule { get; set; } = default!; -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/UserRole.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/UserRole.cs deleted file mode 100644 index 31787898..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Event/BbsSignReward/UserRole.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -using Snap.Hutao.Model.Binding; -using Snap.Hutao.Web.Hoyolab.Takumi.Binding; - -namespace Snap.Hutao.Web.Hoyolab.Takumi.Event.BbsSignReward; - -/// -/// 将用户与角色捆绑在一起 -/// -public struct UserRole -{ - /// - /// 构造一个新的用户角色 - /// - /// 用户 - /// 角色 - public UserRole(User user, UserGameRole role) - { - User = user; - Role = role; - } - - /// - /// 用户 - /// - public User User { get; set; } - - /// - /// 角色 - /// - public UserGameRole Role { get; set; } -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/GameRecordClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/GameRecordClient.cs index 948bd50e..8f222e40 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/GameRecordClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/GameRecordClient.cs @@ -56,7 +56,7 @@ internal class GameRecordClient { Response? resp = await httpClient .SetUser(user) - .UsingDynamicSecret2(jsonSerializerOptions, ApiEndpoints.GameRecordIndex(uid.Value, uid.Region)) + .UsingDynamicSecret(jsonSerializerOptions, ApiEndpoints.GameRecordIndex(uid.Value, uid.Region)) .GetFromJsonAsync>(token) .ConfigureAwait(false); @@ -88,7 +88,7 @@ internal class GameRecordClient { Response? resp = await httpClient .SetUser(user) - .UsingDynamicSecret2(jsonSerializerOptions, ApiEndpoints.GameRecordSpiralAbyss(schedule, uid)) + .UsingDynamicSecret(jsonSerializerOptions, ApiEndpoints.GameRecordSpiralAbyss(schedule, uid)) .GetFromJsonAsync>(token) .ConfigureAwait(false); @@ -122,7 +122,7 @@ internal class GameRecordClient HttpResponseMessage? response = await httpClient .SetUser(user) - .UsingDynamicSecret2(jsonSerializerOptions, ApiEndpoints.GameRecordCharacter, data) + .UsingDynamicSecret(jsonSerializerOptions, ApiEndpoints.GameRecordCharacter, data) .PostAsJsonAsync(token) .ConfigureAwait(false); diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Response/KnownReturnCode.cs b/src/Snap.Hutao/Snap.Hutao/Web/Response/KnownReturnCode.cs index cff37291..dcfde2fe 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Response/KnownReturnCode.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Response/KnownReturnCode.cs @@ -18,10 +18,30 @@ public enum KnownReturnCode : int /// AlreadySignedIn = -5003, + /// + /// 需要风险验证 + /// + RET_NEED_RISK_VERIFY = -3235, + + /// + /// 禁止 + /// + RET_AIGIS_FAILED = -3202, + + /// + /// Ban + /// + RET_BAN = -3201, + + /// + /// 需要地理验证 + /// + RET_NEED_AIGIS = -3101, + /// /// 尚未登录 /// - NotLoggedIn = -100, + RET_TOKEN_INVALID = -100, /// /// 验证密钥过期 @@ -31,7 +51,7 @@ public enum KnownReturnCode : int /// /// Ok /// - OK = 0, + RET_SUCCESS = 0, /// /// 未定义 diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Response/Response.cs b/src/Snap.Hutao/Snap.Hutao/Web/Response/Response.cs index 55339038..8112ed6f 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Response/Response.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Response/Response.cs @@ -88,4 +88,14 @@ public class Response : Response /// [JsonPropertyName("data")] public TData? Data { get; set; } + + /// + public override int GetHashCode() + { + int j = ReturnCode.GetHashCode(); + int k = Message == null ? 0 : Message.GetHashCode(); + int i = Data == null ? 0 : Data.GetHashCode(); + + return (((j * 31) + k) * 31) + i; + } } \ No newline at end of file