This commit is contained in:
qhy040404
2023-11-28 16:18:24 +08:00
parent 9993082b86
commit 4dd6765e35
7 changed files with 57 additions and 0 deletions

View File

@@ -2249,6 +2249,12 @@
<data name="ViewPageSettingDeviceIdHeader" xml:space="preserve">
<value>设备 ID</value>
</data>
<data name="ViewPageSettingDeviceIpDescription" xml:space="preserve">
<value>IP{0},归属:{1}</value>
</data>
<data name="ViewPageSettingDeviceIpHeader" xml:space="preserve">
<value>设备 IP</value>
</data>
<data name="ViewPageSettingEmptyHistoryVisibleDescription" xml:space="preserve">
<value>在祈愿记录页面显示或隐藏无记录的历史祈愿活动</value>
</data>

View File

@@ -19,6 +19,7 @@ internal sealed class HutaoUserOptions : ObservableObject, IOptions<HutaoUserOpt
private readonly TaskCompletionSource initializedTaskCompletionSource = new();
private string? userName = SH.ViewServiceHutaoUserLoginOrRegisterHint;
private string? token;
private IPInfo ipInfo = new();
private bool isLoggedIn;
private bool isHutaoCloudServiceAllowed;
private bool isLicensedDeveloper;
@@ -36,6 +37,11 @@ internal sealed class HutaoUserOptions : ObservableObject, IOptions<HutaoUserOpt
/// </summary>
public string? ActualUserName { get => IsLoggedIn ? UserName : null; }
/// <summary>
/// 设备当前IP
/// </summary>
public IPInfo IPInfo { get => ipInfo; set => ipInfo = value; }
/// <summary>
/// 是否已登录
/// </summary>
@@ -131,6 +137,11 @@ internal sealed class HutaoUserOptions : ObservableObject, IOptions<HutaoUserOpt
return token;
}
public async ValueTask GetIPInfoAsync(HomaPassportClient passportClient)
{
IPInfo = await passportClient.GetIPInfoAsync().ConfigureAwait(false);
}
private void ClearUserInfo()
{
IsLicensedDeveloper = false;

View File

@@ -33,6 +33,7 @@ internal sealed partial class HutaoUserService : IHutaoUserService, IHutaoUserSe
{
string userName = LocalSetting.Get(SettingKeys.PassportUserName, string.Empty);
string password = LocalSetting.Get(SettingKeys.PassportPassword, string.Empty);
await options.GetIPInfoAsync(passportClient).ConfigureAwait(false);
if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
{

View File

@@ -103,6 +103,7 @@
Description="{Binding HutaoOptions.DeviceId}"
Header="{shcm:ResourceString Name=ViewPageSettingDeviceIdHeader}"
IsClickEnabled="True"/>
<cwc:SettingsCard Description="{Binding UserOptions.IPInfo}" Header="{shcm:ResourceString Name=ViewPageSettingDeviceIpHeader}"/>
<cwc:SettingsCard Description="{Binding HutaoOptions.WebView2Version}" Header="{shcm:ResourceString Name=ViewPageSettingWebview2Header}"/>
</cwc:SettingsExpander.Items>
</cwc:SettingsExpander>

View File

@@ -193,6 +193,17 @@ internal sealed partial class HomaPassportClient
return HutaoResponse.DefaultIfNull(resp);
}
public async ValueTask<IPInfo> GetIPInfoAsync(CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
.SetRequestUri(HutaoEndpoints.Ip)
.Get();
IPInfo? resp = await builder.TryCatchSendAsync<IPInfo>(httpClient, logger, token).ConfigureAwait(false);
return resp ?? new();
}
private static string Encrypt(string text)
{
byte[] plaintextBytes = Encoding.UTF8.GetBytes(text);

View File

@@ -0,0 +1,24 @@
namespace Snap.Hutao.Web.Hutao;
internal sealed class IPInfo
{
public IPInfo()
{
}
[JsonConstructor]
public IPInfo(string ip, string division)
{
Ip = ip;
Division = division;
}
public string Ip { get; set; } = "Unknown";
public string Division { get; set; } = "Unknown";
public override string ToString()
{
return SH.FormatViewPageSettingDeviceIpDescription(Ip, Division);
}
}

View File

@@ -11,6 +11,7 @@ namespace Snap.Hutao.Web;
/// </summary>
[HighQuality]
[SuppressMessage("", "SA1201")]
[SuppressMessage("", "SA1203")]
[SuppressMessage("", "SA1124")]
internal static class HutaoEndpoints
{
@@ -22,6 +23,8 @@ internal static class HutaoEndpoints
public const string AnnouncementUpload = $"{HomaSnapGenshinApi}/Service/Announcement/Upload";
public const string Ip = $"{ApiSnapGenshin}/ip";
public static string GachaLogCompensation(int days)
{
return $"{HomaSnapGenshinApi}/Service/GachaLog/Compensation?days={days}";