From 5a5a2b696866f947b6025d26c3302e8ffef46435 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期一, 11 一月 2021 16:11:20 +0800
Subject: [PATCH] 2021-01-11 1.更新MQTT连接和本地搜索网关方法。2.子账号相关接口完善

---
 Crabtree/SmartHome/UI/SimpleControl/MainPage.cs |  565 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 471 insertions(+), 94 deletions(-)

diff --git a/Crabtree/SmartHome/UI/SimpleControl/MainPage.cs b/Crabtree/SmartHome/UI/SimpleControl/MainPage.cs
index 58ad594..46332c8 100644
--- a/Crabtree/SmartHome/UI/SimpleControl/MainPage.cs
+++ b/Crabtree/SmartHome/UI/SimpleControl/MainPage.cs
@@ -1,18 +1,16 @@
 
 using System;
-using Shared.IO;
-using Shared.Net;
 using System.Text;
 using System.Collections.Generic;
+using System.Net;
+using System.IO;
+using Shared.SimpleControl.Phone;
 // <summary>
 // 绋嬪簭涓诲叆鍙�
 // </summary>
 //using SystemConfiguration;
-using System.Net;
-using System.IO;
-using Shared.SimpleControl.Phone;
 namespace Shared.SimpleControl
-{
+{ 
     /// <summary>
     /// 涓婚〉闈�
     /// </summary>
@@ -38,21 +36,61 @@
         }
 
         //public static Button LogoButton = new Button ();
+  
 
-        public static string CodeIDString = "20191223";
+        public static string RequestVersion = "2.601071";
         public static UserInfo LoginUser;
+        /// <summary>
+        /// 鏄惁鏄鐞嗗憳鏉冮檺(鍙樻洿浜�,鎴愬憳鐨勬椂鍊�,杩欎釜涔熶负ture銆備负浠�涔堜細澹版槑杩欐牱鍙橀噺,鍥犱负鏈変簺鎺ュ彛蹇呴』浣跨敤鍘熸潵鐨凾oken)
+        /// </summary>
+        public static bool IsAdministrator {
+            get {
+                if (UserConfig.Instance == null || UserConfig.Instance.CurrentRegion == null) {
+                    return false;
+                } else {
+                    return UserConfig.Instance.CurrentRegion.IsOthreShare;
+                }
+            }
+        }
 
+        ///// <summary>
+        ///// 鏄惁璐﹀彿鍦ㄥ叾瀹冭澶囩櫥褰曚簡
+        ///// </summary>
+        //public static bool IsOtherDevicesLogin = false;
+
+//#if __IOS__
+//        public static readonly string PhoneType = "iOS";
+//#else
+//         public static readonly string PhoneType = "Android";
+//#endif
 
         public static string SoftPadTitle = "Crabtree";
         public static string SoftTitle = "Crabtree";
         public static int SoftSmsType = 0;
+        public static string RequestSource = "1"; //0:Zigbee銆�1:HdlOn銆�2:GraphicsMonitor銆�3:BusproSoft銆�4:AgentWeb
+
         public static string LogoString = "";//"Logo/Logo.png";
         public static string WiFiStatus = "CrabtreeAdd/WiFi.png";//"CrabtreeAdd/WiFi.png";
         public static string RegisterLogoString = "Logo/Register_logo.png";
         public static string SeviceIP = "52.172.25.151";
-        //public static string RequestHttpsHost = "https://homeautomation.havells.com";
-        public static string RequestHttpsHost = "https://developer.hdlcontrol.com";
+        public static string RequestHttpsHost = "https://smarth-api.havells.com/HangZhouHdlCloudApi";
+        //public static string RequestHttpsHost = "https://global.hdlcontrol.com/HangZhouHdlCloudApi";
 
+        //public static string RequestHttpsHostMqtt = "https://smarth-api.havells.com";
+
+        //public static string RequestHttpsHost = "https://developer.hdlcontrol.com";
+
+        #region GetDesignHeight
+        /// <summary>
+        /// 鑾峰彇view鐨勮绠楅珮搴︼紝ON杞欢涓轰簡閫傞厤鍏ㄩ潰鐗规畩浣跨敤鐨勬瘮渚嬫柟娉曪紝鐢变簬涓�浜涜儗鏅浘鐗囨槸鐩存帴鍏ㄩ儴濉厖鐨勶紝鏀瑰姩鎴愪笁灞傜殑锛坴iew-button-button)鐨勫伐浣滈噺寰堝ぇ锛屼笉绂侀渶瑕佸鍔犱竴涓獀iew锛岃繕闇�瑕佷慨鏀瑰浘鐗�
+        /// </summary>
+        /// <returns>The view height.</returns>
+        public static int GetDesignHeight (int height)
+        {
+            int ss = Convert.ToInt32 (height / PixelScale);
+            return Application.GetRealHeight (ss);
+        }
+        #endregion
 
         public static double PixelScale {
             get {
@@ -101,6 +139,9 @@
                     Application.DesignWidth = 640;
                     Application.DesignHeight = 1136;
                 }
+                //鍗板害瀹㈡埛瀹氬埗APP榛樿浣跨敤鑻辨枃
+                Language.CurrentLanguage = "English";
+
                 Shared.BusSocket.Start (6000);
                 CommonPage.InitReceiveEvent ();
 
@@ -111,11 +152,17 @@
                 } else {
                     Phone.UserHomePage.Init ();
 #if __IOS__
-                    //Loading.LodingBackgroundColor = 0x10777777;
+               //Loading.LodingBackgroundColor = 0x10777777;
+
 #else
-                    Loading.LodingBackgroundColor = SkinStyle.Current.MainColor;
+              //Loading.LodingBackgroundColor = SkinStyle.Current.MainColor;
 #endif
+                    Loading.TextColor = 0xFFA9A9A9;
+                    Loading.LodingBackgroundColor = SkinStyle.Current.MainColor;
                 }
+
+                CommonUtlis.Current.CheckIfJailBreak ();
+
             } catch (Exception ex) {
                 //new Alert ("Eorr", ex.Message, "Close").Show();
             }
@@ -123,7 +170,7 @@
 
 
         /// <summary>
-        /// 澧炲姞rjfi
+        /// 寮瑰嚭閿欒鎻愮ず
         /// </summary>
         /// <param name="tip">Tip.</param>
         /// <param name="time">Time.</param>
@@ -137,11 +184,13 @@
                     Gravity = Gravity.Center,
                     Width = Application.GetRealWidth (560),
                     Height = Application.GetRealHeight (126),
-                    BackgroundColor = SkinStyle.Current.AddTipButtonColor,
+                    //BackgroundColor = SkinStyle.Current.AddTipButtonColor,
+                    BackgroundColor = SkinStyle.Current.MainColor,
                     Radius = 10,
                     IsMoreLines = true,
                     Text = tip,
                     TextSize = 16,
+                    TextColor = 0xFF000000
                 };
                 MainFrameLayout.AddChidren (button);
                 button.MouseUpEventHandler += (sender, e) => {
@@ -158,6 +207,53 @@
 
         static DateTime requesTime = DateTime.MinValue;
         static bool isShowLoading = true;
+        ///// <summary>
+        ///// 璇锋眰鏈嶅姟鍣ㄦ柟娉�
+        ///// </summary>
+        ///// <returns>The https.</returns>
+        ///// <param name="methodType">璇锋眰鏂规硶.</param>
+        ///// <param name="dataStringJson">璇锋眰鐨勫弬鏁�.</param>
+        ///// <param name="needHeaders">鏄惁闇�瑕佸寘澶�.</param>
+        //public static ResponsePack RequestHttpsOld (string methodType, string dataStringJson, string urlHead = "")
+        //{
+        //    ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, error) => {
+        //        return true;
+        //    };
+
+        //    #region
+        //    var webClient = new WebClient ();
+        //    if (urlHead == "") {
+        //        urlHead = RequestHttpsHost;
+        //    }
+        //    //else {
+        //    //    webClient.Headers.Add ("CONTENT-TYPE", "application/json");
+        //    //}
+        //    webClient.Headers.Add ("CONTENT-TYPE", "application/json");
+        //    string url = urlHead + methodType;
+        //    if (LoginUser != null) {/* 濡傛灉涓嶉渶瑕侀獙璇乀oken鍙互涓嶇敤浼犲叆 */
+        //        webClient.Headers.Add ("Authorization", LoginUser.LoginTokenString);
+        //    }
+        //    byte [] bytes = null;
+        //    try {
+        //        bytes = webClient.UploadData (url, Encoding.UTF8.GetBytes (dataStringJson));
+        //    } catch (System.Net.WebException webEx) {
+        //        //Application.RunOnMainThread (() => {
+        //        //    MainPage.Loading.Hide ();
+        //        //});
+        //        return new ResponsePack () { StateCode = ErrorCode.NetworkError };
+        //    }
+        //    string responseString = Encoding.UTF8.GetString (bytes);
+           
+        //    try {
+        //        return Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack> (responseString);
+        //    } catch (Exception ex) {
+        //        Utlis.WriteLine (ex.ToString ());
+        //        return new ResponsePack () { StateCode = "Data exception" };
+        //    }
+        //    #endregion
+
+        //}
+
         /// <summary>
         /// 璇锋眰鏈嶅姟鍣ㄦ柟娉�
         /// </summary>
@@ -165,40 +261,24 @@
         /// <param name="methodType">璇锋眰鏂规硶.</param>
         /// <param name="dataStringJson">璇锋眰鐨勫弬鏁�.</param>
         /// <param name="needHeaders">鏄惁闇�瑕佸寘澶�.</param>
-        public static ResponsePack RequestHttps (string methodType, string dataStringJson, bool needHeaders = true, bool needTip = true,string urlHead = "")
+        public static byte [] RequestHttpsReturnByte (string methodType, string dataStringJson, bool needHeaders = false, string urlHead = "")
         {
             ResponsePack revertObj = null;
             try {
-                if (!SystemRemote.checeInternet ()) {
-                    Application.RunOnMainThread (() => {
-                        MainPage.WiFiStatus = "CrabtreeAdd/WiFiUnlink.png";
-                        MainPage.Loading.Hide ();
-                    });
-                }
-                //new System.Threading.Thread (() => {
-                //    requesTime = DateTime.Now;
-                //    isShowLoading = true;
-                //    while (isShowLoading) {
-                //        System.Threading.Thread.Sleep (1000);
-                //        if (requesTime == DateTime.MinValue) {
-                //            break;
-                //        }
-                //        if (requesTime.AddSeconds (30) < DateTime.Now) {
-                //            Application.RunOnMainThread (Loading.Hide);
-                //            isShowLoading = false;
-                //        }
-                //    }
-                //}) { IsBackground = true }.Start ();
 
+                ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, error) => {
+                    return true;
+                };
 
                 #region
                 var webClient = new WebClient ();
                 if (urlHead == "") {
-                    urlHead = $"{RequestHttpsHost}/WebApi/";
-                    urlHead = "https://developer.hdlcontrol.com/api/";
-                } else {
-                    webClient.Headers.Add ("CONTENT-TYPE", "application/json");
+                    urlHead = RequestHttpsHost;
                 }
+                //else {
+                //    webClient.Headers.Add ("CONTENT-TYPE", "application/json");
+                //}
+                webClient.Headers.Add ("CONTENT-TYPE", "application/json");
                 string url = urlHead + methodType;
                 if (needHeaders && LoginUser != null) {/* 濡傛灉涓嶉渶瑕侀獙璇乀oken鍙互涓嶇敤浼犲叆 */
                     webClient.Headers.Add ("Authorization", LoginUser.LoginTokenString);
@@ -207,76 +287,363 @@
                 try {
                     bytes = webClient.UploadData (url, Encoding.UTF8.GetBytes (dataStringJson));
                 } catch (System.Net.WebException webEx) {
-                    Application.RunOnMainThread (() => {
-                        MainPage.Loading.Hide ();
-                        revertObj = new ResponsePack () { StateCode = "Network_Error" };
-                        //new Alert ( "","Network abnormal, unable to connect to the Internet", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
-                        return;
-                    });
+                    return bytes;
                 }
-                string responseString = null;
-                if (bytes != null) {
-                    responseString = Encoding.UTF8.GetString (bytes);
-                }
-
-                //var request = (HttpWebRequest)WebRequest.Create (url);
-                //var data = Encoding.UTF8.GetBytes (dataStringJson);
-                //request.Method = "POST";
-                //request.ContentLength = data.Length;
-                //if (needHeaders) {/* 濡傛灉涓嶉渶瑕侀獙璇乀oken鍙互涓嶇敤浼犲叆 */
-                //    request.Headers.Set (HttpRequestHeader.Authorization, LoginUser.LoginTokenString);
-                //}
-                //using (var stream = request.GetRequestStream ()) {
-                //    stream.Write (data, 0, data.Length);
-                //}
-                //var response = (HttpWebResponse)request.GetResponse ();
-                //var responseString = new StreamReader (response.GetResponseStream ()).ReadToEnd ();
-
-                if (responseString != null) {
-                    try {
-                        revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack> (responseString);
-                        if (revertObj.StateCode != "SUCCESS") {
-                            if (methodType == "IsExistingAccount") {
-
-                            } else if (needTip) {
-                                Application.RunOnMainThread (() => {
-                                    new Alert ("", revertObj.ErrorInfo, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
-                                });
-                            }
-                        }
-                    } catch (Exception ex) {
-                        Console.WriteLine (ex.ToString ());
-                    }
-                } else {
-                    if (methodType == "Login" && needTip) {
-                        Application.RunOnMainThread (() => {
-                            new Alert ("", Language.StringByID (R.MyInternationalizationString.FailureToDataBase),
-                                       Language.StringByID (R.MyInternationalizationString.Close)).Show ();
-                        });
-                    } else {
-                        if (needTip)
-                            FailureToServer ();
-                    }
-                }
-                return revertObj;
+             
+            
+                return bytes;
                 #endregion
             } catch (Exception ex) {
-                Console.WriteLine (ex.Message);
-                return revertObj;
+                Utlis.WriteLine (ex.Message);
+                return null;
             } finally {
                 //requesTime = requesTime.AddDays(1);
             }
         }
+
+
+        /// <summary>
+        /// 璇锋眰鏈嶅姟鍣ㄦ柟娉�
+        /// </summary>
+        /// <returns>The https.</returns>
+        /// <param name="methodType">璇锋眰鏂规硶.</param>
+        public static ResponsePack RequestHttpsNewBig (string methodType, byte [] byteData, UploadHomeAppGatewaySubFilesBigObj mUploadHomeAppGatewaySubFilesBigObj, string urlHead = "", int mTimeout = 10, string requestMethod = "POST")
+        {
+            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, error) => {
+                return true;
+            };
+            #region HttpWebRequest
+            try {
+
+                if (urlHead == "") {
+                    urlHead = RequestHttpsHost;
+                }
+                string requestFullUrl = urlHead + methodType;
+                //鍒濆鍖栨柊鐨剋ebRequst
+                //1锛� 鍒涘缓httpWebRequest瀵硅薄
+                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create (new Uri (requestFullUrl));
+
+                //2锛� 鍒濆鍖朒ttpWebRequest瀵硅薄
+                webRequest.Method = requestMethod;
+                //webRequest.Timeout = mTimeout * 1000;
+                webRequest.Headers.Add (HttpRequestHeader.Authorization, LoginUser.LoginTokenString);
+                webRequest.Headers.Add ("RequestVersion", mUploadHomeAppGatewaySubFilesBigObj.RequestVersion);
+                webRequest.Headers.Add ("LoginAccessToken", LoginUser.LoginTokenString);
+                webRequest.Headers.Add ("HomeId", mUploadHomeAppGatewaySubFilesBigObj.HomeId);
+                webRequest.Headers.Add ("BackupClassId", mUploadHomeAppGatewaySubFilesBigObj.BackupClassId);
+                webRequest.Headers.Add ("FileName", mUploadHomeAppGatewaySubFilesBigObj.FileName);
+                webRequest.Headers.Add ("IsOtherAccountCtrl", mUploadHomeAppGatewaySubFilesBigObj.IsOtherAccountCtrl.ToString ());
+
+                //var byteData = new byte [] { }锛�//Encoding.UTF8.GetBytes (dataStringJson);
+                //if (LoginUser != null) {/* 濡傛灉涓嶉渶瑕侀獙璇乀oken鍙互涓嶇敤浼犲叆 */
+                //    //瀵瑰簲寰俊缃戝潃
+
+                //}
+
+                if (requestMethod == "GET") {
+                    //webRequest.ContentType = "text/html";
+                    webRequest.ContentType = "application/json";
+                } else {
+                    webRequest.ContentType = "application/octet-stream";
+                    //webRequest.ContentType = "application/json";
+                    webRequest.ContentLength = byteData.Length;
+
+                    //3锛� 闄勫姞瑕丳OST缁欐湇鍔″櫒鐨勬暟鎹埌HttpWebRequest瀵硅薄(闄勫姞POST鏁版嵁鐨勮繃绋嬫瘮杈冪壒娈婏紝瀹冨苟娌℃湁鎻愪緵涓�涓睘鎬х粰鐢ㄦ埛瀛樺彇锛岄渶瑕佸啓鍏ttpWebRequest瀵硅薄鎻愪緵鐨勪竴涓猻tream閲岄潰銆�)
+                    var newStream = webRequest.GetRequestStream ();//鍒涘缓涓�涓猄tream,璧嬪�兼槸鍐欏叆HttpWebRequest瀵硅薄鎻愪緵鐨勪竴涓猻tream閲岄潰
+                    newStream.Write (byteData, 0, byteData.Length);
+                    newStream.Flush ();
+                    newStream.Close ();
+                }
+
+                //4锛� 璇诲彇鏈嶅姟鍣ㄧ殑杩斿洖淇℃伅
+                var response = (HttpWebResponse)webRequest.GetResponse ();
+                using (var stream = response.GetResponseStream ()) {
+                    if (stream == null) {
+                        return new ResponsePack () { StateCode = ErrorCode.NetworkError };
+                    }
+                    var ms = new MemoryStream ();
+                    var bytes = new byte [1024];
+                    var len = int.MaxValue;
+                    while (stream.CanRead && 0 < len) {
+                        len = stream.Read (bytes, 0, bytes.Length);
+                        ms.Write (bytes, 0, len);
+                    }
+                    //var backBytes = ms.ToArray ();
+                    string responseString = Encoding.UTF8.GetString (ms.ToArray ());
+
+                    try {
+                        ResponsePack revertObj = new ResponsePack () { };
+                        revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack> (responseString);
+                        if (revertObj.StateCode == null) {
+                            revertObj.StateCode = "Data Exception";
+                        }
+                        return revertObj;
+                    } catch (Exception ex) {
+                        Shared.Utlis.WriteLine (ex.ToString ());
+                        return new ResponsePack () { StateCode = "Data Exception" };
+                    }
+
+                    //return ms.ToArray ();
+                }
+            } catch (Exception ex) {
+#if DEBUG
+                System.Console.WriteLine (ex.Message);
+#endif
+                //The operation has timed out
+                return new ResponsePack () { StateCode = ErrorCode.NetworkError };
+            }
+
+            #endregion
+
+        }
+
+        /// <summary>
+        /// 璇锋眰鏈嶅姟鍣ㄦ柟娉�
+        /// 2020-06-22 甯﹁嚜瀹氫箟璇锋眰瓒呮椂 鏃堕棿鏂规硶
+        /// </summary>
+        /// <returns>The https.</returns>
+        /// <param name="methodType">璇锋眰鏂规硶.</param>
+        /// <param name="dataStringJson">璇锋眰鐨勫弬鏁�.</param>
+        /// <param name="needHeaders">鏄惁闇�瑕佸寘澶�.</param>
+        public static ResponsePack RequestHttps (string methodType, string dataStringJson, string urlHead = "", int mTimeout = 10, string requestMethod = "POST")
+        {
+            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, error) => {
+                return true;
+            };
+
+
+            #region HttpWebRequest
+
+            try {
+
+                if (urlHead == "") {
+                    urlHead = RequestHttpsHost;
+                }
+                string requestFullUrl = urlHead + methodType;
+
+                //鍒濆鍖栨柊鐨剋ebRequst
+                //1锛� 鍒涘缓httpWebRequest瀵硅薄
+                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create (new Uri (requestFullUrl));
+
+                //2锛� 鍒濆鍖朒ttpWebRequest瀵硅薄
+                webRequest.Method = requestMethod;
+
+                webRequest.Timeout = mTimeout * 1000;
+
+                var byteData = Encoding.UTF8.GetBytes (dataStringJson);
+
+                if (LoginUser != null) {/* 濡傛灉涓嶉渶瑕侀獙璇乀oken鍙互涓嶇敤浼犲叆 */
+                    //瀵瑰簲寰俊缃戝潃
+                    webRequest.Headers.Add (HttpRequestHeader.Authorization, LoginUser.LoginTokenString);
+                }
+                if (requestMethod == "GET") {
+                    //webRequest.ContentType = "text/html";
+                    webRequest.ContentType = "application/json";
+                } else {
+                    webRequest.ContentType = "application/json";
+                    webRequest.ContentLength = byteData.Length;
+
+                    //3锛� 闄勫姞瑕丳OST缁欐湇鍔″櫒鐨勬暟鎹埌HttpWebRequest瀵硅薄(闄勫姞POST鏁版嵁鐨勮繃绋嬫瘮杈冪壒娈婏紝瀹冨苟娌℃湁鎻愪緵涓�涓睘鎬х粰鐢ㄦ埛瀛樺彇锛岄渶瑕佸啓鍏ttpWebRequest瀵硅薄鎻愪緵鐨勪竴涓猻tream閲岄潰銆�)
+                    var newStream = webRequest.GetRequestStream ();//鍒涘缓涓�涓猄tream,璧嬪�兼槸鍐欏叆HttpWebRequest瀵硅薄鎻愪緵鐨勪竴涓猻tream閲岄潰
+                    newStream.Write (byteData, 0, byteData.Length);
+                    newStream.Flush ();
+                    newStream.Close ();
+                }
+
+                //4锛� 璇诲彇鏈嶅姟鍣ㄧ殑杩斿洖淇℃伅
+                var response = (HttpWebResponse)webRequest.GetResponse ();
+                using (var stream = response.GetResponseStream ()) {
+                    if (stream == null) {
+                        return new ResponsePack () { StateCode = ErrorCode.NetworkError };
+                    }
+                    var ms = new MemoryStream ();
+                    var bytes = new byte [1024];
+                    var len = int.MaxValue;
+                    while (stream.CanRead && 0 < len) {
+                        len = stream.Read (bytes, 0, bytes.Length);
+                        ms.Write (bytes, 0, len);
+                    }
+                    //var backBytes = ms.ToArray ();
+                    string responseString = Encoding.UTF8.GetString (ms.ToArray ());
+
+                    try {
+                        ResponsePack revertObj = new ResponsePack () { };
+                        revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack> (responseString);
+                        if (revertObj.StateCode == null) {
+                            revertObj.StateCode = "Data Exception";
+                        }
+                        return revertObj;
+                    } catch (Exception ex) {
+                        Shared.Utlis.WriteLine (ex.ToString ());
+                        return new ResponsePack () { StateCode = "Data Exception" };
+                    }
+
+                    //return ms.ToArray ();
+                }
+            } catch (Exception ex) {
+#if DEBUG
+                System.Console.WriteLine (ex.Message);
+#endif
+                //The operation has timed out
+                return new ResponsePack () { StateCode = ErrorCode.NetworkError };
+            }
+
+            #endregion
+
+        }
+
+        public const int TIME_OUT_20 = 30;
+        /// <summary>
+        /// 涓嬭浇鏂囦欢鏂规硶
+        /// </summary>
+        /// <param name="methodType"></param>
+        /// <param name="dataStringJson"></param>
+        /// <param name="urlHead"></param>
+        /// <param name="mTimeout"></param>
+        /// <param name="requestMethod"></param>
+        /// <returns></returns>
+        public static byte [] RequestHttpsReturnByteNew (string methodType, string dataStringJson, string urlHead = "", int mTimeout = 20, string requestMethod = "POST")
+        {
+            try {
+                #region
+                if (urlHead == "") {
+                    urlHead = RequestHttpsHost;
+                }
+                string requestFullUrl = urlHead + methodType;
+
+                //鍒濆鍖栨柊鐨剋ebRequst
+                //1锛� 鍒涘缓httpWebRequest瀵硅薄
+                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create (new Uri (requestFullUrl));
+
+                //2锛� 鍒濆鍖朒ttpWebRequest瀵硅薄
+                webRequest.Method = requestMethod;
+                //webRequest.Timeout = timeout * 1000;
+                //鍙栨秷浣跨敤浠g悊璁块棶
+                webRequest.Proxy = null;
+                webRequest.UseDefaultCredentials = false;
+              
+                if (requestMethod == "GET") {
+                    webRequest.ContentType = "application/json";
+                } else {
+                    var byteData = Encoding.UTF8.GetBytes (dataStringJson);
+                    webRequest.ContentType = "application/json";
+                    webRequest.ContentLength = byteData.Length;
+                    //3锛� 闄勫姞瑕丳OST缁欐湇鍔″櫒鐨勬暟鎹埌HttpWebRequest瀵硅薄(闄勫姞POST鏁版嵁鐨勮繃绋嬫瘮杈冪壒娈婏紝瀹冨苟娌℃湁鎻愪緵涓�涓睘鎬х粰鐢ㄦ埛瀛樺彇锛岄渶瑕佸啓鍏ttpWebRequest瀵硅薄鎻愪緵鐨勪竴涓猻tream閲岄潰銆�)
+                    var newStream = webRequest.GetRequestStream ();//鍒涘缓涓�涓猄tream,璧嬪�兼槸鍐欏叆HttpWebRequest瀵硅薄鎻愪緵鐨勪竴涓猻tream閲岄潰
+                    newStream.Write (byteData, 0, byteData.Length);
+                    newStream.Flush ();
+                    newStream.Close ();
+                }
+
+                //4锛� 璇诲彇鏈嶅姟鍣ㄧ殑杩斿洖淇℃伅
+                var response = (HttpWebResponse)webRequest.GetResponse ();
+                using (var stream = response.GetResponseStream ()) {
+                    if (stream == null) {
+                        return null;
+                    }
+                    var ms = new MemoryStream ();
+                    var bytes = new byte [1024];
+                    var len = int.MaxValue;
+                    while (stream.CanRead && 0 < len) {
+                        len = stream.Read (bytes, 0, bytes.Length);
+                        ms.Write (bytes, 0, len);
+                    }
+                    return ms.ToArray ();
+                }
+                #endregion
+            } catch (WebException e) {
+                //if (e.Status == WebExceptionStatus.ConnectFailure//鐢辨湁缃戠粶鍒囨崲鍒版棤缃戠粶鏃惰Е鍙�
+                //    || e.Status == WebExceptionStatus.Timeout//瓒呮椂
+                //    || e.Status == WebExceptionStatus.NameResolutionFailure)//鏈韩灏辨槸鏃犵綉缁滄椂鍚姩鏃惰Е鍙�
+                //{
+                //    //Phone.UserCenter.HdlWifiLogic.Current.CanAccessHttp = false;
+                //}
+                return null;
+            } catch (Exception e) {
+                return null;
+            }
+        }
+
+        #region LoadingTipMsg 杩滅▼杩炴帴Tip
+
+        static Button btnLoadingTipMsg;
+
+        public static void LoadingTipShow (string tip)
+        {
+
+            if (MainFrameLayout == null) {
+                return;
+            }
+
+            Application.RunOnMainThread (() => {
+                try {
+                    if (btnLoadingTipMsg == null) {
+                        btnLoadingTipMsg = new Button () {
+                            Height = Application.GetRealHeight (90),
+                            BackgroundColor = SkinStyle.Current.MainColor,
+                            //BackgroundColor = 0xFF000000,
+                            Y = Application.GetRealHeight (36),
+                            TextAlignment = TextAlignment.Center,
+                            TextColor = 0xFF000000,
+                        };
+                    }
+                    if (btnLoadingTipMsg.Parent == null) {
+                        MainFrameLayout.AddChidren (btnLoadingTipMsg);
+                        if (btnLoadingTipMsg.MouseUpEventHandler == null) {
+                            btnLoadingTipMsg.MouseUpEventHandler += (sender, e) => {
+                                if (btnLoadingTipMsg.Parent != null)
+                                    btnLoadingTipMsg.RemoveFromParent ();
+                            };
+                        }
+                    }
+
+                    btnLoadingTipMsg.Text = tip;
+
+                } catch { }
+            });
+        }
+
+        public static void LoadingTipHide ()
+        {
+            if (MainFrameLayout == null) {
+                return;
+            }
+            Application.RunOnMainThread (() => {
+                try {
+                    if (btnLoadingTipMsg != null) {
+                        if (btnLoadingTipMsg.Parent != null)
+                            btnLoadingTipMsg.RemoveFromParent ();
+                    }
+
+                } catch { }
+            });
+        }
+
+        #endregion
+
         /// <summary>
         /// 杩炴帴鏈嶅姟鍣ㄥけ璐�
         /// </summary>
         public static void FailureToServer ()
         {
+            //Application.RunOnMainThread (() => {
+            //    new Alert ("", Language.StringByID (R.MyInternationalizationString.FailureToServer),
+            //               Language.StringByID (R.MyInternationalizationString.Close)).Show ();
+            //});
+            ShowAlertOnMainThread (ErrorCode.FailedRequestServer);
+        }
+
+        /// <summary>
+        /// 2020-01-11 寮圭獥鎻愮ず
+        /// </summary>
+        /// <param name="mes"></param>
+        public static void ShowAlertOnMainThread (string mes)
+        {
             Application.RunOnMainThread (() => {
-                new Alert ("", Language.StringByID (R.MyInternationalizationString.FailureToServer),
-                           Language.StringByID (R.MyInternationalizationString.Close)).Show ();
+                new Alert ("", mes, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
             });
         }
+
 
         /// <summary>
         /// 璁惧涓嶅湪绾匡紝鏃犲搷搴�
@@ -296,11 +663,21 @@
             });
         }
 
+        public static void LoadingSetText (string showString = "")
+        {
+            Application.RunOnMainThread (() => {
+                MainPage.Loading.Text = showString;
+            });
+        }
+
         public static void LoadingHide ()
         {
             Application.RunOnMainThread (() => {
                 MainPage.Loading.Hide ();
             });
         }
+
+       
+
     }
-}
\ No newline at end of file
+}

--
Gitblit v1.8.0