/// <summary> /// 获取加密的token字符串 /// </summary> /// <returns></returns> private string GetEncrypTokenString(string token) { string tokenStr = ""; //判断是否配置了加密token L.J.X 2016.05.26 if (ConfigHelper.GetConfigValueByKey("Token_IsEncryptToken").ToInt() == 1) { tokenStr = NH.Service.Api.TokenService.EncrypToken(token); tokenStr = tokenStr.Replace("+", "["); } else { tokenStr = DataConvert.ConvertStringToBase64(token); } return(tokenStr); }
/// <summary> /// 输出Token实体 /// </summary> /// <param name="userid">用户ID</param> /// <param name="platform">平台(详见 NH.Entity.EnumLibrary.Regplatform 枚举)</param> /// <returns></returns> public NH.Entity.Model.Token GetTokenEntity(int userid, NH.Entity.EnumLibrary.Regplatform platform) { NH.Entity.Model.Token token = new NH.Entity.Model.Token(); if (userid > 0) { //密钥(32位数字+字母组成的字符串) string AppKey = ""; if (ConfigHelper.GetConfigValueByKey("Token_IsEncryptToken").ToInt() != 1) { AppKey = ConfigHelper.GetConfigValueByKey("AppKey"); } //从当前时间开始指定天数后(截止天数) int AppTokenValidDays = TypeConverter.StrToInt(ConfigHelper.GetConfigValueByKey("AppTokenValidDays"), 7); token.UserID = userid; token.Timestamp = DataConvert.ConvertDateTimeToInt(AppTokenValidDays); //if (platform == NH.Entity.EnumLibrary.Regplatform.MiniCourse) //{ // token.Authenticate = NH.Service.V2.ExpertService.GetAuthenticateStatus(userid); //} token.Platform = platform; //把用户ID转换成Base64字符 string useridBase64 = DataConvert.ConvertStringToBase64(token.UserID.ToString()); string[] arrayTemp = new string[] { useridBase64, token.Timestamp.ToString(), AppKey, ((int)token.Platform).ToString() }; string tokenstr = string.Join("-", arrayTemp); token.TokenStr = GetEncrypTokenString(tokenstr); //token.UserID = userid; //token.Timestamp = DataConvert.ConvertDateTimeToInt(); //时间戳 //token.Noncestr = GetNonceStr(); //16位随机字符串(数字+字母) //token.Signature = GetSignature(token.TokenStr, token.Timestamp.ToString(), token.Noncestr); //签名 } return(token); }