/// <summary> /// 生成token /// </summary> /// <param name="user"></param> /// <param name="ip"></param> /// <param name="did"></param> /// <param name="platform"></param> /// <param name="expireTime"></param> /// <param name="fromCode"></param> /// <returns></returns> private CredentialsExt MakeToken(UserDetail user, string ip, string did, string platform, DateTime?expireTime, string fromCode) { string token = string.Empty; CredentialsExt credentials = new CredentialsExt(); credentials.myPhoto = user.myPhoto; credentials.fullname = user.fullname; //生成token token = Guid.NewGuid().ToString("N"); //登录的基本信息 credentials.UserId = user.id.ToString(); credentials.UserName = user.loginname; credentials.NickName = user.name + " " + user.surname; credentials.RealName = user.name + " " + user.surname; //设备号 credentials.Did = did; //本次登录的令牌 credentials.accesstoken = token; //本次登录的用户IP credentials.UserIp = ip; //服务器IP credentials.HostIp = WebUtils.GetHostIp(); //登录的平台 credentials.Platform = platform; //本次登录的机构 credentials.OrgId = user.discriminator; credentials.OrgCode = user.discriminator; credentials.OrgName = user.discriminator; //本次登录的部门 credentials.DeptId = string.Empty; credentials.DeptCode = string.Empty; credentials.DeptName = string.Empty; credentials.FromCode = string.Empty; credentials.FromName = string.Empty; if (expireTime.HasValue && expireTime.Value > DateTime.Now) { credentials.ExpireTime = expireTime.Value; } else { credentials.ExpireTime = DateTime.Now.AddDays(1); } credentials.Enabled = true; credentials.CreateTime = DateTime.Now; credentials.LastValidTime = DateTime.Now; //插入登录凭据 _credentialsRepository.Add(credentials); return(credentials); }