From 4dc8adc2bf82f1827324c4dbefbc4477202bc433 Mon Sep 17 00:00:00 2001
From: wxr <wxr@hdlchina.com.cn>
Date: 星期一, 23 九月 2024 16:53:33 +0800
Subject: [PATCH] 服务器自动选择;i

---
 HDL_ON/UI/UI1-Login/SelectServerDialog.cs |   35 --------
 HDL_ON/Entity/Function/Function.cs        |   10 ++
 HDL_ON/UI/UI1-Login/LoginPageBLL.cs       |   16 ----
 HDL_ON/UI/UI1-Login/RegisterPageBLL.cs    |   82 ++++++++++++++++++++
 HDL-ON_iOS/Other/JLCountrycode.cs         |   36 +++++++++
 HDL_ON/Entity/DB_ResidenceData.cs         |    2 
 HDL_ON/UI/MainPage.cs                     |    2 
 HDL_ON/UI/UI1-Login/LoginPage.cs          |    2 
 HDL_ON/UI/UI1-Login/RegisterPage.cs       |    4 
 9 files changed, 137 insertions(+), 52 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;
+        }
+
 
 
     }
diff --git a/HDL_ON/Entity/DB_ResidenceData.cs b/HDL_ON/Entity/DB_ResidenceData.cs
index 67b7adf..5786b46 100644
--- a/HDL_ON/Entity/DB_ResidenceData.cs
+++ b/HDL_ON/Entity/DB_ResidenceData.cs
@@ -159,7 +159,7 @@
             FunctionList.List.ClearDatas();
 
             ///鍒囨崲浣忓畢娓呯┖鍓嶄綇瀹呯紦瀛樿嚜鍔ㄥ寲鍒楄〃锛�
-            HDL_ON.UI.UI2.Intelligence.Automation.Logic.LogicList.Clear();
+            UI.UI2.Intelligence.Automation.Logic.LogicList.Clear();
             DAL.Mqtt.MqttClient.DisConnectRemote("閫�鍑虹櫥褰曪紝鎴栬�呭垏鎹綇瀹�");
 
 #if IOS
diff --git a/HDL_ON/Entity/Function/Function.cs b/HDL_ON/Entity/Function/Function.cs
index aaa2157..0f71691 100644
--- a/HDL_ON/Entity/Function/Function.cs
+++ b/HDL_ON/Entity/Function/Function.cs
@@ -1727,6 +1727,16 @@
     public static class SPK
     {
         /// <summary>
+        /// 鏈煡SPK
+        /// (鑷畾涔�)
+        /// </summary>
+        public const string NULL = "NULL";
+        /// <summary>
+        /// 瑗垮ⅷ鍙瀵硅闂ㄥ彛鏈�
+        /// (鑷畾涔�)
+        /// </summary>
+        public const string LinphoneXiMo = "door.gate";
+        /// <summary>
         /// 缇ゆ帶锛堣嚜瀹氫箟锛�
         /// </summary>
         public const string GroupControl = "groupControl";
diff --git a/HDL_ON/UI/MainPage.cs b/HDL_ON/UI/MainPage.cs
index 96dbd6a..fe8645f 100644
--- a/HDL_ON/UI/MainPage.cs
+++ b/HDL_ON/UI/MainPage.cs
@@ -26,7 +26,7 @@
         /// <summary>
         /// 鐗堟湰鍙�
         /// </summary>
-        public static string VersionString = "2.5.1";
+        public static string VersionString = "2.7.0";
         ///// <summary>
         ///// 瀹㈡埛绔被鍨�
         ///// </summary>
diff --git a/HDL_ON/UI/UI1-Login/LoginPage.cs b/HDL_ON/UI/UI1-Login/LoginPage.cs
index 434c178..074f96c 100644
--- a/HDL_ON/UI/UI1-Login/LoginPage.cs
+++ b/HDL_ON/UI/UI1-Login/LoginPage.cs
@@ -320,7 +320,7 @@
                     etAccount.Text = "13682244600";
                     etAccount.Text = "pjh@hdlchina.com.cn";
                     etAccount.Text = "13580507523";
-                    etAccount.Text = "15313316909";
+                    etAccount.Text = "18475593023";
                 }
                 else
                 {
diff --git a/HDL_ON/UI/UI1-Login/LoginPageBLL.cs b/HDL_ON/UI/UI1-Login/LoginPageBLL.cs
index 096ad5c..58a951b 100644
--- a/HDL_ON/UI/UI1-Login/LoginPageBLL.cs
+++ b/HDL_ON/UI/UI1-Login/LoginPageBLL.cs
@@ -740,17 +740,6 @@
             if (loginResult.Code == StateCode.SUCCESS)
             {
                 var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<UserLoginRes>(loginResult.Data.ToString());
-                // UserInfo.Current = new UserInfo
-                //{
-                //    userType = revertData.userType,
-                //    accountString = account,
-                //    password = password,
-                //    lastTime = DateTime.Now,
-                //    ID = revertData.userId,
-                //    loginTokenString = revertData.headerPrefix + revertData.accessToken,
-                //    refreshToken = revertData.refreshToken,
-                //    userName = revertData.name
-                //};
                 if (OnAppConfig.Instance.LastLoginUserId != revertData.userId)
                 {
                     OnAppConfig.Instance.LastLoginUserId = revertData.userId;
@@ -759,17 +748,12 @@
                 UserInfo.Current.ClearUserInfo();
                 UserInfo.Current.userType = revertData.userType;
                 UserInfo.Current.AccountString = account;
-                //UserInfo.Current.password = password;
                 UserInfo.Current.LastTime = DateTime.Now;
                 UserInfo.Current.ID = revertData.userId;
                 UserInfo.Current.LoginTokenString = revertData.headerPrefix + revertData.accessToken;
                 UserInfo.Current.AccessToken = revertData.accessToken;
                 UserInfo.Current.RefreshToken = revertData.refreshToken;
                 UserInfo.Current.userName = revertData.name;
-                //UserInfo.Current.userMobileInfo = "";//閲嶇疆鐢ㄦ埛鎵嬫満
-                //UserInfo.Current.userEmailInfo = "";//閲嶇疆鐢ㄦ埛閭
-                //UserInfo.Current.headImagePagePath = "LoginIcon/2.png";//
-                //UserInfo.Current.CurrentRegion.RegionID = "";
                 UserInfo.Current.SaveUserInfo();
                 MainPage.Log("鐧诲綍鎴愬姛銆�");
 #if __IOS__
diff --git a/HDL_ON/UI/UI1-Login/RegisterPage.cs b/HDL_ON/UI/UI1-Login/RegisterPage.cs
index 8bcf14a..73b0979 100644
--- a/HDL_ON/UI/UI1-Login/RegisterPage.cs
+++ b/HDL_ON/UI/UI1-Login/RegisterPage.cs
@@ -245,6 +245,8 @@
                 {
                     OnAppConfig.Instance.GlobalRegion.regionUrl = "";
                 }
+                getServerList();
+
             }catch(Exception ex)
             {
                 MainPage.Log("Error", "杩涘叆娉ㄥ唽鐣岄潰AppConfig寮傚父锛�" + ex.Message);
@@ -271,7 +273,7 @@
                 Application.HideSoftInput();
             };
 
-            new TopViewDiv(this, bodyView, Language.StringByID(StringId.Register)).LoadTopView(backAction);
+            new TopViewDiv(this, bodyView, Language.StringByID(StringId.Register)) { maginY = 10 }.LoadTopView(backAction);
             //new PublicAssmebly().LoadTopView(this, bodyView, Language.StringByID(StringId.Register));
 
             #region 娉ㄥ唽鏂瑰紡閫夋嫨
diff --git a/HDL_ON/UI/UI1-Login/RegisterPageBLL.cs b/HDL_ON/UI/UI1-Login/RegisterPageBLL.cs
index cb6abf2..50aa11f 100644
--- a/HDL_ON/UI/UI1-Login/RegisterPageBLL.cs
+++ b/HDL_ON/UI/UI1-Login/RegisterPageBLL.cs
@@ -1,4 +1,5 @@
 锘縰sing System;
+using System.Collections.Generic;
 using System.Text.RegularExpressions;
 using System.Threading;
 using HDL_ON.DAL.Server;
@@ -9,6 +10,9 @@
 {
     public partial class RegisterPage
     {
+
+        List<GlobalRegionListRes> serverList;
+
         /// <summary>
         /// 鍔犺浇浜嬩欢鍒楄〃
         /// </summary>
@@ -760,5 +764,83 @@
             }
             return true;
         }
+
+
+        /// <summary>
+        /// 鑾峰彇鏈嶅姟鍣ㄥ垪琛�
+        /// </summary>
+        void getServerList()
+        {
+            var waitPage = new Loading();
+            bodyView.AddChidren(waitPage);
+            waitPage.Start(Language.StringByID(StringId.PleaseWait));
+
+
+            System.Threading.Tasks.Task.Run(() =>
+            {
+                try
+                {
+                    Console.WriteLine("GetCountryByIP");
+                    var ddd = JLCountrycode.CountryCodeView.Current.GetCountryByIP();
+                    Console.WriteLine(ddd);
+                    serverList = new List<GlobalRegionListRes>();
+                    var requestJson = HttpUtil.GetSignRequestJson(new GetRegionListObj() { regionMark = HttpUtil.RegionMark });
+                    var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_GlobalRegionList, requestJson, HttpUtil.GlobalRequestHttpsHost);
+                    if (revertObj.Code == StateCode.SUCCESS)
+                    {
+                        Application.RunOnMainThread(() =>
+                        {
+                            var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GlobalRegionListRes>>(revertObj.Data.ToString());
+                            if (responseDataObj != null)
+                            {
+                                serverList = responseDataObj;
+                                if (serverList.Count > 0)
+                                {
+                                    if (Language.CurrentLanguage == "Chinese")
+                                    {
+                                        var server = serverList.Find((obj) => obj.regionUrl.Contains("china-gateway"));
+                                        if (server != null)
+                                        {
+                                            OnAppConfig.Instance.GlobalRegion.regionUrl = server.regionUrl;
+                                            SetServerText();
+                                        }
+                                    }
+                                    else
+                                    {
+                                        var server = serverList.Find((obj) => obj.regionUrl.Contains("bahrain-gateway"));
+                                        if (server != null)
+                                        {
+                                            OnAppConfig.Instance.GlobalRegion.regionUrl = server.regionUrl;
+                                            SetServerText();
+                                        }
+                                    }
+                                }
+                            }
+                        });
+                    }
+                    else
+                    {
+                        //鎻愮ず閿欒
+                        IMessageCommon.Current.ShowErrorInfoAlter(revertObj.Code);
+                    }
+                }
+                catch
+                {
+
+                }
+                finally
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        if (waitPage != null)
+                        {
+                            waitPage.RemoveFromParent();
+                            waitPage = null;
+                        }
+                    });
+                }
+            });
+
+        }
     }
 }
\ No newline at end of file
diff --git a/HDL_ON/UI/UI1-Login/SelectServerDialog.cs b/HDL_ON/UI/UI1-Login/SelectServerDialog.cs
index 6d71973..671d5b8 100644
--- a/HDL_ON/UI/UI1-Login/SelectServerDialog.cs
+++ b/HDL_ON/UI/UI1-Login/SelectServerDialog.cs
@@ -44,7 +44,7 @@
             bodyView.BackgroundColor = CSS_Color.MainBackgroundColor;
             this.AddChidren(bodyView);
             //鍔犺浇椤堕儴鑿滃崟鏍�
-            new TopViewDiv(this, bodyView, Language.StringByID(StringId.PlsSelectServer)).LoadTopView();
+            new TopViewDiv(this, bodyView, Language.StringByID(StringId.PlsSelectServer)) { maginY = 10}.LoadTopView();
             //鍔犺浇鏈嶅姟鍣ㄥ尯鍩熼�夋嫨
             AddRegionalSelectionView();
             //Show
@@ -60,8 +60,8 @@
 
             VerticalScrolViewLayout VerticalScrolViewMiddle = new VerticalScrolViewLayout()
             {
-                Y = Application.GetRealHeight(74),
-                Height = bodyView.Height - Application.GetRealHeight(74),
+                Y = Application.GetRealHeight(84),
+                Height = bodyView.Height - Application.GetRealHeight(84),
                 ScrollEnabled = false,
             };
             bodyView.AddChidren(VerticalScrolViewMiddle);
@@ -125,35 +125,6 @@
                 }
             });
 
-            //var bottomView = new FrameLayout()
-            //{
-            //    Y = Application.GetRealHeight(591),
-            //    Height = Application.GetRealHeight(76) + Application.GetRealWidth(44),
-            //    Radius = (uint)Application.GetRealWidth(22),
-            //    BackgroundColor = CSS_Color.MainBackgroundColor,
-            //};
-            //bodyView.AddChidren(bottomView);
-
-
-            //btnConfrim = new Button()
-            //{
-            //    Gravity = Gravity.CenterHorizontal,
-            //    Y = Application.GetRealHeight(603),
-            //    Width = Application.GetRealWidth(220),
-            //    Height = Application.GetRealWidth(44),
-            //    Radius = (uint)Application.GetRealWidth(22),
-            //    BackgroundColor = CSS_Color.MainColor,
-            //    TextColor = CSS_Color.MainBackgroundColor,
-            //    TextSize = CSS_FontSize.SubheadingFontSize,
-            //    TextAlignment = TextAlignment.Center,
-            //    IsBold = true,
-            //    TextID = StringId.ConfirmAdd,
-            //};
-            //bodyView.AddChidren(btnConfrim);
-
-            //btnConfrim.MouseUpEventHandler = (sender, e) => {
-
-            //};
         }
 
         /// <summary>

--
Gitblit v1.8.0