using System;
|
using System.Collections.Generic;
|
using Shared;
|
|
namespace HDL_ON.DAL.Server
|
{
|
/// <summary>
|
/// 接口类的返回信息
|
/// </summary>
|
public class IMessageCommon
|
{
|
|
/// <summary>
|
/// 接口类的返回信息
|
/// </summary>
|
private static IMessageCommon m_Current = null;
|
/// <summary>
|
/// 接口类的返回信息
|
/// </summary>
|
public static IMessageCommon Current
|
{
|
get
|
{
|
if (m_Current == null)
|
{
|
m_Current = new IMessageCommon();
|
//初始化全部的信息
|
m_Current.InitAllMsg();
|
}
|
return m_Current;
|
}
|
}
|
|
/// <summary>
|
/// 是否在获取token
|
/// </summary>
|
public bool isGetingToken;
|
|
/// <summary>
|
/// 无视错误(访问云端时,此操作将不会弹出错误)
|
/// </summary>
|
public bool IgnoreError = false;
|
|
///// <summary>
|
///// 全部信息
|
///// </summary>
|
//private Dictionary<string, Dictionary<string, int>> dicMsg = null;
|
|
/// <summary>
|
/// 通用错误码
|
/// </summary>
|
private Dictionary<string, int> stateCodeDic = null;
|
|
|
/// <summary>
|
/// 初始化全部的信息
|
/// </summary>
|
public void InitAllMsg()
|
{
|
//dicMsg = new Dictionary<string, Dictionary<string, int>>();
|
#region 共通错误码
|
stateCodeDic = new Dictionary<string, int>();
|
//与服务器通讯失败
|
stateCodeDic["NETWORK_ERROR"] = HDL_ON.StringId.FailedRequestServer;
|
//数据异常
|
stateCodeDic["DATA_EXCEPTION"] = HDL_ON.StringId.DataExceptionPleaseTryAgain;
|
|
#region 基础服务 新错误码
|
//系统维护中~请稍后再试~
|
stateCodeDic["2"] = HDL_ON.StringId.SystemMaintenance;
|
//签名错误
|
stateCodeDic["4"] = HDL_ON.StringId.SignatureError;
|
//验证码校验失败
|
stateCodeDic["14"] = HDL_ON.StringId.VerificationCodeWrong;
|
//验证码发送频繁,请稍后再试!
|
stateCodeDic["15"] = HDL_ON.StringId.VerificationCodeSentFrequently;
|
//会话超时,请更新token
|
stateCodeDic[StateCode.TOKEN_EXPIRED] = HDL_ON.StringId.NotLogin;
|
////登录失败,账号或者密码错误
|
stateCodeDic["10008"] = HDL_ON.StringId.LoginFailed_AccountOrPasswordError;
|
//账号不存在
|
stateCodeDic[StateCode.ACCOUNT_NOT_EXIST] = HDL_ON.StringId.AccountNotExist;
|
//账号已存在
|
stateCodeDic["10012"] = HDL_ON.StringId.AccountExist;
|
////调用用户模块接口失败
|
//stateCodeDic["10213"] = HDL_ON.StringId;
|
#endregion
|
|
////return;
|
//#region 2020-09-18 新对接错误码
|
//////操作失败,请重试
|
////stateCodeDic ["10001"] = HDL_ON.StringId.uOperationFailed;
|
////请求参数错误
|
//stateCodeDic["10101"] = HDL_ON.StringId.uParameterError;
|
////无效登录Token
|
//stateCodeDic["10102"] = HDL_ON.StringId.uNoLogin;
|
////登录失败,账号或者密码错误
|
//stateCodeDic["10103"] = HDL_ON.StringId.Accountorpassworderro;
|
////没有记录
|
//stateCodeDic["10104"] = HDL_ON.StringId.NoRecord;
|
////操作权限不足
|
//stateCodeDic["10105"] = HDL_ON.StringId.uBeRestrict;
|
////不存在
|
//stateCodeDic["10106"] = HDL_ON.StringId.NO_EXISTS;
|
|
|
////-------------------用户模块-------------------
|
////账号不存在
|
//stateCodeDic["10201"] = HDL_ON.StringId.uAccountNoExists;
|
////账号已经存在
|
//stateCodeDic["10202"] = HDL_ON.StringId.RegisterSendVerCode_Exist;
|
////验证码已失效
|
//stateCodeDic["10203"] = HDL_ON.StringId.ValidatorCode_NoRecord;
|
////验证码错误
|
//stateCodeDic["10204"] = HDL_ON.StringId.VerificationCodeError;
|
|
|
////登录失败,密码错误
|
//stateCodeDic["10205"] = HDL_ON.StringId.PasswordIsError;
|
////验证码无效[用户没有通过手机[邮箱]号获取验证码]
|
//stateCodeDic["10206"] = HDL_ON.StringId.ValidatorCode_ValidCodeAndPhoneNoEqual;
|
////验证码发送频繁
|
//stateCodeDic["10207"] = HDL_ON.StringId.VERIFY_CODE_SENDED;
|
////该账号已经绑定
|
//stateCodeDic["10208"] = HDL_ON.StringId.Exist;
|
////用户名称已经存在
|
//stateCodeDic["10209"] = HDL_ON.StringId.Exist;
|
////验证码发送失败
|
//stateCodeDic["10210"] = HDL_ON.StringId.RegisterSendVerCode_SendFail;
|
|
////-------------------更新密码模块-------------------
|
////原密码和新密码相同
|
//stateCodeDic["10211"] = HDL_ON.StringId.UpdatePassword_NewPasswordAndOldPasswordEqual;
|
////旧密码不对
|
//stateCodeDic["10212"] = HDL_ON.StringId.UpdatePassword_OldPwdNoYes;
|
|
////-------------------子账号模块-------------------
|
////子账号已经存在
|
//stateCodeDic["10301"] = HDL_ON.StringId.BindSubAccount_Exist;
|
////子账号不存在
|
//stateCodeDic["10302"] = HDL_ON.StringId.uAccountNoExists;
|
////不能把自己添加为成员
|
//stateCodeDic["10303"] = HDL_ON.StringId.BindSubAccount_SameAccount;
|
////一样的远程请求
|
//stateCodeDic["10304"] = HDL_ON.StringId.uOperationFailed;
|
////账号已经存在于此住宅
|
//stateCodeDic["10305"] = HDL_ON.StringId.BindSubAccount_Exist;
|
|
////-------------------住宅模块-------------------
|
////当前住宅不属于该账号
|
//stateCodeDic["10401"] = HDL_ON.StringId.HomeIdAndTokenNoConsistent;
|
////住宅名称已存在
|
//stateCodeDic["10402"] = HDL_ON.StringId.EditZigbeeHome_Exist;
|
////住宅ID已存在
|
//stateCodeDic["10403"] = HDL_ON.StringId.HOME_ID_EXISTS;
|
////住宅不存在
|
//stateCodeDic["10404"] = HDL_ON.StringId.uZigbeeHome_NoRecord;
|
|
////-------------------住宅分享模块-------------------
|
////住宅分享不存在
|
//stateCodeDic["10405"] = HDL_ON.StringId.NO_EXISTS;
|
|
////-------------------网关模块-------------------
|
////是否强制解绑网关
|
//stateCodeDic["10501"] = HDL_ON.StringId.BindGwToHome_BindGatewaysExists;
|
////应用成功
|
//stateCodeDic["10502"] = HDL_ON.StringId.AmendTheSuccess;
|
////当前住宅下并没有绑定指定的网关
|
//stateCodeDic["10503"] = HDL_ON.StringId.ReleaseGatewayToZigbeeHome_NoBind;
|
////不支持
|
//stateCodeDic["10504"] = HDL_ON.StringId.NOT_SUPPORT;
|
////网关MAC不存在
|
//stateCodeDic["10505"] = HDL_ON.StringId.MACError;
|
|
////-------------------备份模块-------------------
|
////备注名称已经存在,请更换后重试!文件夹名称已经存在
|
//stateCodeDic["10601"] = HDL_ON.StringId.uBackupNameExists;
|
////备份文件夹不存在
|
//stateCodeDic["10602"] = HDL_ON.StringId.FolderNoExist;
|
////备份文件不存在
|
//stateCodeDic["10603"] = HDL_ON.StringId.FileNoExist;
|
|
|
////-------------------跨区-------------------
|
////该接口不存在跨区操作
|
//stateCodeDic["11001"] = HDL_ON.StringId.NOT_SUPPORT;
|
////跨区调用失败
|
//stateCodeDic["11002"] = HDL_ON.StringId.NOT_SUPPORT;
|
////枚举错误
|
//stateCodeDic["11003"] = HDL_ON.StringId.uOperationFailed;
|
|
|
#endregion
|
|
|
}
|
|
/// <summary>
|
/// 根据接口的状态码,翻译返回信息
|
/// </summary>
|
/// <param name="requestName">接口</param>
|
/// <param name="revertObj">云端返回的数据</param>
|
/// <param name="pra">请求参数</param>
|
/// <returns></returns>
|
public string GetMsgByRequestName(string statuCode)
|
{
|
if (IgnoreError == true)
|
{
|
//无视错误
|
return null;
|
}
|
|
//共通码
|
if (stateCodeDic.ContainsKey(statuCode) == true)
|
{
|
return Language.StringByID(stateCodeDic[statuCode]);
|
}
|
|
//if (dicMsg.ContainsKey(requestName) == true && dicMsg[requestName].ContainsKey(statuCode) == true)
|
//{
|
// //在册的Msg
|
// return Language.StringByID(dicMsg[requestName][statuCode]);
|
//}
|
|
return Language.StringByID(HDL_ON.StringId.FailedRequestServer) + "\n(" + statuCode + ")";
|
}
|
|
|
/// <summary>
|
/// 弹窗提示网络请求错误信息
|
/// </summary>
|
/// <param name="requestName"></param>
|
/// <param name="statuCode"></param>
|
/// <param name="isTipStyle"></param>
|
/// <param name="tipStr">补充的错误提示</param>
|
public void ShowErrorInfoAlter(string statuCode, bool isTipStyle = true, int closeTime = 2, string tipStr = "")
|
{
|
try
|
{
|
//如果是token过期则刷新token
|
if (statuCode == StateCode.TOKEN_EXPIRED)
|
{
|
StartRefreshToken();
|
}
|
else
|
{
|
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();
|
|
}
|
}
|
|
/// <summary>
|
/// 常用状态码管理
|
/// </summary>
|
public class StateCode
|
{
|
/// <summary>
|
/// 请求成功的状态码
|
/// </summary>
|
public const string SUCCESS = "0";
|
/// <summary>
|
/// 账号不存在的错误码
|
/// </summary>
|
public const string ACCOUNT_NOT_EXIST = "10010";
|
|
/// <summary>
|
/// 会话超时,请更新token
|
/// </summary>
|
public const string TOKEN_EXPIRED = "10001";
|
|
}
|
}
|