geetest verify

This commit is contained in:
DismissedLight
2023-08-22 23:32:03 +08:00
parent f4f3242546
commit 704113cacd
7 changed files with 80 additions and 3 deletions

View File

@@ -34,7 +34,7 @@ internal sealed partial class ExceptionRecorder
#if RELEASE
#pragma warning disable VSTHRD002
serviceProvider
.GetRequiredService<Web.Hutao.HomaLogUploadClient>()
.GetRequiredService<Web.Hutao.Log.HomaLogUploadClient>()
.UploadLogAsync(serviceProvider, e.Exception)
.GetAwaiter()
.GetResult();

View File

@@ -7,7 +7,7 @@ using Snap.Hutao.Web.Hutao.GachaLog;
using Snap.Hutao.Web.Response;
using System.Net.Http;
namespace Snap.Hutao.Web.Hutao;
namespace Snap.Hutao.Web.Hutao.GachaLog;
/// <summary>
/// 胡桃祈愿记录API客户端

View File

@@ -0,0 +1,19 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Web.Hutao.Geetest;
internal sealed class GeetestData
{
[JsonPropertyName("gt")]
public string Gt { get; set; } = default!;
[JsonPropertyName("challenge")]
public string Challenge { get; set; } = default!;
[JsonPropertyName("validate")]
public string Validate { get; set; } = default!;
[JsonPropertyName("type")]
public string Type { get; set; } = default!;
}

View File

@@ -0,0 +1,19 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Web.Hutao.Geetest;
internal sealed class GeetestResponse
{
[JsonPropertyName("code")]
public int Code { get; set; }
[JsonPropertyName("info")]
public string Info { get; set; } = default!;
[JsonPropertyName("data")]
public GeetestData Data { get; set; } = default!;
[JsonPropertyName("times")]
public int Times { get; set; } = default!;
}

View File

@@ -0,0 +1,32 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient;
using Snap.Hutao.Service.Hutao;
using Snap.Hutao.Web.Hutao.GachaLog;
using Snap.Hutao.Web.Response;
using System.Net.Http;
namespace Snap.Hutao.Web.Hutao.Geetest;
[ConstructorGenerated(ResolveHttpClient = true)]
[HttpClient(HttpClientConfiguration.Default)]
internal sealed partial class HomaGeetestClient
{
private readonly HttpClient httpClient;
private readonly JsonSerializerOptions options;
private readonly ILogger<HomaGeetestClient> logger;
private readonly HutaoUserOptions hutaoUserOptions;
public async ValueTask<GeetestResponse> VerifyAsync(string gt, string challenge, CancellationToken token)
{
httpClient.DefaultRequestHeaders.Authorization = new("Bearer", hutaoUserOptions.Token);
GeetestResponse? resp = await httpClient
.TryCatchGetFromJsonAsync<GeetestResponse>(HutaoEndpoints.GeetestVerify(gt,challenge), options, logger, token)
.ConfigureAwait(false);
ArgumentNullException.ThrowIfNull(resp);
return resp;
}
}

View File

@@ -7,7 +7,7 @@ using Snap.Hutao.Web.Hutao.Log;
using Snap.Hutao.Web.Response;
using System.Net.Http;
namespace Snap.Hutao.Web.Hutao;
namespace Snap.Hutao.Web.Hutao.Log;
/// <summary>
/// 胡桃日志客户端

View File

@@ -18,6 +18,13 @@ internal static class HutaoEndpoints
/// </summary>
public const string StaticHutao = "static.hut.ao";
#region
public static string GeetestVerify(string gt, string challenge)
{
return $"{HomaSnapGenshinApi}/Geetest/Verify?gt={gt}&challenge={challenge}";
}
#endregion
#region GachaLog
/// <summary>