JLChen
2020-11-25 52e05a5fb6e07afbb14960fc3cbb8a8971e19eb2
HDL_ON/DAL/Server/IMessageCommon.cs
@@ -9,7 +9,7 @@
    /// </summary>
    public class IMessageCommon
    {
        /// <summary>
        /// 接口类的返回信息
        /// </summary>
@@ -30,6 +30,12 @@
                return m_Current;
            }
        }
        /// <summary>
        /// 是否在获取token
        /// </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))
                //如果是token过期则刷新token
                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";
    }
}