From 50ad482974a7e838d11360a84e9e8ff3f7974ab2 Mon Sep 17 00:00:00 2001
From: wxr <wxr@hdlchina.com.cn>
Date: 星期六, 12 十月 2024 09:34:01 +0800
Subject: [PATCH] 金茂问题修复
---
HDL-ON_iOS/Other/JLCountrycode.cs | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/HDL-ON_iOS/Other/JLCountrycode.cs b/HDL-ON_iOS/Other/JLCountrycode.cs
index 176a7df..0346b43 100644
--- a/HDL-ON_iOS/Other/JLCountrycode.cs
+++ b/HDL-ON_iOS/Other/JLCountrycode.cs
@@ -2,6 +2,9 @@
using Shared.IOS.JLCountryCode;
using Foundation;
using System.Collections.Generic;
+using Newtonsoft.Json.Linq;
+using System.Net.Http;
+using System.Threading.Tasks;
namespace JLCountrycode
{
@@ -95,6 +98,39 @@
return newDictionary;
}
+ /// <summary>
+ /// 鏍规嵁鎵嬫満褰撳墠鐨処P鑾峰彇鍥藉淇℃伅
+ /// </summary>
+ /// <returns></returns>
+ public async Task<string> GetCountryByIP()
+ {
+ string country = "Unknown";
+
+ try
+ {
+ using (HttpClient client = new HttpClient())
+ {
+ // 浣跨敤 ipinfo.io 鑾峰彇浣嶇疆淇℃伅
+ HttpResponseMessage response = await client.GetAsync("https://ipinfo.io/json");
+
+ if (response.IsSuccessStatusCode)
+ {
+ string json = await response.Content.ReadAsStringAsync();
+ JObject jsonObject = JObject.Parse(json);
+
+ // 浠庤繑鍥炵殑 JSON 涓彁鍙栧浗瀹朵俊鎭�
+ country = jsonObject["country"].ToString();
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Error fetching IP info: {ex.Message}");
+ }
+
+ return country;
+ }
+
}
--
Gitblit v1.8.0