From ea0b1e8e5f43c5fd0a7d479e25ede3b8cbea464a Mon Sep 17 00:00:00 2001
From: wxr <wxr@hdlchina.com.cn>
Date: 星期一, 02 十二月 2024 17:17:19 +0800
Subject: [PATCH] tcp;可视对讲;

---
 HDL_ON/DAL/Server/HttpUtil.cs |  119 +++++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 94 insertions(+), 25 deletions(-)

diff --git a/HDL_ON/DAL/Server/HttpUtil.cs b/HDL_ON/DAL/Server/HttpUtil.cs
index 6758fbc..b953eb2 100644
--- a/HDL_ON/DAL/Server/HttpUtil.cs
+++ b/HDL_ON/DAL/Server/HttpUtil.cs
@@ -12,20 +12,76 @@
 {
     public class HttpUtil
     {
+        static HttpUtil _HttpUtil;
+        public static HttpUtil Ins
+        {
+            get
+            {
+                if (_HttpUtil == null)
+                {
+                    _HttpUtil = new HttpUtil();
+                }
+                return _HttpUtil;
+            }
+        }
 
         #region **********鍏ㄥ眬甯搁噺**********
+        //public const string GlobalRequestHttpsHost = "https://nearest.hdlcontrol.com";
+        //public const string APP_KEY = "QWERREWQ";
+        //public const string SECRET_KEY = "CPBUCTRLCPBUABCD";
+
+
+        string _GlobalRequestHttpsHost;
         /// <summary>
         /// 鍥哄畾鍩熷悕,姝e紡鐜
         /// 鍏叡鍩熷悕灏辫繎瑙f瀽
         /// </summary>
-        public const string GlobalRequestHttpsHost = "https://nearest.hdlcontrol.com";
-        //public const string GlobalRequestHttpsHost = "http://59.41.255.150:7777";
-        //const string APP_KEY = "COSDFPIN";
-        //const string SECRET_KEY = "COSDFPJDCOSDFPJT";
-        const string APP_KEY = "QWERREWQ";
-        const string SECRET_KEY = "CPBUCTRLCPBUABCD";
+        public string GlobalRequestHttpsHost
+        {
+            get
+            {
+                _GlobalRequestHttpsHost = "https://nearest.hdlcontrol.com";
+                if (OnAppConfig.Instance.HostType == RequestHostType.ONLINE)
+                    _GlobalRequestHttpsHost = "https://nearest.hdlcontrol.com";
+                else if (OnAppConfig.Instance.HostType == RequestHostType.TEST)
+                    _GlobalRequestHttpsHost = "https://test-gz.hdlcontrol.com";
+                else if (OnAppConfig.Instance.HostType == RequestHostType.DEV)
+                    _GlobalRequestHttpsHost = "http://59.41.255.150:7777";
+                return _GlobalRequestHttpsHost;
+            }
+        }
+        string app_key;
+        public string APP_KEY
+        {
+            get
+            {
+                app_key = "QWERREWQ";
+                if (OnAppConfig.Instance.HostType == RequestHostType.ONLINE)
+                    app_key = "QWERREWQ";
+                else if (OnAppConfig.Instance.HostType == RequestHostType.TEST)
+                    app_key = "HDL-HOME-APP-TEST";
+                else if (OnAppConfig.Instance.HostType == RequestHostType.DEV)
+                    app_key = "CPEVRLRT";
+                return app_key;
+            }
+        }
+        string _SECRET_KEY;
+        public string SECRET_KEY
+        {
+            get
+            {
+                _SECRET_KEY = "CPBUCTRLCPBUABCD";
+                if (OnAppConfig.Instance.HostType == RequestHostType.ONLINE)
+                    _SECRET_KEY = "CPBUCTRLCPBUABCD";
+                else if (OnAppConfig.Instance.HostType == RequestHostType.TEST)
+                    _SECRET_KEY = "WeJ8TY88vbakCcnvH8G1tDUqzLWY8yss";
+                else if (OnAppConfig.Instance.HostType == RequestHostType.DEV)
+                    _SECRET_KEY = "CPEVRLSJCPEVRLSZ";
+                return _SECRET_KEY;
+            }
+        }
 
-        //public const string GlobalRequestHttpsHost = "https://test-gz.hdlcontrol.com";//mmmm
+
         /// <summary>
         /// RegionMark
         /// </summary>
@@ -46,7 +102,6 @@
         #endregion
 
         #region **********缃戠粶璇锋眰灏佽**********
-
         /// <summary>
         ///  Get  璇锋眰鏈嶅姟鍣ㄦ柟娉�
         /// </summary>
@@ -156,25 +211,23 @@
 
             if(MainPage.NoLoginMode)
             {
-                return new ResponsePackNew() { Code = "0" };
+                return new ResponsePackNew() { Code = "0" ,Data = "" };
             }
             #region HttpWebRequest
             try
             {
-
                 if (string.IsNullOrEmpty(urlHead))
                 {
                     urlHead = OnAppConfig.Instance.RequestHttpsHost;
                 }
                 string requestFullUrl = urlHead + apiPath;
 
-
                 RestClient client = new RestClient(requestFullUrl);
 
                 RestRequest request = new RestRequest(method);
                 request.Timeout = mTimeout * 1000;
                 request.AddHeader("content-type", "application/json");
-                request.AddHeader("language", Language.CurrentLanguage == "Chinese" ? "zh" : "en");//澧炲姞璇█鏍囪瘑
+                request.AddHeader("language", Language.CurrentLanguage == "Chinese" ? "cn" : "en");//澧炲姞璇█鏍囪瘑 wxr 2023-03-22 17:03:34
 
                 if (string.IsNullOrEmpty(replaceToken))
                 {
@@ -208,8 +261,13 @@
                         request.AddUrlSegment(data.Key, data.Value.ToString());
                     }
                 }
-
                 IRestResponse response = client.Execute(request);
+                HDL_ON.Utlis.WriteLine("鍙戦��", requestFullUrl, response.Request.Body?.Value.ToString());
+                if(apiPath == NewAPI.API_POST_Login)
+                {
+                    var ddd = Newtonsoft.Json.JsonConvert.SerializeObject(response);
+                    //Console.WriteLine(ddd);
+                }
                 if (response.StatusCode == HttpStatusCode.OK)
                 {
                     try
@@ -227,7 +285,7 @@
                             revertObj.Data = "";
                         }
                         //*****涓�浜涘垽绌哄鐞�*****************
-
+                        HDL_ON.Utlis.WriteLine("鎺ユ敹", requestFullUrl, response.Content);
                         return revertObj;
                     }
                     catch (Exception ex)
@@ -238,7 +296,19 @@
                 }
                 else
                 {
-                    HDL_ON.Utlis.WriteLine(response.Content);
+                    HDL_ON.Utlis.WriteLine($"鎺ュ彛寮傚父:{requestFullUrl} \r\n"+response.Content);
+                    if(response.Content!= null)
+                    {
+                        try
+                        {
+                            var pack = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePackNew>(response.Content);
+                            if (pack != null)
+                            {
+                                return pack;
+                            }
+                        }
+                        catch { }
+                    }
                     return new ResponsePackNew() { Code = StateCode.NETWORK_ERROR };
                 }
 
@@ -290,7 +360,7 @@
         /// 鍒锋柊  Token
         /// </summary>
         /// <returns></returns>
-        static bool RefreshToken()
+        static bool RefreshToken(bool canRefresh = true)
         {
             try
             {
@@ -307,12 +377,12 @@
                     UserInfo.Current.RefreshToken = revertData.refreshToken;
                     UserInfo.Current.LastTime = DateTime.Now;
                     UserInfo.Current.SaveUserInfo();
-                    return true;
 #if __IOS__
-                    //var sdm = new SiriKit.SceneDateManager();
-                    //sdm.AccessToken = UserInfo.Current.LoginTokenString;
-                    //sdm.RefreshToken = UserInfo.Current.RefreshToken;
+                    var sdm = new SiriKit.SceneDateManager();
+                    sdm.AccessToken = UserInfo.Current.LoginTokenString;
+                    sdm.RefreshToken = UserInfo.Current.RefreshToken;
 #endif
+                    return true;
                 }
                 else if (revertObj.Code == StateCode.PasswrodError)
                 {
@@ -351,7 +421,6 @@
                 RestRequest request = new RestRequest(Method.POST);
                 request.Timeout = mTimeout * 1000;
                 request.AddHeader("content-type", "application/json");
-                request.AddHeader("language", Language.CurrentLanguage == "Chinese" ? "cn" : "en");//澧炲姞璇█鏍囪瘑
 
                 if (string.IsNullOrEmpty(replaceToken))
                 {
@@ -527,10 +596,10 @@
 
         }
 
-        #endregion
+#endregion
 
         #region **********绛惧悕鏍¢獙**********
-        
+
         /// <summary>
         /// 鑾峰彇褰撳墠鏃堕棿鎴冲��
         /// </summary>
@@ -590,7 +659,7 @@
                 //2. 璁$畻sign
                 if (paramDictionary != null)
                 {
-                    paramDictionary.Add("appKey", APP_KEY);
+                    paramDictionary.Add("appKey", Ins.APP_KEY);
                     paramDictionary.Add("timestamp", GetTimestamp());
                     //2.1 瀛楀吀鍗囧簭
                     paramDictionary = paramDictionary.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value);
@@ -621,7 +690,7 @@
                     }
 
                     //2.3 鎷兼帴SECRET_KEY
-                    str = str.Substring(0, str.Length - 1) + SECRET_KEY;
+                    str = str.Substring(0, str.Length - 1) + Ins.SECRET_KEY;
                     //2.4 MD5杞崲+杞皬鍐�
                     var signstr = SignMD5Encrypt(str);
                     paramDictionary.Add("sign", signstr);

--
Gitblit v1.8.0