diff --git a/src/BootstrapBlazor.Server/Components/Samples/Locators.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Locators.razor.cs
index e23fcf5c642..a94a2673bb5 100644
--- a/src/BootstrapBlazor.Server/Components/Samples/Locators.razor.cs
+++ b/src/BootstrapBlazor.Server/Components/Samples/Locators.razor.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
@@ -30,7 +30,7 @@ public partial class Locators
private string? Location { get; set; }
- private string ProviderName { get; set; } = nameof(BaiduIpLocatorProviderV2);
+ private string ProviderName { get; set; } = nameof(BaiduIpLocatorProvider);
[NotNull]
private List
? _providers = null;
diff --git a/src/BootstrapBlazor.Server/Locales/en-US.json b/src/BootstrapBlazor.Server/Locales/en-US.json
index cf8eecb8000..f8b9deb9d07 100644
--- a/src/BootstrapBlazor.Server/Locales/en-US.json
+++ b/src/BootstrapBlazor.Server/Locales/en-US.json
@@ -2982,9 +2982,10 @@
"LocatorsNormalTips2": "The Startup file add the following phrase to the ConfigureServices method",
"LocatorsNormalTips3": "Shandong, China Unicom",
"LocatorsNormalTips4": "Shushan District Hefei, Anhui China Telecom",
+ "LocatorsNormalTips5": "Bao'an District, Shenzhen, Guangdong China Telecom",
"LocatorsNormalTipsTitle": "Some geographic location query interfaces may return character sets from other character sets such asgbk, and the program may report an error",
"LocatorsNormalTitle": "Basic usage",
- "LocatorsProviderDesc": "The component library has two built-in free online geolocation locators, BaiduIpLocatorProvider BaiduIpLocatorProviderV2
The component library has a built-in paid online geolocation locator BootstrapBlazor.JuHeIpLocatorProvider Nuget package Official website address
The component library has a built-in free offline geolocation locator BootstrapBlazor.IP2Region Nuget package
",
+ "LocatorsProviderDesc": "The component library built-in free online geolocation locators, BaiduIpLocatorProvider
The component library has a built-in paid online geolocation locator BootstrapBlazor.JuHeIpLocatorProvider Nuget package Official website address
The component library has a built-in free offline geolocation locator BootstrapBlazor.IP2Region Nuget package. Supports IPv6 format.
",
"LocatorsSubTitle": "More for system log tracking and analysis",
"LocatorsTitle": "Get the IP geographic location"
},
diff --git a/src/BootstrapBlazor.Server/Locales/zh-CN.json b/src/BootstrapBlazor.Server/Locales/zh-CN.json
index 97a8de1054c..1bdd5814fe5 100644
--- a/src/BootstrapBlazor.Server/Locales/zh-CN.json
+++ b/src/BootstrapBlazor.Server/Locales/zh-CN.json
@@ -2982,9 +2982,10 @@
"LocatorsNormalTips2": "Startup 文件中 ConfigureServices 方法内增加下面这句话即可解决",
"LocatorsNormalTips3": "山东省 中国联通",
"LocatorsNormalTips4": "安徽省合肥市蜀山区 中国电信",
+ "LocatorsNormalTips5": "广东省深圳市宝安区 中国电信",
"LocatorsNormalTipsTitle": "某些地理位置查询接口返回字符集可能是其他字符集如 gbk,程序会报错;",
"LocatorsNormalTitle": "普通用法",
- "LocatorsProviderDesc": "组件库内置两个免费在线地理位置定位器分别为 BaiduIpLocatorProvider BaiduIpLocatorProviderV2
组件库内置一个收费在线地理位置定位器 BootstrapBlazor.JuHeIpLocatorProvider Nuget 包 官网地址
组件库内置一个免费离线地理位置定位器 BootstrapBlazor.IP2Region Nuget 包
",
+ "LocatorsProviderDesc": "组件库内置免费一个在线地理位置定位器 BaiduIpLocatorProvider
组件库内置一个收费在线地理位置定位器 BootstrapBlazor.JuHeIpLocatorProvider Nuget 包 官网地址
组件库内置一个免费离线地理位置定位器 BootstrapBlazor.IP2Region Nuget 包 支持 IPv6 格式
",
"LocatorsSubTitle": "多用于系统日志跟踪与分析",
"LocatorsTitle": "获取 IP 地理位置"
},
diff --git a/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs b/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs
index 4c40b405fee..bd05cdadae6 100644
--- a/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs
+++ b/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs
@@ -69,11 +69,9 @@ public static IServiceCollection AddBootstrapBlazor(this IServiceCollection serv
// IP Locator Service
services.TryAddSingleton();
services.AddSingleton();
- services.AddSingleton();
#if NET8_0_OR_GREATER
services.AddKeyedSingleton(nameof(BaiduIpLocatorProvider));
- services.AddKeyedSingleton(nameof(BaiduIpLocatorProviderV2));
#endif
// 节日服务
diff --git a/src/BootstrapBlazor/Services/IPLocator/BaiduIpLocatorProviderV2.cs b/src/BootstrapBlazor/Services/IPLocator/BaiduIpLocatorProviderV2.cs
deleted file mode 100644
index 8e5f2734964..00000000000
--- a/src/BootstrapBlazor/Services/IPLocator/BaiduIpLocatorProviderV2.cs
+++ /dev/null
@@ -1,169 +0,0 @@
-// 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
-
-using Microsoft.Extensions.Logging;
-using System.Net.Http.Json;
-
-namespace BootstrapBlazor.Components;
-
-///
-/// BaiduIPLocatorV2 第二个版本实现类
-/// BaiduIPLocatorV2 Implementation Class
-///
-public class BaiduIpLocatorProviderV2(IHttpClientFactory httpClientFactory, IOptions options, ILogger logger) : BaiduIpLocatorProvider(httpClientFactory, options, logger)
-{
- ///
- ///
- ///
- ///
- protected override string GetUrl(string ip) => $"https://qifu-api.baidubce.com/ip/geo/v1/district?ip={ip}";
-
- ///
- ///
- ///
- ///
- ///
- ///
- protected override async Task Fetch(string url, HttpClient client, CancellationToken token)
- {
- var result = await client.GetFromJsonAsync(url, token);
- return result?.ToString();
- }
-
- [ExcludeFromCodeCoverage]
- class LocationResultV2
- {
- public string? Code { get; set; }
-
- [NotNull]
- public LocationDataV2? Data { get; set; }
-
- public bool Charge { get; set; }
-
- public string? Msg { get; set; }
-
- public string? Ip { get; set; }
-
- public string? CoordSys { get; set; }
-
- public override string? ToString()
- {
- string? ret = null;
- if (Code == "Success")
- {
- ret = Data?.Country == "中国"
- ? $"{Data?.Prov}{Data?.City}{Data?.District} {Data?.Isp}"
- : $"{Data?.Continent} {Data?.Country} {Data?.City}";
- }
- return ret;
- }
- }
-
- [ExcludeFromCodeCoverage]
- class LocationDataV2
- {
- ///
- /// 获得/设置 州
- /// Gets or sets Continent
- ///
- public string? Continent { get; set; }
-
- ///
- /// 获得/设置 国家
- /// Gets or sets Country
- ///
- public string? Country { get; set; }
-
- ///
- /// 获得/设置 邮编
- /// Gets or sets ZipCode
- ///
- public string? ZipCode { get; set; }
-
- ///
- /// 获得/设置 时区
- /// Gets or sets TimeZone
- ///
- public string? TimeZone { get; set; }
-
- ///
- /// 获得/设置 精度
- /// Gets or sets Accuracy
- ///
- public string? Accuracy { get; set; }
-
- ///
- /// 获得/设置 所属
- /// Gets or sets Owner
- ///
- public string? Owner { get; set; }
-
- ///
- /// 获得/设置 运营商
- /// Gets or sets ISP
- ///
- public string? Isp { get; set; }
-
- ///
- /// 获得/设置 来源
- /// Gets or sets Source
- ///
- public string? Source { get; set; }
-
- ///
- /// 获得/设置 区号
- /// Gets or sets Area Code
- ///
- public string? AreaCode { get; set; }
-
- ///
- /// 获得/设置 行政区划代码
- /// Gets or sets AdCode
- ///
- public string? AdCode { get; set; }
-
- ///
- /// 获得/设置 国家代码
- /// Gets or sets Country Code
- ///
- public string? AsNumber { get; set; }
-
- ///
- /// 获得/设置 经度
- /// Gets or sets Latitude
- ///
- public string? Lat { get; set; }
-
- ///
- /// 获得/设置 纬度
- /// Gets or sets Longitude
- ///
- public string? Lng { get; set; }
-
- ///
- /// 获得/设置 半径
- /// Gets or sets Radius
- ///
- public string? Radius { get; set; }
-
- ///
- /// 获得/设置 省份
- /// Gets or sets Province
- ///
- public string? Prov { get; set; }
-
- ///
- /// 获得/设置 城市
- /// Gets or sets City
- ///
- public string? City { get; set; }
-
- ///
- /// 获得/设置 区县
- /// Gets or sets District
- ///
- public string? District { get; set; }
- }
-}
diff --git a/test/UnitTest/Services/IpLocatorTest.cs b/test/UnitTest/Services/IpLocatorTest.cs
index 5371ae06b52..767da1b5b70 100644
--- a/test/UnitTest/Services/IpLocatorTest.cs
+++ b/test/UnitTest/Services/IpLocatorTest.cs
@@ -36,40 +36,19 @@ public async Task BaiduIpLocatorProvider_Ok()
// 关闭缓存
option.Value.IpLocatorOptions.EnableCache = false;
option.Value.IpLocatorOptions.SlidingExpiration = TimeSpan.FromMinutes(5);
- option.Value.IpLocatorOptions.ProviderName = nameof(BaiduIpLocatorProviderV2);
+ option.Value.IpLocatorOptions.ProviderName = nameof(BaiduIpLocatorProvider);
await provider.Locate("223.91.188.112");
Assert.Equal("美国", result);
}
- [Fact]
- public async Task BaiduIpLocatorProviderV2_Ok()
- {
- var factory = Context.Services.GetRequiredService();
- var option = Context.Services.GetRequiredService>();
- var logger = Context.Services.GetRequiredService>();
- var provider = new MockProviderV2(factory, option, logger);
-
- var result = await provider.Locate("127.0.0.1");
- Assert.Equal("localhost", result);
-
- result = await provider.Locate("");
- Assert.Equal("localhost", result);
-
- // 河南省漯河市 移动
- result = await provider.Locate("223.91.188.112");
- Assert.Equal("省份城市区县 测试", result);
- }
-
[Fact]
public void Factory_Ok()
{
var factory = Context.Services.GetRequiredService();
- Assert.NotNull(factory.Create("BaiduIpLocatorProviderV2"));
Assert.NotNull(factory.Create("BaiduIpLocatorProvider"));
Assert.NotNull(factory.Create());
Assert.NotNull(Context.Services.GetKeyedService("BaiduIpLocatorProvider"));
- Assert.NotNull(Context.Services.GetKeyedService("BaiduIpLocatorProviderV2"));
}
[Fact]
@@ -89,8 +68,8 @@ public async Task Fetch_Error()
var result = await provider.Locate("223.91.188.112");
Assert.Null(result);
- var cancelPprovider = new MockProviderFetchCancelError(factory, option, logger);
- result = await cancelPprovider.Locate("223.91.188.112");
+ var cancelProvider = new MockProviderFetchCancelError(factory, option, logger);
+ result = await cancelProvider.Locate("223.91.188.112");
Assert.Null(result);
}
@@ -104,11 +83,6 @@ public async Task Fetch_Result_Fail()
var provider = new MockBaiduProvider(factory, option, logger);
var result = await provider.Locate("223.91.188.112");
Assert.Null(result);
-
- var loggerV2 = Context.Services.GetRequiredService>();
- var providerV2 = new MockBaiduProviderV2(factory, option, loggerV2);
- result = await providerV2.Locate("223.91.188.112");
- Assert.Null(result);
}
class MockProviderFetchError(IHttpClientFactory httpClientFactory, IOptions option, ILogger logger) : BaiduIpLocatorProvider(httpClientFactory, option, logger)
@@ -130,15 +104,6 @@ class MockBaiduProvider(IHttpClientFactory httpClientFactory, IOptions option, ILogger logger) : BaiduIpLocatorProviderV2(httpClientFactory, option, logger)
- {
- protected override Task Fetch(string url, HttpClient client, CancellationToken token)
- {
- client = new HttpClient(new MockHttpNullMessageHandler(), true);
- return base.Fetch(url, client, token);
- }
- }
-
class MockProvider(IHttpClientFactory httpClientFactory, IOptions option, ILogger logger) : BaiduIpLocatorProvider(httpClientFactory, option, logger)
{
protected override Task Fetch(string url, HttpClient client, CancellationToken token)
@@ -148,15 +113,6 @@ class MockProvider(IHttpClientFactory httpClientFactory, IOptions option, ILogger logger) : BaiduIpLocatorProviderV2(httpClientFactory, option, logger)
- {
- protected override Task Fetch(string url, HttpClient client, CancellationToken token)
- {
- client = new HttpClient(new MockHttpSuccessMessageHandlerV2(), true);
- return base.Fetch(url, client, token);
- }
- }
-
class MockHttpNullMessageHandler : HttpMessageHandler
{
protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)