/// <summary> /// 通过 openId 获取用户信息 /// </summary> /// <param name="openId">唯一键</param> /// <returns>用户实体</returns> public static BaseUserEntity GetObjectByOpenIdByCache(string openId) { BaseUserEntity result = null; string key = "OpenId"; string userId = string.Empty; if (!string.IsNullOrWhiteSpace(openId)) { key = key + openId; # if Redis // 2015-12-14 吉日嘎拉 这里可以支持不走缓存的方式 using (var redisClient = PooledRedisHelper.GetReadOnlyClient()) { userId = redisClient.Get <string>(key); if (!string.IsNullOrWhiteSpace(userId)) { result = GetObjectByCache(redisClient, userId); } if (result == null) { // 若没获取到用户?到数据库里查一次 BaseUserLogOnManager userLogOnManager = new BaseUserLogOnManager(); userId = userLogOnManager.GetIdByOpenId(openId); if (!string.IsNullOrWhiteSpace(userId)) { result = GetObjectByCache(redisClient, userId); } } } #endif }
public static BaseUserEntity GetObjectByOpenIdByCache(string openId) { BaseUserEntity result = null; string userId = string.Empty; if (!string.IsNullOrWhiteSpace(openId)) { if (result == null) { // 若没获取到用户?到数据库里查一次 BaseUserLogOnManager userLogOnManager = new BaseUserLogOnManager(); userId = userLogOnManager.GetIdByOpenId(openId); if (!string.IsNullOrWhiteSpace(userId)) { result = GetObjectByCache(userId); } } } return(result); }