重构代码:优化通过IP地址获取地理位置逻辑 link #IUU35
#Issue https://gitee.com/LongbowEnterprise/dashboard/issues?id=IUU35 #Comment 对字典表配置项 IP地理位置接口 检查
This commit is contained in:
parent
7d7af71559
commit
87395f0376
|
@ -60,12 +60,15 @@ namespace Bootstrap.Admin
|
|||
/// <returns></returns>
|
||||
public string RetrieveLocaleByIp(string ip = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(DictHelper.RetrieveLocaleIPSvr()) || ip.IsNullOrEmpty() || _local.Any(p => p == ip)) return "本地连接";
|
||||
var ipSvr = DictHelper.RetrieveLocaleIPSvr();
|
||||
if (ipSvr.IsNullOrEmpty() || ipSvr.Equals("None", StringComparison.OrdinalIgnoreCase) || ip.IsNullOrEmpty() || _local.Any(p => p == ip)) return "本地连接";
|
||||
|
||||
return _ipLocator.GetOrAdd(ip, key =>
|
||||
{
|
||||
var ipSvr = DictHelper.RetrieveLocaleIPSvr();
|
||||
var url = $"{DictHelper.RetrieveLocaleIPSvrUrl(ipSvr)}{ip}";
|
||||
var ipSvrUrl = DictHelper.RetrieveLocaleIPSvrUrl(ipSvr);
|
||||
if (ipSvrUrl.IsNullOrEmpty()) return "本地连接";
|
||||
|
||||
var url = $"{ipSvrUrl}{ip}";
|
||||
var task = ipSvr == "BaiDuIPSvr" ? RetrieveLocator<BaiDuIPLocator>(url) : RetrieveLocator<JuheIPLocator>(url);
|
||||
task.Wait();
|
||||
return task.Result;
|
||||
|
|
Loading…
Reference in New Issue