wxr
2024-09-26 0fc2962749e7e1f4078717a9914ac8175a2c4b26
HDL_ON/UI/UI1-Login/RegisterPageBLL.cs
@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading;
using HDL_ON.DAL.Server;
using HDL_ON.UI.CSS;
using Newtonsoft.Json.Linq;
using Shared;
namespace HDL_ON.UI.UI1Login
@@ -776,13 +778,34 @@
            waitPage.Start(Language.StringByID(StringId.PleaseWait));
            System.Threading.Tasks.Task.Run(() =>
            System.Threading.Tasks.Task.Run(async () =>
            {
                try
                {
                    Console.WriteLine("GetCountryByIP");
                    var ddd = JLCountrycode.CountryCodeView.Current.GetCountryByIP();
                    Console.WriteLine(ddd);
                    string country = "CN";
                    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)
                    {
                        MainPage.Log("Error",$"Error fetching IP info: {ex.StackTrace}");
                    }
                    serverList = new List<GlobalRegionListRes>();
                    var requestJson = HttpUtil.GetSignRequestJson(new GetRegionListObj() { regionMark = HttpUtil.RegionMark });
                    var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_GlobalRegionList, requestJson, HttpUtil.GlobalRequestHttpsHost);
@@ -796,12 +819,12 @@
                                serverList = responseDataObj;
                                if (serverList.Count > 0)
                                {
                                    if (Language.CurrentLanguage == "Chinese")
                                    if (country == "CN")//if (Language.CurrentLanguage == "Chinese")
                                    {
                                        var server = serverList.Find((obj) => obj.regionUrl.Contains("china-gateway"));
                                        if (server != null)
                                        {
                                            OnAppConfig.Instance.GlobalRegion.regionUrl = server.regionUrl;
                                            OnAppConfig.Instance.GlobalRegion = server;
                                            SetServerText();
                                        }
                                    }
@@ -810,7 +833,7 @@
                                        var server = serverList.Find((obj) => obj.regionUrl.Contains("bahrain-gateway"));
                                        if (server != null)
                                        {
                                            OnAppConfig.Instance.GlobalRegion.regionUrl = server.regionUrl;
                                            OnAppConfig.Instance.GlobalRegion = server;
                                            SetServerText();
                                        }
                                    }