From 52e05a5fb6e07afbb14960fc3cbb8a8971e19eb2 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期三, 25 十一月 2020 20:08:56 +0800
Subject: [PATCH] 2020-11-25 1.TOKEN过期刷新处理

---
 HDL_ON/DAL/Server/IMessageCommon.cs |   93 ++++++++++++++++++++++++++++++++++++----------
 1 files changed, 72 insertions(+), 21 deletions(-)

diff --git a/HDL_ON/DAL/Server/IMessageCommon.cs b/HDL_ON/DAL/Server/IMessageCommon.cs
index cc5f79c..eae567b 100644
--- a/HDL_ON/DAL/Server/IMessageCommon.cs
+++ b/HDL_ON/DAL/Server/IMessageCommon.cs
@@ -9,7 +9,7 @@
     /// </summary>
     public class IMessageCommon
     {
-       
+
         /// <summary>
         /// 鎺ュ彛绫荤殑杩斿洖淇℃伅
         /// </summary>
@@ -30,6 +30,12 @@
                 return m_Current;
             }
         }
+
+        /// <summary>
+        /// 鏄惁鍦ㄨ幏鍙杢oken
+        /// </summary>
+        public bool isGetingToken;
+
         /// <summary>
         /// 鏃犺閿欒(璁块棶浜戠鏃讹紝姝ゆ搷浣滃皢涓嶄細寮瑰嚭閿欒)
         /// </summary>
@@ -69,7 +75,7 @@
             //楠岃瘉鐮佸彂閫侀绻侊紝璇风◢鍚庡啀璇曪紒
             stateCodeDic["15"] = HDL_ON.StringId.VerificationCodeSentFrequently;
             //浼氳瘽瓒呮椂锛岃鏇存柊token
-            stateCodeDic["10001"] = HDL_ON.StringId.NotLogin;
+            stateCodeDic[StateCode.TOKEN_EXPIRED] = HDL_ON.StringId.NotLogin;
             ////鐧诲綍澶辫触锛岃处鍙锋垨鑰呭瘑鐮侀敊璇�
             stateCodeDic["10008"] = HDL_ON.StringId.LoginFailed_AccountOrPasswordError;
             //璐﹀彿涓嶅瓨鍦�
@@ -231,32 +237,72 @@
         {
             try
             {
-                string mes = GetMsgByRequestName(statuCode);
-                if (mes == null) return;
-                if (!string.IsNullOrEmpty(tipStr))
+                //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken
+                if (statuCode == StateCode.TOKEN_EXPIRED)
                 {
-                    mes = tipStr + "\n" + mes;
-                }
-                if (isTipStyle)
-                {
-                    Application.RunOnMainThread(() => {
-                        var tip = new Tip()
-                        {
-                            Text = mes,
-                            CloseTime = closeTime,
-                            Direction = AMPopTipDirection.None
-                        };
-                        tip.Show(MainPage.BaseView);
-                    });
+                    StartRefreshToken();
                 }
                 else
                 {
-                    Application.RunOnMainThread(() => {
-                        new Alert("", mes, Language.StringByID(HDL_ON.StringId.Close)).Show();
-                    });
+                    string mes = GetMsgByRequestName(statuCode);
+                    if (mes == null) return;
+                    if (!string.IsNullOrEmpty(tipStr))
+                    {
+                        mes = tipStr + "\n" + mes;
+                    }
+                    if (isTipStyle)
+                    {
+                        Application.RunOnMainThread(() =>
+                        {
+                            var tip = new Tip()
+                            {
+                                Text = mes,
+                                CloseTime = closeTime,
+                                Direction = AMPopTipDirection.None
+                            };
+                            tip.Show(MainPage.BaseView);
+                        });
+                    }
+                    else
+                    {
+                        Application.RunOnMainThread(() =>
+                        {
+                            new Alert("", mes, Language.StringByID(HDL_ON.StringId.Close)).Show();
+                        });
+                    }
                 }
             }
             catch { }
+        }
+
+        /// <summary>
+        /// StartRefreshToken
+        /// </summary>
+        void StartRefreshToken()
+        {
+            if (isGetingToken) return;
+
+            new System.Threading.Thread(() =>
+            {
+                isGetingToken = true;
+
+                try
+                {
+                    var success = new HttpServerRequest().RefreshToken();
+                    if (success) {
+                        Utlis.WriteLine("RefreshToken success");
+                    }
+                }
+                catch
+                {
+                }
+                finally
+                {
+                    isGetingToken = false;
+                }
+            })
+            { IsBackground = true }.Start();
+
         }
     }
 
@@ -274,5 +320,10 @@
         /// </summary>
         public const string ACCOUNT_NOT_EXIST = "10010";
 
+        /// <summary>
+        /// 浼氳瘽瓒呮椂锛岃鏇存柊token
+        /// </summary>
+        public const string TOKEN_EXPIRED = "10001";
+
     }
 }

--
Gitblit v1.8.0