From 57133e10b2269a3ffb8f4eb3f1394bc2579b1cce Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 19 Feb 2026 10:34:18 +0800 Subject: [PATCH 1/6] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/ServiceCollectionExtensions.cs | 10 +- .../JuHeIpLocatorOptions.cs | 18 ++- .../JuHeIpLocatorProvider.cs | 143 ++---------------- .../JuHeLocationData.cs | 114 ++++++++++++++ .../JuHeLocationResult.cs | 48 ++++++ 5 files changed, 188 insertions(+), 145 deletions(-) create mode 100644 src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeLocationData.cs create mode 100644 src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeLocationResult.cs diff --git a/src/components/BootstrapBlazor.JuHeIpLocatorProvider/Extensions/ServiceCollectionExtensions.cs b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/Extensions/ServiceCollectionExtensions.cs index 90a8f529..1dcdb5f4 100644 --- a/src/components/BootstrapBlazor.JuHeIpLocatorProvider/Extensions/ServiceCollectionExtensions.cs +++ b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/Extensions/ServiceCollectionExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Website: https://www.blazor.zone or https://argozhang.github.io/ @@ -7,12 +7,14 @@ namespace Microsoft.Extensions.DependencyInjection; /// -/// BootstrapBlazor 服务扩展类 +/// BootstrapBlazor 服务扩展类 +/// BootstrapBlazor service extensions /// -public static class BootstrapBlazoJuHeIpLocatorExtensions +public static class BootstrapBlazorJuHeIpLocatorExtensions { /// - /// 添加 AzureOpenAIService 服务 + /// 添加聚合搜索引擎 IP 定位器服务 + /// Adds JuHe IP locator service /// /// public static IServiceCollection AddBootstrapBlazorJuHeIpLocatorService(this IServiceCollection services) diff --git a/src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeIpLocatorOptions.cs b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeIpLocatorOptions.cs index ce58ec2c..444dbcc4 100644 --- a/src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeIpLocatorOptions.cs +++ b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeIpLocatorOptions.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 License // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone @@ -6,22 +6,26 @@ namespace BootstrapBlazor.Components; /// -/// 聚合搜索引擎 IP 定位器配置类 +/// 聚合搜索引擎 IP 定位器配置类 +/// JuHe IP locator options /// class JuHeIpLocatorOptions { /// - /// 聚合搜索引擎 IP 定位器 AppKey + /// 获得/设置 聚合搜索引擎 IP 定位器 AppKey + /// Gets or sets the JuHe IP locator AppKey /// - public string Key { get; set; } = ""; + public string? Key { get; set; } /// - /// 聚合搜索引擎 IP 定位器请求地址 + /// 获得/设置 聚合搜索引擎 IP 定位器请求地址 + /// Gets or sets the JuHe IP locator request URL /// - public string Url { get; set; } = "http://apis.juhe.cn/ip/ipNew"; + public string? Url { get; set; } /// - /// 聚合搜索引擎 IP 定位器请求超时时间 默认 5 秒 + /// 获得/设置 聚合搜索引擎 IP 定位器请求超时时间 默认 5 秒 + /// Gets or sets the JuHe IP locator request timeout, default is 5 seconds /// public TimeSpan Timeout { get; set; } } diff --git a/src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeIpLocatorProvider.cs b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeIpLocatorProvider.cs index 9aad0e95..dcbdc65a 100644 --- a/src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeIpLocatorProvider.cs +++ b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeIpLocatorProvider.cs @@ -1,17 +1,16 @@ -// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Website: https://www.blazor.zone or https://argozhang.github.io/ -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using System.Net.Http.Json; -using System.Text.Json.Serialization; namespace BootstrapBlazor.Components; /// -/// 聚合搜索引擎 IP 定位器 +/// 聚合搜索引擎 IP 定位器 +/// JuHe IP locator provider /// /// /// @@ -26,6 +25,8 @@ class JuHeIpLocatorProvider(IHttpClientFactory httpClientFactory, private JuHeIpLocatorOptions? _options; + private const string Url = "http://apis.juhe.cn/ip/ipNewV3"; + /// /// /// @@ -60,7 +61,7 @@ private JuHeIpLocatorOptions GetOptions() } if (string.IsNullOrEmpty(options.Url)) { - options.Url = "http://apis.juhe.cn/ip/ipNewV3"; + options.Url = Url; } } catch (Exception ex) @@ -71,145 +72,19 @@ private JuHeIpLocatorOptions GetOptions() } /// - /// 请求获得地理位置接口方法 + /// 请求获得地理位置接口方法 + /// Fetches the geolocation data /// /// /// /// - /// protected virtual async Task Fetch(string url, HttpClient client, CancellationToken token) { - var result = await client.GetFromJsonAsync(url, token); + var result = await client.GetFromJsonAsync(url, token); if (result != null && result.ErrorCode != 0) { logger.LogError("ErrorCode: {ErrorCode} Reason: {Reason}", result.ErrorCode, result.Reason); } return result?.ToString(); } - - /// - /// LocationResult 结构体 - /// - class LocationResult - { - /// - /// 获得/设置 结果状态返回码 为 查询成功 时通讯正常 - /// - public string? Reason { get; set; } - - /// - /// 获得/设置 错误码 - /// - [JsonPropertyName("error_code")] - public int ErrorCode { get; set; } - - /// - /// 获得/设置 定位信息 - /// - public LocationData? Result { get; set; } - - /// - /// - /// - /// - public override string? ToString() - { - string? ret = null; - if (ErrorCode == 0) - { - ret = Result?.Country == "中国" - ? $"{Result?.Prov}{Result?.City}{Result?.District} {Result?.Isp}" - : $"{Result?.Continent} {Result?.Country} {Result?.City}"; - } - return ret; - } - } - - class LocationData - { - /// - /// 获得/设置 州 - /// - public string? Continent { get; set; } - - /// - /// 获得/设置 国家 - /// - public string? Country { get; set; } - - /// - /// 获得/设置 邮编 - /// - public string? ZipCode { get; set; } - - /// - /// 获得/设置 时区 - /// - public string? TimeZone { get; set; } - - /// - /// 获得/设置 精度 - /// - public string? Accuracy { get; set; } - - /// - /// 获得/设置 所属 - /// - public string? Owner { get; set; } - - /// - /// 获得/设置 运营商 - /// - public string? Isp { get; set; } - - /// - /// 获得/设置 来源 - /// - public string? Source { get; set; } - - /// - /// 获得/设置 区号 - /// - public string? AreaCode { get; set; } - - /// - /// 获得/设置 行政区划代码 - /// - public string? AdCode { get; set; } - - /// - /// 获得/设置 国家代码 - /// - public string? AsNumber { get; set; } - - /// - /// 获得/设置 经度 - /// - public string? Lat { get; set; } - - /// - /// 获得/设置 纬度 - /// - public string? Lng { get; set; } - - /// - /// 获得/设置 半径 - /// - public string? Radius { get; set; } - - /// - /// 获得/设置 省份 - /// - public string? Prov { get; set; } - - /// - /// 获得/设置 城市 - /// - public string? City { get; set; } - - /// - /// 获得/设置 区县 - /// - public string? District { get; set; } - } } diff --git a/src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeLocationData.cs b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeLocationData.cs new file mode 100644 index 00000000..2bb5f281 --- /dev/null +++ b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeLocationData.cs @@ -0,0 +1,114 @@ +// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone + +namespace BootstrapBlazor.Components; + +/// +/// 聚合定位数据类 +/// JuHe location data class +/// +class JuHeLocationData +{ + /// + /// 获得/设置 州 + /// Gets or sets the continent + /// + public string? Continent { get; set; } + + /// + /// 获得/设置 国家 + /// Gets or sets the country + /// + public string? Country { get; set; } + + /// + /// 获得/设置 邮编 + /// Gets or sets the zip code + /// + public string? ZipCode { get; set; } + + /// + /// 获得/设置 时区 + /// Gets or sets the time zone + /// + public string? TimeZone { get; set; } + + /// + /// 获得/设置 精度 + /// Gets or sets the accuracy + /// + public string? Accuracy { get; set; } + + /// + /// 获得/设置 所属 + /// Gets or sets the owner + /// + public string? Owner { get; set; } + + /// + /// 获得/设置 运营商 + /// Gets or sets the ISP + /// + public string? Isp { get; set; } + + /// + /// 获得/设置 来源 + /// Gets or sets the source + /// + public string? Source { get; set; } + + /// + /// 获得/设置 区号 + /// Gets or sets the area code + /// + public string? AreaCode { get; set; } + + /// + /// 获得/设置 行政区划代码 + /// Gets or sets the administrative division code + /// + public string? AdCode { get; set; } + + /// + /// 获得/设置 国家代码 + /// Gets or sets the AS number + /// + public string? AsNumber { get; set; } + + /// + /// 获得/设置 经度 + /// Gets or sets the latitude + /// + public string? Lat { get; set; } + + /// + /// 获得/设置 纬度 + /// Gets or sets the longitude + /// + public string? Lng { get; set; } + + /// + /// 获得/设置 半径 + /// Gets or sets the radius + /// + public string? Radius { get; set; } + + /// + /// 获得/设置 省份 + /// Gets or sets the province + /// + public string? Prov { get; set; } + + /// + /// 获得/设置 城市 + /// Gets or sets the city + /// + public string? City { get; set; } + + /// + /// 获得/设置 区县 + /// Gets or sets the district + /// + public string? District { get; set; } +} diff --git a/src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeLocationResult.cs b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeLocationResult.cs new file mode 100644 index 00000000..42179614 --- /dev/null +++ b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeLocationResult.cs @@ -0,0 +1,48 @@ +// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone + +using System.Text.Json.Serialization; + +namespace BootstrapBlazor.Components; + +/// +/// 聚合定位结果类 +/// JuHe location result class +/// +class JuHeLocationResult +{ + /// + /// 获得/设置 结果状态返回码 + /// Gets or sets the result status reason + /// + public string? Reason { get; set; } + + /// + /// 获得/设置 错误码 + /// Gets or sets the error code + /// + [JsonPropertyName("error_code")] + public int ErrorCode { get; set; } + + /// + /// 获得/设置 定位信息 + /// Gets or sets the location data + /// + public JuHeLocationData? Result { get; set; } + + /// + /// + /// + public override string? ToString() + { + string? ret = null; + if (ErrorCode == 0) + { + ret = Result?.Country == "中国" + ? $"{Result?.Prov}{Result?.City}{Result?.District} {Result?.Isp}" + : $"{Result?.Continent} {Result?.Country} {Result?.City}"; + } + return ret; + } +} From c843c003f167ff8a76e260fa75ecb68ba6f279f1 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 19 Feb 2026 10:34:27 +0800 Subject: [PATCH 2/6] chore: bump version 10.0.1 --- .../BootstrapBlazor.JuHeIpLocatorProvider.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/BootstrapBlazor.JuHeIpLocatorProvider/BootstrapBlazor.JuHeIpLocatorProvider.csproj b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/BootstrapBlazor.JuHeIpLocatorProvider.csproj index 90bf0d02..056a3595 100644 --- a/src/components/BootstrapBlazor.JuHeIpLocatorProvider/BootstrapBlazor.JuHeIpLocatorProvider.csproj +++ b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/BootstrapBlazor.JuHeIpLocatorProvider.csproj @@ -1,5 +1,9 @@ + + 10.0.1 + + Bootstrap Blazor WebAssembly wasm UI Components JuHe Ip Locator Bootstrap UI components extensions of JuHeIpLocator From 5bb4b49c2ddeede428fe1f2cb1d77b449c81b67f Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 19 Feb 2026 11:20:06 +0800 Subject: [PATCH 3/6] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E6=9C=AA?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=20Key=20=E9=80=BB=E8=BE=91=E6=8F=90=E9=AB=98?= =?UTF-8?q?=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JuHeIpLocatorProvider.cs | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeIpLocatorProvider.cs b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeIpLocatorProvider.cs index dcbdc65a..abdec664 100644 --- a/src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeIpLocatorProvider.cs +++ b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/JuHeIpLocatorProvider.cs @@ -53,20 +53,15 @@ private JuHeIpLocatorOptions GetOptions() { var options = juHeIpLocatorOptions.Value; - try + if (string.IsNullOrEmpty(options.Key)) { - if (string.IsNullOrEmpty(options.Key)) - { - throw new InvalidOperationException($"{nameof(JuHeIpLocatorOptions)}:Key not value in appsettings configuration file. 未配置 {nameof(JuHeIpLocatorOptions)}:Key 请在 appsettings.json 中配置 {nameof(JuHeIpLocatorOptions)}:Key"); - } - if (string.IsNullOrEmpty(options.Url)) - { - options.Url = Url; - } + LastError = $"{nameof(JuHeIpLocatorOptions)}:Key not value in appsettings configuration file. 未配置 {nameof(JuHeIpLocatorOptions)}:Key 请在 appsettings.json 中配置 {nameof(JuHeIpLocatorOptions)}:Key"; + Log(LastError); + } - catch (Exception ex) + if (string.IsNullOrEmpty(options.Url)) { - logger.LogError(ex, "{GetOptions} failed", nameof(GetOptions)); + options.Url = Url; } return options; } @@ -83,8 +78,17 @@ private JuHeIpLocatorOptions GetOptions() var result = await client.GetFromJsonAsync(url, token); if (result != null && result.ErrorCode != 0) { - logger.LogError("ErrorCode: {ErrorCode} Reason: {Reason}", result.ErrorCode, result.Reason); + LastError = $"ErrorCode: {result.ErrorCode} Reason: {result.Reason}"; + Log(LastError); } return result?.ToString(); } + + private void Log(string? message) + { + if (logger.IsEnabled(LogLevel.Error)) + { + logger.LogError("{message}", message); + } + } } From 6172e1e6ea7b0451191a24508b7e23a3beaf4c2f Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 19 Feb 2026 11:20:21 +0800 Subject: [PATCH 4/6] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E5=A2=9E=E5=8A=A0=20LastError=20=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BootstrapBlazor.JuHeIpLocatorProvider.csproj | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/BootstrapBlazor.JuHeIpLocatorProvider/BootstrapBlazor.JuHeIpLocatorProvider.csproj b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/BootstrapBlazor.JuHeIpLocatorProvider.csproj index 056a3595..122ab094 100644 --- a/src/components/BootstrapBlazor.JuHeIpLocatorProvider/BootstrapBlazor.JuHeIpLocatorProvider.csproj +++ b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/BootstrapBlazor.JuHeIpLocatorProvider.csproj @@ -10,7 +10,11 @@ - + + + + + From 5a68835ccffdd7fe9ebff122aeaf5aefcf46c8a4 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 19 Feb 2026 11:30:23 +0800 Subject: [PATCH 5/6] =?UTF-8?q?revert:=20=E6=92=A4=E9=94=80=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BootstrapBlazor.JuHeIpLocatorProvider.csproj | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/components/BootstrapBlazor.JuHeIpLocatorProvider/BootstrapBlazor.JuHeIpLocatorProvider.csproj b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/BootstrapBlazor.JuHeIpLocatorProvider.csproj index 122ab094..056a3595 100644 --- a/src/components/BootstrapBlazor.JuHeIpLocatorProvider/BootstrapBlazor.JuHeIpLocatorProvider.csproj +++ b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/BootstrapBlazor.JuHeIpLocatorProvider.csproj @@ -10,11 +10,7 @@ - - - - - + From 1605eee3e27dcee867bfdad72c8761dd9018ed2d Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sat, 7 Mar 2026 17:09:40 +0800 Subject: [PATCH 6/6] chore: bump version 10.1.0 --- .../BootstrapBlazor.JuHeIpLocatorProvider.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/BootstrapBlazor.JuHeIpLocatorProvider/BootstrapBlazor.JuHeIpLocatorProvider.csproj b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/BootstrapBlazor.JuHeIpLocatorProvider.csproj index 056a3595..d5a6d7f4 100644 --- a/src/components/BootstrapBlazor.JuHeIpLocatorProvider/BootstrapBlazor.JuHeIpLocatorProvider.csproj +++ b/src/components/BootstrapBlazor.JuHeIpLocatorProvider/BootstrapBlazor.JuHeIpLocatorProvider.csproj @@ -1,7 +1,7 @@ - 10.0.1 + 10.1.0 @@ -10,7 +10,7 @@ - +