From bbc74a6dae2e90a811b2507c5896fe89aa29ccc0 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期三, 08 一月 2020 11:30:46 +0800
Subject: [PATCH] 2020-01-08 1.替换新服务器接口。

---
 Crabtree/SmartHome/UI/SimpleControl/MainPage.cs |  154 +++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 113 insertions(+), 41 deletions(-)

diff --git a/Crabtree/SmartHome/UI/SimpleControl/MainPage.cs b/Crabtree/SmartHome/UI/SimpleControl/MainPage.cs
index 24c4766..fdf907a 100644
--- a/Crabtree/SmartHome/UI/SimpleControl/MainPage.cs
+++ b/Crabtree/SmartHome/UI/SimpleControl/MainPage.cs
@@ -39,18 +39,29 @@
 
         //public static Button LogoButton = new Button ();
 
-        public static string CodeIDString = "20191223";
+        public static string RequestVersion = "20200108";
         public static UserInfo LoginUser;
-
+        /// <summary>
+        /// 鏄惁鏄鐞嗗憳鏉冮檺(鍙樻洿浜�,鎴愬憳鐨勬椂鍊�,杩欎釜涔熶负ture銆備负浠�涔堜細澹版槑杩欐牱鍙橀噺,鍥犱负鏈変簺鎺ュ彛蹇呴』浣跨敤鍘熸潵鐨凾oken)
+        /// </summary>
+        public static bool IsAdministrator = false;
 
         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://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";
+
 
         public static double PixelScale {
             get {
@@ -163,7 +174,7 @@
         /// <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 ResponsePack RequestHttps (string methodType, string dataStringJson, bool needHeaders = false, bool needTip2 = true, string urlHead = "")
         {
             ResponsePack revertObj = null;
             try {
@@ -173,28 +184,32 @@
                         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 ();
+                //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 ();
 
 
                 #region
-                urlHead = $"{"https://homeautomation.havells.com"}/WebApi/";
-                urlHead = "https://developer.hdlcontrol.com/api/";
-                string url = urlHead + methodType;
-
                 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 (needHeaders && LoginUser != null) {/* 濡傛灉涓嶉渶瑕侀獙璇乀oken鍙互涓嶇敤浼犲叆 */
                     webClient.Headers.Add ("Authorization", LoginUser.LoginTokenString);
                 }
@@ -204,7 +219,7 @@
                 } catch (System.Net.WebException webEx) {
                     Application.RunOnMainThread (() => {
                         MainPage.Loading.Hide ();
-                        revertObj = new ResponsePack () { StateCode = "Network_Error" };
+                        revertObj = new ResponsePack () { StateCode = ErrorCode.NetworkError };
                         //new Alert ( "","Network abnormal, unable to connect to the Internet", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                         return;
                     });
@@ -212,6 +227,7 @@
                 string responseString = null;
                 if (bytes != null) {
                     responseString = Encoding.UTF8.GetString (bytes);
+                    //var DD = Newtonsoft.Json.Linq.JObject .Parse("GFGFDG");DD["ResponseData"]["PageData"]
                 }
 
                 //var request = (HttpWebRequest)WebRequest.Create (url);
@@ -230,28 +246,31 @@
                 if (responseString != null) {
                     try {
                         revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack> (responseString);
-                        if (revertObj.StateCode != "SUCCESS") {
-                            if (methodType == "IsExistingAccount") {
+                        //if (revertObj.StateCode.ToUpper()  != "SUCCESS") {
+                        //    if (methodType == API.IsExistingAccount) {
 
-                            } else if (needTip) {
-                                Application.RunOnMainThread (() => {
-                                    new Alert ("", revertObj.ErrorInfo, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
-                                });
-                            }
-                        }
+                        //    } else if (needTip) {
+                        //        Application.RunOnMainThread (() => {
+                        //            new Alert ("", revertObj.ErrorInfo, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
+                        //        });
+                        //    }
+                        //}
                     } catch (Exception ex) {
                         Console.WriteLine (ex.ToString ());
+                        revertObj = new ResponsePack () { StateCode = "Data exception" };          
                     }
-                } else {
-                    if (methodType == "Login" && needTip) {
-                        Application.RunOnMainThread (() => {
-                            new Alert ("", Language.StringByID (R.MyInternationalizationString.FailureToDataBase),
-                                       Language.StringByID (R.MyInternationalizationString.Close)).Show ();
-                        });
-                    } else {
-                        if (needTip)
-                            FailureToServer ();
-                    }
+                }
+                else {
+                    revertObj = new ResponsePack () { StateCode = ErrorCode.NetworkError };
+                    //if (methodType == API.Login && needTip) {
+                    //    Application.RunOnMainThread (() => {
+                    //        new Alert ("", Language.StringByID (R.MyInternationalizationString.FailureToDataBase),
+                    //                   Language.StringByID (R.MyInternationalizationString.Close)).Show ();
+                    //    });
+                    //} else {
+                    //    if (needTip)
+                    //        FailureToServer ();
+                    //}
                 }
                 return revertObj;
                 #endregion
@@ -262,6 +281,59 @@
                 //requesTime = requesTime.AddDays(1);
             }
         }
+
+        /// <summary>
+        /// 璇锋眰鏈嶅姟鍣ㄦ柟娉�
+        /// </summary>
+        /// <returns>The https.</returns>
+        /// <param name="methodType">璇锋眰鏂规硶.</param>
+        /// <param name="dataStringJson">璇锋眰鐨勫弬鏁�.</param>
+        /// <param name="needHeaders">鏄惁闇�瑕佸寘澶�.</param>
+        public static byte [] RequestHttpsReturnByte (string methodType, string dataStringJson, bool needHeaders = false, bool needTip2 = true, string urlHead = "")
+        {
+            ResponsePack revertObj = null;
+            try {
+                if (!SystemRemote.checeInternet ()) {
+                    Application.RunOnMainThread (() => {
+                        MainPage.WiFiStatus = "CrabtreeAdd/WiFiUnlink.png";
+                        MainPage.Loading.Hide ();
+                    });
+                }
+            
+
+
+                #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 (needHeaders && 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) {
+                    return bytes;
+                }
+             
+            
+                return bytes;
+                #endregion
+            } catch (Exception ex) {
+                Console.WriteLine (ex.Message);
+                return null;
+            } finally {
+                //requesTime = requesTime.AddDays(1);
+            }
+        }
+
+
         /// <summary>
         /// 杩炴帴鏈嶅姟鍣ㄥけ璐�
         /// </summary>

--
Gitblit v1.8.0