/// <summary> /// 获取所有区县 /// </summary> /// <param name="countryId"></param> /// <returns></returns> private IList <AreaModel> GetAllArea(int language) { try { return(RedisCacheHelper.AutoCache(ConstClass.RedisKey4MPrefix, "Area2_" + language, () => dal.GetAllArea(language), 1440));//1440min=1天 } catch (Exception ex) { LogHelper.Error(ex); } return(null); }
/// <summary> /// 获取所有省份 /// </summary> /// <param name="countryId"></param> /// <returns></returns> public IList <ProvinceModel> GetAllProvince(string country, int language) { try { return(RedisCacheHelper.AutoCache(ConstClass.RedisKey4MPrefix, "Province_" + language, () => dal.GetAllProvince(country, language), 1440));//1440min=1天 } catch (Exception ex) { LogHelper.Error(ex); } return(null); }
public IList <BerserkProductEntity> GetBerserkDay(int top, int language) { try { var berserkProduct = RedisCacheHelper.AutoCache(ConstClass.RedisKey4MPrefix, ConstClass.Key_SupermarketBerserkProduct, () => { return(SupermarketDal.GetBerserkProduct(top, language)); }, minutes); return(berserkProduct); } catch (Exception ex) { LogHelper.Error(ex); } return(new List <BerserkProductEntity>()); }
/// <summary> /// 获取缓存分类 /// </summary> /// <param name="type"></param> /// <param name="top"></param> /// <returns></returns> private IList <CategoryEntity> GetCategoryModules(int language) { try { var modules = RedisCacheHelper.AutoCache(ConstClass.RedisKey4MPrefix, ConstClass.RedisKeyCategoryModules, () => { var data = GetCategoryAll(language); return(data); }, 360); return(modules); } catch (Exception ex) { LogHelper.Error(ex); return(new List <CategoryEntity>()); } }
/// <summary> /// 获取首页新品区数据 /// </summary> /// <param name="type"></param> /// <param name="top"></param> /// <returns></returns> public IList <IndexModulesEntity> GetIndexNewProduct(int top, int language, int SalesTerritory) { try { var modules = RedisCacheHelper.AutoCache(ConstClass.RedisKey4MPrefix, ConstClass.RedisKeyIndexNewProduct, () => { return(IndexDal.GetIndexNewProduct(top, language, SalesTerritory)); }, 60); return(modules); } catch (Exception ex) { LogHelper.Error(ex); } return(new List <IndexModulesEntity>()); }
public BrandEntity GetBrandInfoFromAutoCache(int brandId, int language, int deliveryRegion, decimal exchangeRate, int userId, int SourceType) { try { var modules = RedisCacheHelper.AutoCache(ConstClass.RedisKey4MPrefix, ConstClass.RedisKeyBrandEntity + SourceType, () => { var data = GetBrandEntity(brandId, language, deliveryRegion, exchangeRate, userId); return(data); }, 1440);//缓存24小时 return(modules); } catch (Exception ex) { LogHelper.Error(ex); var modules = GetBrandEntity(brandId, language, deliveryRegion, exchangeRate, userId); return(modules); } }
/// <summary> /// 从缓存中获取数据 /// </summary> /// <param name="type"></param> /// <param name="top"></param> /// <returns></returns> public IList <IndexModulesEntity> GetIndexModulesFromCache(IndexModuleType type, int top) { try { var modules = RedisCacheHelper.AutoCache(ConstClass.RedisKey4MPrefix, ConstClass.RedisKeyIndexModules, () => { var data = GetAllIndexModules(); return(data); }, 60); return(GetIndexModules(type, top, modules)); } catch (Exception ex) { LogHelper.Error(ex); var modules = GetAllIndexModules(); return(GetIndexModules(type, top, modules)); } }
public IList <IndexModulesProductEntity> GetAllCMSHotProductsFromCache(int language, int salesTerritory) { try { var products = RedisCacheHelper.AutoCache(ConstClass.RedisKey4MPrefix, ConstClass.RedisKeyIndexCMSHotProducts, () => { var data = IndexDal.GetAllCMSHotProducts(language, salesTerritory); return(data); }, 60); return(products); } catch (Exception ex) { LogHelper.Error(ex.Message); return(new List <IndexModulesProductEntity>()); } }
/// <summary> /// 从缓存中获得首页轮播焦点图 /// </summary> /// <param name="type"></param> /// <param name="top"></param> /// <returns></returns> public IList <BannerImagesEntity> GetIndexBannerImagesFromCache() { try { var modules = RedisCacheHelper.AutoCache(ConstClass.RedisKey4MPrefix, ConstClass.RedisKeyIndexBannerImagesModules, () => { var data = GetIndexBannerImages(); return(data); }, 60); return(modules); } catch (Exception ex) { LogHelper.Error(ex); var modules = GetIndexBannerImages(); return(modules); } }
/// <summary> /// 健康绿氧超市页面单banner图 /// </summary> /// <param name="channelId"></param> /// <returns></returns> public SingleBannerImagesEntity GetIndexSingleBannerImagesFromCache(int channelId) { try { var modules = RedisCacheHelper.AutoCache(ConstClass.RedisKey4MPrefix, ConstClass.Key_SupermarketSingleBannerImage, () => { var data = GetIndexSingleBannerImage(channelId); return(data); }, minutes); return(modules); } catch (Exception ex) { LogHelper.Error(ex); var modules = GetIndexSingleBannerImage(channelId); return(modules); } }
/// <summary> /// 获取CMS设置的热词 /// </summary> /// <returns>设置的热门词汇列表</returns> public List <CMSHotKeyword> GetHotKeywordsFromCache(int top = 0) { try { var hotwords = RedisCacheHelper.AutoCache(ConstClass.RedisKey4MPrefix, ConstClass.RedisKeyHotWords, () => { return(searchDal.GetHotKeywords()); }, 1); //不传top值默认获取全部数据 return(top == 0?hotwords:hotwords.Take(top).ToList()); } catch (Exception ex) { LogHelper.Error(ex); return(new List <CMSHotKeyword>()); } }
/// <summary> /// 检查登陆状态 /// </summary> /// <param name="userModel"></param> /// <returns></returns> private static bool CheckSessionBase(out LoginUserModel userModel) { userModel = null; if (System.Web.HttpContext.Current.Session != null && System.Web.HttpContext.Current.Session[ConstClass.SessionKeyMLoginUser] != null) { int userId = System.Web.HttpContext.Current.Session[ConstClass.SessionKeyMLoginUser].As(0); try { if (userId <= 0) { System.Web.HttpContext.Current.Session[ConstClass.SessionKeyMLoginUser] = null; System.Web.HttpContext.Current.Session.Clear(); return(false); } var tempuser = RedisCacheHelper.AutoCache <LoginUserModel>("", GetLoginUserRedisKey(userId), () => accountBll.GetUserById(userId).AsLoginUserModel(), ConfigHelper.SessionExpireMinutes); if (tempuser == null || tempuser.Status != 1) { //清错误缓存 RedisCacheHelper.Remove(GetLoginUserRedisKey(userId)); System.Web.HttpContext.Current.Session[ConstClass.SessionKeyMLoginUser] = null; System.Web.HttpContext.Current.Session.Clear(); return(false); } userModel = tempuser; return(true); } catch (Exception ex) { LogHelper.Error(ex); RedisCacheHelper.Remove(GetLoginUserRedisKey(userId)); System.Web.HttpContext.Current.Session[ConstClass.SessionKeyMLoginUser] = null; return(false); } } return(false); }
/// <summary> /// 获取汇率信息,缓存一天时间 /// </summary> /// <param name="pattern"></param> /// <returns></returns> public static decimal GetExchangeRates(int pattern) { return(RedisCacheHelper.AutoCache(ConstClass.RedisKey4MPrefix, ConstClass.RedisKey4ExchangeRates, () => DAL.GetExchangeRateByPattern(pattern), ConstClass.RedisCacheMinutesOneDay)); }
/// <summary> /// 获取jsapi_ticket /// jsapi_ticket是公众号用于调用微信JS接口的临时票据。 /// 正常情况下,jsapi_ticket的有效期为7200秒,通过access_token来获取。 /// 由于获取jsapi_ticket的api调用次数非常有限,频繁刷新jsapi_ticket会导致api调用受限,影响自身业务,开发者必须在自己的服务全局缓存jsapi_ticket 。 /// </summary> /// <param name="access_token">BasicAPI获取的access_token,也可以通过TokenHelper获取</param> /// <returns></returns> public AccessTokenModel GetAccessToken() { /// 第三方用户唯一凭证和第三方用户唯一凭证密钥 string appid = System.Web.Configuration.WebConfigurationManager.AppSettings["appid"].ToString(); string secret = System.Web.Configuration.WebConfigurationManager.AppSettings["secret"].ToString();; /// 请求URL var url = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", appid, secret); var client = new HttpClient(); /// 声明变量 string access_token_str = ""; int expires_in_value = 7200; int type = 0; string content = ""; LogHelper.Info("------------TeamDetail-----执行autocach_token开始"); /// 缓存 var modules = RedisCacheHelper.AutoCache(ConstClass.RedisKey4MPrefix, "Key_AccessToken", () => { LogHelper.Info("------------TeamDetail-----进入autocach_token开始"); LogHelper.Info("------------TeamDetail-----获取token开始"); /// 获取access_token var responseResult = client.GetAsync(url).Result; LogHelper.Info("------------TeamDetail-----获取token结束"); if (!responseResult.IsSuccessStatusCode) { return(string.Empty); } var result = responseResult.Content.ReadAsStringAsync().Result; var parseResult = JObject.Parse(result.ToString()); /// 测试用固定值 //string json = "{\"access_token\":\"C9-moFZa8Vg4izrX7Ty7SC-cDasK88bxfSTV2DyzD4XsF-z2jmAQB4lUwkgQx5CD0rusKuHWSsd7aihDPpXECzlBaRADp_5eff2vWuzkYQdNLTY1wGfwLDQZiryIeFbjSLNeAGAIBD\",\"expires_in\":7200}"; //var parseResult = JObject.Parse(json); var errcode = parseResult["errcode"]; LogHelper.Info("------------TeamDetail-----token-errorcode:" + errcode); if (errcode == null) { type = 1; var access_token = parseResult["access_token"]; LogHelper.Info("------------TeamDetail-----access_token:" + access_token); if (access_token != null) { access_token_str = access_token.ToString(); } var expires_in = parseResult["expires_in"]; if (expires_in != null) { LogHelper.Info("------------TeamDetail-----token-expires_in:" + expires_in); expires_in_value = Convert.ToInt32(expires_in); LogHelper.Info("------------TeamDetail-----token-expires_in_ToInt32:" + expires_in_value); } } else { type = 2; content = parseResult["errcode"].ToString(); access_token_str = ""; } var data = access_token_str; LogHelper.Info("------------TeamDetail-----autocach-token最后返回的data:" + data); LogHelper.Info("------------TeamDetail-----进入autocach_token结束"); return(data); }, 7200); LogHelper.Info("------------TeamDetail-----执行autocach_token结束"); LogHelper.Info("------------TeamDetail-----:token缓存modules" + modules); AccessTokenModel accessTokenModel = new AccessTokenModel(); if (modules == null || modules.Equals("")) { accessTokenModel.type = type; accessTokenModel.content = content; accessTokenModel.access_token = ""; } else { accessTokenModel.type = 1; accessTokenModel.content = ""; accessTokenModel.access_token = modules.ToString(); } return(accessTokenModel); }
/// <summary> /// 获取jsapi_ticket /// jsapi_ticket是公众号用于调用微信JS接口的临时票据。 /// 正常情况下,jsapi_ticket的有效期为7200秒,通过access_token来获取。 /// 由于获取jsapi_ticket的api调用次数非常有限,频繁刷新jsapi_ticket会导致api调用受限,影响自身业务,开发者必须在自己的服务全局缓存jsapi_ticket 。 /// </summary> /// <param name="access_token">BasicAPI获取的access_token,也可以通过TokenHelper获取</param> /// <returns></returns> public AccessTokenModel GetAccessToken() { /// 第三方用户唯一凭证和第三方用户唯一凭证密钥 string appid = System.Web.Configuration.WebConfigurationManager.AppSettings["appid"].ToString(); string secret = System.Web.Configuration.WebConfigurationManager.AppSettings["secret"].ToString();; /// 请求URL var url = string.Format(ShareUtils.WechatTokenRequestUrl, appid, secret); var client = new HttpClient(); /// 声明变量 string access_token_str = ""; int type = 0; string content = ""; /// 缓存 var modules = RedisCacheHelper.AutoCache(ConstClass.RedisKey4MPrefix, "Key_AccessToken", () => { /// 获取access_token var responseResult = client.GetAsync(url).Result; if (!responseResult.IsSuccessStatusCode) { return(string.Empty); } var result = responseResult.Content.ReadAsStringAsync().Result; var parseResult = JObject.Parse(result.ToString()); /// 测试用固定值 //string json = "{\"access_token\":\"C9-moFZa8Vg4izrX7Ty7SC-cDasK88bxfSTV2DyzD4XsF-z2jmAQB4lUwkgQx5CD0rusKuHWSsd7aihDPpXECzlBaRADp_5eff2vWuzkYQdNLTY1wGfwLDQZiryIeFbjSLNeAGAIBD\",\"expires_in\":7200}"; //var parseResult = JObject.Parse(json); var errcode = parseResult["errcode"]; //LogHelper.Info("------------Shared-----token-errorcode:" + errcode); if (errcode == null) { type = (int)ShareUtils.JsonType.typeSucc; var access_token = parseResult["access_token"]; //LogHelper.Info("------------Shared-----access_token:" + access_token); if (access_token != null) { access_token_str = access_token.ToString(); } var expires_in = parseResult["expires_in"]; /*if (expires_in != null) * { * LogHelper.Info("------------Shared-----token-expires_in:" + expires_in); * }*/ } else { type = (int)ShareUtils.JsonType.typeFailed; content = parseResult["errcode"].ToString(); access_token_str = ""; } var data = access_token_str; //LogHelper.Info("------------Shared-----autocach-token最后返回的data:" + data); return(data); }, 120); //LogHelper.Info("------------Shared-----:token缓存modules" + modules); AccessTokenModel accessTokenModel = new AccessTokenModel(); if (modules == null || modules.Equals("")) { accessTokenModel.type = type; accessTokenModel.content = content; accessTokenModel.access_token = ""; } else { accessTokenModel.type = (int)ShareUtils.JsonType.typeSucc; accessTokenModel.content = ""; accessTokenModel.access_token = modules.ToString(); } return(accessTokenModel); }
/// <summary> /// 获取jsapi_ticket /// jsapi_ticket是公众号用于调用微信JS接口的临时票据。 /// 正常情况下,jsapi_ticket的有效期为7200秒,通过access_token来获取。 /// 由于获取jsapi_ticket的api调用次数非常有限,频繁刷新jsapi_ticket会导致api调用受限,影响自身业务,开发者必须在自己的服务全局缓存jsapi_ticket 。 /// </summary> /// <param name="access_token">BasicAPI获取的access_token,也可以通过TokenHelper获取</param> /// <returns></returns> public JsapiTicketModel GetTickect(string access_token) { /// 请求URL var url = string.Format(ShareUtils.WechatTicketRequestUrl, access_token); var client = new HttpClient(); /// 声明变量 string ticket_str = ""; int type = 0; string content = ""; /// 缓存 var modules = RedisCacheHelper.AutoCache(ConstClass.RedisKey4MPrefix, "Key_Ticket", () => { /// 获取ticket var responseResult = client.GetAsync(url).Result; if (!responseResult.IsSuccessStatusCode) { return(string.Empty); } var result = responseResult.Content.ReadAsStringAsync().Result; var parseResult = JObject.Parse(result.ToString()); //var json = "{\"errcode\":0,\"errmsg\":\"ok\",\"ticket\":\"sM4AOVdWfPE4DxkXGEs8VBnCOGWyCh0yozn7VHLbWf0wR7SqMRVe-h4niB2YDaeVuDMBPYzyNoVJRY4ZZOab8Q\",\"expires_in\":7200}"; //var parseResult = JObject.Parse(json); var errcode = parseResult["errcode"]; //LogHelper.Info("------------Shared-----ticket-errorcode:" + errcode); var errmsg = parseResult["errmsg"]; var ticket = parseResult["ticket"]; //LogHelper.Info("------------Shared-----ticket:" + ticket); var expires_in = parseResult["expires_in"]; //LogHelper.Info("------------Shared-----ticket-expires_in:" + expires_in); if (errcode != null && errmsg != null) { if (Convert.ToInt32(errcode) == 0 && errmsg.ToString().Equals("ok")) { type = (int)ShareUtils.JsonType.typeSucc; if (ticket != null) { ticket_str = ticket.ToString(); } } else { type = (int)ShareUtils.JsonType.typeFailed; content = parseResult["errmsg"].ToString(); ticket_str = ""; } } var data = ticket_str; //LogHelper.Info("------------Shared-----ticket_str:" + ticket_str); return(data); }, 120); //LogHelper.Info("------------Shared-----:ticket缓存modules" + modules); JsapiTicketModel jsapiTicketModel = new JsapiTicketModel(); if (modules == null || modules.Equals("")) { jsapiTicketModel.type = type; jsapiTicketModel.content = content; jsapiTicketModel.ticket = ""; } else { jsapiTicketModel.type = (int)ShareUtils.JsonType.typeSucc; jsapiTicketModel.content = ""; jsapiTicketModel.ticket = modules.ToString(); } return(jsapiTicketModel); }
/// <summary> /// 获取jsapi_ticket /// jsapi_ticket是公众号用于调用微信JS接口的临时票据。 /// 正常情况下,jsapi_ticket的有效期为7200秒,通过access_token来获取。 /// 由于获取jsapi_ticket的api调用次数非常有限,频繁刷新jsapi_ticket会导致api调用受限,影响自身业务,开发者必须在自己的服务全局缓存jsapi_ticket 。 /// </summary> /// <param name="access_token">BasicAPI获取的access_token,也可以通过TokenHelper获取</param> /// <returns></returns> public JsapiTicketModel GetTickect(string access_token) { /// 请求URL var url = string.Format("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={0}&type=jsapi", access_token); var client = new HttpClient(); /// 声明变量 string ticket_str = ""; int expires_in_value = 7200; int type = 0; string content = ""; LogHelper.Info("------------TeamDetail-----执行autocach-ticket开始"); /// 缓存 var modules = RedisCacheHelper.AutoCache(ConstClass.RedisKey4MPrefix, "Key_Ticket", () => { LogHelper.Info("------------TeamDetail-----进入autocach-ticket开始"); LogHelper.Info("------------TeamDetail-----获取ticket开始"); /// 获取ticket var responseResult = client.GetAsync(url).Result; LogHelper.Info("------------TeamDetail-----获取ticket开始"); if (!responseResult.IsSuccessStatusCode) { return(string.Empty); } var result = responseResult.Content.ReadAsStringAsync().Result; var parseResult = JObject.Parse(result.ToString()); //var json = "{\"errcode\":0,\"errmsg\":\"ok\",\"ticket\":\"sM4AOVdWfPE4DxkXGEs8VBnCOGWyCh0yozn7VHLbWf0wR7SqMRVe-h4niB2YDaeVuDMBPYzyNoVJRY4ZZOab8Q\",\"expires_in\":7200}"; //var parseResult = JObject.Parse(json); var errcode = parseResult["errcode"]; LogHelper.Info("------------TeamDetail-----ticket-errorcode:" + errcode); var errmsg = parseResult["errmsg"]; var ticket = parseResult["ticket"]; LogHelper.Info("------------TeamDetail-----ticket:" + ticket); var expires_in = parseResult["expires_in"]; LogHelper.Info("------------TeamDetail-----ticket-expires_in:" + expires_in); if (errcode != null && errmsg != null) { if (Convert.ToInt32(errcode) == 0 && errmsg.ToString().Equals("ok")) { type = 1; if (ticket != null) { ticket_str = ticket.ToString(); } if (expires_in != null) { expires_in_value = Convert.ToInt32(expires_in); } } else { type = 2; content = parseResult["errmsg"].ToString(); ticket_str = ""; } } var data = ticket_str; LogHelper.Info("------------TeamDetail-----ticket_str:" + ticket_str); LogHelper.Info("------------TeamDetail-----进入autocach-ticket结束"); return(data); }, 7200); LogHelper.Info("------------TeamDetail-----执行autocach-ticket结束"); LogHelper.Info("------------TeamDetail-----:ticket缓存modules" + modules); JsapiTicketModel jsapiTicketModel = new JsapiTicketModel(); if (modules == null || modules.Equals("")) { jsapiTicketModel.type = type; jsapiTicketModel.content = content; jsapiTicketModel.ticket = ""; } else { jsapiTicketModel.type = 1; jsapiTicketModel.content = ""; jsapiTicketModel.ticket = modules.ToString(); } return(jsapiTicketModel); }