/// <summary> /// 更新token信息 /// </summary> /// <param name="customerName">用户账号</param> /// <param name="customerId">用户编号</param> public void UpdateTokenUser(string customerName, long customerId) { string token = RedisEntity.HashGet(LoginCustomerNameListKey, customerName); if (!string.IsNullOrEmpty(token)) { RedisEntity.HashSet(LoginCustomerListKey, token, customerId.ToString()); } }
/// <summary> /// 获取新的用户token /// </summary> /// <param name="val">用户信息</param> /// <returns></returns> public TokenOpearteResult GetNewToken(CustomerInfo val) { string customerName = val.CustomerName; var oldtoken = RedisEntity.HashGet(LoginCustomerNameListKey, customerName); //被挤掉的用户token if (!string.IsNullOrEmpty(oldtoken)) { var customerId = RedisEntity.HashGet(LoginCustomerListKey, oldtoken); CustomerRedisDal cusRedisDal = new CustomerRedisDal(); CustomerDetail oldLoginInfo = cusRedisDal.GetCustomerDetail(long.Parse(customerId)); //不是同一台设备 if (oldLoginInfo != null) { //添加到被挤掉的用户 string crowKey = CrowdedTokenKey + ":" + oldtoken; RedisEntity.ItemSet <string>(crowKey, customerName); RedisEntity.ItemSetExpire(crowKey, DateTime.Now.AddDays(1)); } RedisEntity.HashRemove(LoginCustomerNameListKey, customerName); RedisEntity.HashRemove(LoginCustomerListKey, oldtoken); //记录删除的token列表 LogHelper.Debug("移除旧的token:" + oldtoken + "|" + customerName); } string token = Guid.NewGuid().ToString(); RedisEntity.HashSet(LoginCustomerListKey, token, val.CustomerId.ToString()); RedisEntity.HashSet(LoginCustomerNameListKey, customerName, token); TokenOpearteResult result = new TokenOpearteResult { isok = true, token = token }; return(result); }
/// <summary> /// 获取新的用户token /// </summary> /// <param name="val">用户信息</param> /// <returns></returns> public TokenOpearteResult GetWXToken(WxLoginInfo val) { TimeSpan Expire = TimeSpan.FromDays(3); //string customerName = val.CustomerName; //var oldtoken = RedisEntity.HashGet(LoginCustomerNameListKey, customerName); ////被挤掉的用户token //if (!string.IsNullOrEmpty(oldtoken)) //{ // var customerId = RedisEntity.HashGet(LoginCustomerListKey, oldtoken); // CustomerRedisDal cusRedisDal = new CustomerRedisDal(); // CustomerDetail oldLoginInfo = cusRedisDal.GetCustomerDetail(long.Parse(customerId)); // //不是同一台设备 // if (oldLoginInfo != null) // { // //添加到被挤掉的用户 // string crowKey = CrowdedTokenKey + ":" + oldtoken; // RedisEntity.ItemSet<string>(crowKey, customerName); // RedisEntity.ItemSetExpire(crowKey, DateTime.Now.AddDays(1)); // } // RedisEntity.HashRemove(LoginCustomerNameListKey, customerName); // RedisEntity.HashRemove(LoginCustomerListKey, oldtoken); // //记录删除的token列表 // LogHelper.Debug("移除旧的token:" + oldtoken + "|" + customerName); //} string token = Guid.NewGuid().ToString(); RedisEntity.HashSet(WXLoginListKey, token, val.openid + ";" + val.session_key); RedisEntity.HashSetExpire(token, Expire); TokenOpearteResult result = new TokenOpearteResult { isok = true, token = token }; return(result); }