add ability to customize geetest url

This commit is contained in:
DismissedLight
2023-08-27 22:20:28 +08:00
parent 82b00ba458
commit 92afa4b23c
13 changed files with 335 additions and 22 deletions

View File

@@ -1,6 +1,8 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using System.Runtime.Versioning;
namespace Snap.Hutao.Model.Entity;
/// <summary>
@@ -86,10 +88,16 @@ internal sealed partial class SettingEntry
/// <summary>
/// 启动游戏 多倍启动
/// </summary>
[Obsolete("不再支持多开")]
public const string MultipleInstances = "Launch.MultipleInstances";
/// <summary>
/// 语言
/// </summary>
public const string Culture = "Culture";
/// <summary>
/// 自定义极验接口
/// </summary>
public const string GeetestCustomCompositeUrl = "GeetestCustomCompositeUrl";
}

View File

@@ -2274,6 +2274,87 @@ namespace Snap.Hutao.Resource.Localization {
}
}
/// <summary>
/// 查找类似 请输入请求接口的 Url 复合模板 的本地化字符串。
/// </summary>
internal static string ViewDialogGeetestCustomUrlCompositInputHint {
get {
return ResourceManager.GetString("ViewDialogGeetestCustomUrlCompositInputHint", resourceCulture);
}
}
/// <summary>
/// 查找类似 接口需要返回形如上方所示的 Json 数据,多余的数据会被忽略 的本地化字符串。
/// </summary>
internal static string ViewDialogGeetestCustomUrlReturnDataDescription1 {
get {
return ResourceManager.GetString("ViewDialogGeetestCustomUrlReturnDataDescription1", resourceCulture);
}
}
/// <summary>
/// 查找类似 &quot;code&quot; 为 0 时,指示验证成功,其他的值均视为验证失败 的本地化字符串。
/// </summary>
internal static string ViewDialogGeetestCustomUrlReturnDataDescription2 {
get {
return ResourceManager.GetString("ViewDialogGeetestCustomUrlReturnDataDescription2", resourceCulture);
}
}
/// <summary>
/// 查找类似 返回数据 的本地化字符串。
/// </summary>
internal static string ViewDialogGeetestCustomUrlReturnDataHeader {
get {
return ResourceManager.GetString("ViewDialogGeetestCustomUrlReturnDataHeader", resourceCulture);
}
}
/// <summary>
/// 查找类似 {0} 将在实际请求时替换为 gt 的本地化字符串。
/// </summary>
internal static string ViewDialogGeetestCustomUrlSampleDescription1 {
get {
return ResourceManager.GetString("ViewDialogGeetestCustomUrlSampleDescription1", resourceCulture);
}
}
/// <summary>
/// 查找类似 {1} 将在实际请求时替换为 challenge 的本地化字符串。
/// </summary>
internal static string ViewDialogGeetestCustomUrlSampleDescription2 {
get {
return ResourceManager.GetString("ViewDialogGeetestCustomUrlSampleDescription2", resourceCulture);
}
}
/// <summary>
/// 查找类似 将会通过 GET 方式对接口发送请求 的本地化字符串。
/// </summary>
internal static string ViewDialogGeetestCustomUrlSampleDescription3 {
get {
return ResourceManager.GetString("ViewDialogGeetestCustomUrlSampleDescription3", resourceCulture);
}
}
/// <summary>
/// 查找类似 示例 的本地化字符串。
/// </summary>
internal static string ViewDialogGeetestCustomUrlSampleHeader {
get {
return ResourceManager.GetString("ViewDialogGeetestCustomUrlSampleHeader", resourceCulture);
}
}
/// <summary>
/// 查找类似 配置无感验证接口 的本地化字符串。
/// </summary>
internal static string ViewDialogGeetestCustomUrlTitle {
get {
return ResourceManager.GetString("ViewDialogGeetestCustomUrlTitle", resourceCulture);
}
}
/// <summary>
/// 查找类似 导出 App 的本地化字符串。
/// </summary>
@@ -4911,6 +4992,33 @@ namespace Snap.Hutao.Resource.Localization {
}
}
/// <summary>
/// 查找类似 配置 的本地化字符串。
/// </summary>
internal static string ViewPageSettingGeetestCustomUrlAction {
get {
return ResourceManager.GetString("ViewPageSettingGeetestCustomUrlAction", resourceCulture);
}
}
/// <summary>
/// 查找类似 配置当请求触发人机验证时使用的验证接口 的本地化字符串。
/// </summary>
internal static string ViewPageSettingGeetestCustomUrlDescription {
get {
return ResourceManager.GetString("ViewPageSettingGeetestCustomUrlDescription", resourceCulture);
}
}
/// <summary>
/// 查找类似 配置验证请求接口 的本地化字符串。
/// </summary>
internal static string ViewPageSettingGeetestCustomUrlHeader {
get {
return ResourceManager.GetString("ViewPageSettingGeetestCustomUrlHeader", resourceCulture);
}
}
/// <summary>
/// 查找类似 胡桃账号 的本地化字符串。
/// </summary>

View File

@@ -911,6 +911,33 @@
<data name="ViewDialogGachaLogUrlTitle" xml:space="preserve">
<value>手动输入祈愿记录 Url</value>
</data>
<data name="ViewDialogGeetestCustomUrlCompositInputHint" xml:space="preserve">
<value>请输入请求接口的 Url 复合模板</value>
</data>
<data name="ViewDialogGeetestCustomUrlReturnDataDescription1" xml:space="preserve">
<value>接口需要返回形如上方所示的 Json 数据,多余的数据会被忽略</value>
</data>
<data name="ViewDialogGeetestCustomUrlReturnDataDescription2" xml:space="preserve">
<value>"code" 为 0 时,指示验证成功,其他的值均视为验证失败</value>
</data>
<data name="ViewDialogGeetestCustomUrlReturnDataHeader" xml:space="preserve">
<value>返回数据</value>
</data>
<data name="ViewDialogGeetestCustomUrlSampleDescription1" xml:space="preserve">
<value>{0} 将在实际请求时替换为 gt</value>
</data>
<data name="ViewDialogGeetestCustomUrlSampleDescription2" xml:space="preserve">
<value>{1} 将在实际请求时替换为 challenge</value>
</data>
<data name="ViewDialogGeetestCustomUrlSampleDescription3" xml:space="preserve">
<value>将会通过 GET 方式对接口发送请求</value>
</data>
<data name="ViewDialogGeetestCustomUrlSampleHeader" xml:space="preserve">
<value>示例</value>
</data>
<data name="ViewDialogGeetestCustomUrlTitle" xml:space="preserve">
<value>配置无感验证接口</value>
</data>
<data name="ViewDialogImportExportApp" xml:space="preserve">
<value>导出 App</value>
</data>
@@ -1790,6 +1817,15 @@
<data name="ViewPageSettingGameHeader" xml:space="preserve">
<value>游戏</value>
</data>
<data name="ViewPageSettingGeetestCustomUrlAction" xml:space="preserve">
<value>配置</value>
</data>
<data name="ViewPageSettingGeetestCustomUrlDescription" xml:space="preserve">
<value>配置当请求触发人机验证时使用的验证接口</value>
</data>
<data name="ViewPageSettingGeetestCustomUrlHeader" xml:space="preserve">
<value>配置验证请求接口</value>
</data>
<data name="ViewPageSettingHutaoPassportHeader" xml:space="preserve">
<value>胡桃账号</value>
</data>

View File

@@ -38,6 +38,7 @@ internal sealed partial class AppOptions : DbStoreOptions
private BackdropType? backdropType;
private CultureInfo? currentCulture;
private bool? isAdvancedLaunchOptionsEnabled;
private string? geetestCustomCompositeUrl;
/// <summary>
/// 游戏路径
@@ -100,6 +101,12 @@ internal sealed partial class AppOptions : DbStoreOptions
set => SetOption(ref isAdvancedLaunchOptionsEnabled, SettingEntry.IsAdvancedLaunchOptionsEnabled, value);
}
public string GeetestCustomCompositeUrl
{
get => GetOption(ref geetestCustomCompositeUrl, SettingEntry.GeetestCustomCompositeUrl);
set => SetOption(ref geetestCustomCompositeUrl, SettingEntry.GeetestCustomCompositeUrl, value);
}
private static NameValue<string> ToNameValue(CultureInfo info)
{
return new(info.NativeName, info.Name);

View File

@@ -142,6 +142,7 @@
<None Remove="View\Dialog\GachaLogImportDialog.xaml" />
<None Remove="View\Dialog\GachaLogRefreshProgressDialog.xaml" />
<None Remove="View\Dialog\GachaLogUrlDialog.xaml" />
<None Remove="View\Dialog\GeetestCustomUrlDialog.xaml" />
<None Remove="View\Dialog\LaunchGameAccountNameDialog.xaml" />
<None Remove="View\Dialog\LaunchGamePackageConvertDialog.xaml" />
<None Remove="View\Dialog\SignInWebViewDialog.xaml" />
@@ -325,6 +326,12 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Page Update="View\Dialog\GeetestCustomUrlDialog.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Page Update="View\Control\Webview2Viewer.xaml">
<Generator>MSBuild:Compile</Generator>

View File

@@ -14,9 +14,9 @@
<Grid>
<TextBox
x:Name="InputText"
Margin="0,0,0,8"
VerticalAlignment="Top"
PlaceholderText="{shcm:ResourceString Name=ViewDialogAchievementArchiveCreateInputPlaceholder}"/>
PlaceholderText="{shcm:ResourceString Name=ViewDialogAchievementArchiveCreateInputPlaceholder}"
Text="{x:Bind Text, Mode=TwoWay}"/>
</Grid>
</ContentDialog>

View File

@@ -9,6 +9,7 @@ namespace Snap.Hutao.View.Dialog;
/// 成就存档创建对话框
/// </summary>
[HighQuality]
[DependencyProperty("Text", typeof(string))]
internal sealed partial class AchievementArchiveCreateDialog : ContentDialog
{
private readonly ITaskContext taskContext;
@@ -33,8 +34,6 @@ internal sealed partial class AchievementArchiveCreateDialog : ContentDialog
{
await taskContext.SwitchToMainThreadAsync();
ContentDialogResult result = await ShowAsync();
string text = InputText.Text ?? string.Empty;
return new(result == ContentDialogResult.Primary, text);
return new(result == ContentDialogResult.Primary, Text ?? string.Empty);
}
}

View File

@@ -16,7 +16,7 @@
<TextBox
VerticalAlignment="Top"
PlaceholderText="{shcm:ResourceString Name=ViewDialogCultivateProjectInputPlaceholder}"
Text="{x:Bind Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
Text="{x:Bind Text, Mode=TwoWay}"/>
<CheckBox
Margin="0,8,0,0"
Content="{shcm:ResourceString Name=ViewDialogCultivateProjectAttachUid}"

View File

@@ -0,0 +1,89 @@
<ContentDialog
x:Class="Snap.Hutao.View.Dialog.GeetestCustomUrlDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:shcm="using:Snap.Hutao.Control.Markup"
Title="{shcm:ResourceString Name=ViewDialogGeetestCustomUrlTitle}"
CloseButtonText="{shcm:ResourceString Name=ContentDialogCancelCloseButtonText}"
DefaultButton="Primary"
PrimaryButtonText="{shcm:ResourceString Name=ContentDialogConfirmPrimaryButtonText}"
Style="{StaticResource DefaultContentDialogStyle}"
mc:Ignorable="d">
<StackPanel>
<TextBlock
Margin="1,0,0,5"
Style="{StaticResource BaseTextBlockStyle}"
Text="{shcm:ResourceString Name=ViewDialogGeetestCustomUrlReturnDataHeader}"/>
<Border
Margin="0,4,0,0"
Padding="0,8,8,8"
Style="{ThemeResource BorderCardStyle}">
<TextBlock FontFamily="{StaticResource CascadiaMonoAndMiSans}" Style="{StaticResource CaptionTextBlockStyle}">
<TextBlock.Inlines>
<Run Text="{} {"/>
<LineBreak/>
<Run Text=" &quot;code&quot;: 0,"/>
<LineBreak/>
<Run Text=" &quot;data&quot;: {"/>
<LineBreak/>
<Run Text=" &quot;gt&quot;: &quot;same gt below&quot;,"/>
<LineBreak/>
<Run Text=" &quot;challenge&quot;: &quot;same challenge below&quot;,"/>
<LineBreak/>
<Run Text=" &quot;validate&quot;: &quot;validation result&quot;"/>
<LineBreak/>
<Run Text=" }"/>
<LineBreak/>
<Run Text="{}}"/>
</TextBlock.Inlines>
</TextBlock>
</Border>
<TextBlock
Margin="0,4,0,0"
FontFamily="{StaticResource CascadiaMonoAndMiSans}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{shcm:ResourceString Name=ViewDialogGeetestCustomUrlReturnDataDescription1}"/>
<TextBlock
Margin="0,4,0,0"
FontFamily="{StaticResource CascadiaMonoAndMiSans}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{shcm:ResourceString Name=ViewDialogGeetestCustomUrlReturnDataDescription2}"/>
<TextBlock
Margin="1,15,0,5"
Style="{StaticResource BaseTextBlockStyle}"
Text="{shcm:ResourceString Name=ViewDialogGeetestCustomUrlSampleHeader}"/>
<Border
Margin="0,4,0,0"
Padding="8"
Style="{ThemeResource BorderCardStyle}">
<TextBlock
FontFamily="{StaticResource CascadiaMonoAndMiSans}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="https://my.api.com/geetest?gt={0}&amp;challenge={1}"/>
</Border>
<TextBlock
Margin="0,4,0,0"
FontFamily="{StaticResource CascadiaMonoAndMiSans}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{shcm:ResourceString Name=ViewDialogGeetestCustomUrlSampleDescription1}"/>
<TextBlock
Margin="0,2,0,0"
FontFamily="{StaticResource CascadiaMonoAndMiSans}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{shcm:ResourceString Name=ViewDialogGeetestCustomUrlSampleDescription2}"/>
<TextBlock
Margin="0,2,0,0"
FontFamily="{StaticResource CascadiaMonoAndMiSans}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{shcm:ResourceString Name=ViewDialogGeetestCustomUrlSampleDescription3}"/>
<TextBox
Margin="0,16,0,0"
PlaceholderText="{shcm:ResourceString Name=ViewDialogGeetestCustomUrlCompositInputHint}"
Text="{x:Bind Text, Mode=TwoWay}"/>
</StackPanel>
</ContentDialog>

View File

@@ -0,0 +1,28 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Microsoft.UI.Xaml.Controls;
using Snap.Hutao.Service;
namespace Snap.Hutao.View.Dialog;
[DependencyProperty("Text", typeof(string))]
internal sealed partial class GeetestCustomUrlDialog : ContentDialog
{
private readonly ITaskContext taskContext;
public GeetestCustomUrlDialog(IServiceProvider serviceProvider)
{
InitializeComponent();
XamlRoot = serviceProvider.GetRequiredService<MainWindow>().Content.XamlRoot;
Text = serviceProvider.GetRequiredService<AppOptions>().GeetestCustomCompositeUrl;
taskContext = serviceProvider.GetRequiredService<ITaskContext>();
}
public async ValueTask<ValueResult<bool, string>> GetUrlAsync()
{
await taskContext.SwitchToMainThreadAsync();
ContentDialogResult result = await ShowAsync();
return new(result == ContentDialogResult.Primary, Text ?? string.Empty);
}
}

View File

@@ -112,17 +112,6 @@
SelectedItem="{Binding SelectedBackdropType, Mode=TwoWay}"/>
</cwc:SettingsCard>
<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" Text="{shcm:ResourceString Name=ViewPageSettingGachaLogHeader}"/>
<cwc:SettingsCard
Description="{shcm:ResourceString Name=ViewPageSettingEmptyHistoryVisibleDescription}"
Header="{shcm:ResourceString Name=ViewPageSettingEmptyHistoryVisibleHeader}"
HeaderIcon="{shcm:FontIcon Glyph=&#xE81C;}">
<ToggleSwitch
IsOn="{Binding Options.IsEmptyHistoryWishVisible, Mode=TwoWay}"
OffContent="{shcm:ResourceString Name=ViewPageSettingEmptyHistoryVisibleOff}"
OnContent="{shcm:ResourceString Name=ViewPageSettingEmptyHistoryVisibleOn}"/>
</cwc:SettingsCard>
<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" Text="{shcm:ResourceString Name=ViewPageSettingGameHeader}"/>
<InfoBar
IsClosable="False"
@@ -146,6 +135,27 @@
HeaderIcon="{shcm:FontIcon Glyph=&#xE74D;}"
IsClickEnabled="True"/>
<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" Text="{shcm:ResourceString Name=ViewPageSettingGachaLogHeader}"/>
<cwc:SettingsCard
Description="{shcm:ResourceString Name=ViewPageSettingEmptyHistoryVisibleDescription}"
Header="{shcm:ResourceString Name=ViewPageSettingEmptyHistoryVisibleHeader}"
HeaderIcon="{shcm:FontIcon Glyph=&#xE81C;}">
<ToggleSwitch
IsOn="{Binding Options.IsEmptyHistoryWishVisible, Mode=TwoWay}"
OffContent="{shcm:ResourceString Name=ViewPageSettingEmptyHistoryVisibleOff}"
OnContent="{shcm:ResourceString Name=ViewPageSettingEmptyHistoryVisibleOn}"/>
</cwc:SettingsCard>
<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" Text="无感验证"/>
<cwc:SettingsCard
ActionIcon="{shcm:FontIcon Glyph=&#xE76C;}"
ActionIconToolTip="{shcm:ResourceString Name=ViewPageSettingGeetestCustomUrlAction}"
Command="{Binding ConfigureGeetestUrlCommand}"
Description="{shcm:ResourceString Name=ViewPageSettingGeetestCustomUrlDescription}"
Header="{shcm:ResourceString Name=ViewPageSettingGeetestCustomUrlHeader}"
HeaderIcon="{shcm:FontIcon Glyph=&#xE776;}"
IsClickEnabled="True"/>
<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" Text="{shcm:ResourceString Name=ViewPageSettingStorageHeader}"/>
<cwc:SettingsCard
ActionIcon="{shcm:FontIcon Glyph=&#xE76C;}"

View File

@@ -18,6 +18,7 @@ using Snap.Hutao.Service.Hutao;
using Snap.Hutao.Service.Navigation;
using Snap.Hutao.Service.Notification;
using Snap.Hutao.Service.User;
using Snap.Hutao.View.Dialog;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
@@ -41,7 +42,7 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
private readonly IUserService userService;
private readonly IInfoBarService infoBarService;
private readonly ITaskContext taskContext;
private readonly AppOptions options;
private readonly AppOptions appOptions;
private readonly RuntimeOptions runtimeOptions;
private readonly HutaoUserOptions hutaoUserOptions;
@@ -51,7 +52,7 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
/// <summary>
/// 应用程序设置
/// </summary>
public AppOptions Options { get => options; }
public AppOptions Options { get => appOptions; }
/// <summary>
/// 胡桃选项
@@ -231,4 +232,18 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
}
}
}
[Command("ConfigureGeetestUrlCommand")]
private async Task ConfigureGeetestUrlAsync()
{
GeetestCustomUrlDialog dialog = await contentDialogFactory.CreateInstanceAsync<GeetestCustomUrlDialog>().ConfigureAwait(false);
(bool isOk, string template) = await dialog.GetUrlAsync().ConfigureAwait(false);
if (isOk)
{
await taskContext.SwitchToMainThreadAsync();
appOptions.GeetestCustomCompositeUrl = template;
infoBarService.Success("无感验证复合 Url 配置成功");
}
}
}

View File

@@ -2,6 +2,7 @@
// Licensed under the MIT license.
using Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient;
using Snap.Hutao.Service;
using Snap.Hutao.Service.Hutao;
using Snap.Hutao.Web.Hutao.GachaLog;
using System.Net.Http;
@@ -15,14 +16,19 @@ internal sealed partial class HomaGeetestClient
private readonly HttpClient httpClient;
private readonly JsonSerializerOptions options;
private readonly ILogger<HomaGeetestClient> logger;
private readonly HutaoUserOptions hutaoUserOptions;
private readonly AppOptions appOptions;
public async ValueTask<GeetestResponse> VerifyAsync(string gt, string challenge, CancellationToken token)
{
await httpClient.TrySetTokenAsync(hutaoUserOptions).ConfigureAwait(false);
string template = appOptions.GeetestCustomCompositeUrl;
if (string.IsNullOrEmpty(template))
{
return new() { Code = -1 };
}
GeetestResponse? resp = await httpClient
.TryCatchGetFromJsonAsync<GeetestResponse>(HutaoEndpoints.GeetestVerify(gt, challenge), options, logger, token)
.TryCatchGetFromJsonAsync<GeetestResponse>(template.Format(gt, challenge), options, logger, token)
.ConfigureAwait(false);
ArgumentNullException.ThrowIfNull(resp);