/// <summary> /// 验证OpenId /// </summary> /// <param name="openId"></param> /// <returns></returns> public static bool ValidateOpenId(string openId) { var result = false; if (!string.IsNullOrWhiteSpace(openId)) { var userId = CacheUtil.Get <string>("openId" + openId); if (!string.IsNullOrWhiteSpace(userId)) { result = true; } } if (!result) { var url = BaseSystemInfo.UserCenterHost + "UserCenterV42/LogonService.ashx"; var webClient = new WebClient(); var postValues = new NameValueCollection(); postValues.Add("function", "ValidateOpenId"); postValues.Add("systemCode", BaseSystemInfo.SystemCode); postValues.Add("ipAddress", Utils.GetIp()); postValues.Add("securityKey", BaseSystemInfo.SecurityKey); postValues.Add("openId", openId); // 向服务器发送POST数据 var responseArray = webClient.UploadValues(url, postValues); var response = Encoding.UTF8.GetString(responseArray); if (!string.IsNullOrEmpty(response)) { result = response.Equals(true.ToString(), StringComparison.InvariantCultureIgnoreCase); } } return(result); }
/// <summary> /// 根据ID获取用户领域模型。 /// </summary> /// <param name="userId"></param> /// <param name="clear"></param> /// <returns></returns> public UserDomainModel GetUserDomainModelById(string userId, bool clear) { if (string.IsNullOrEmpty(userId)) { return(null); } string cacheKey = CacheKey.GetKeyDefine(CacheKey.USERDOMAIN_INFO, userId); UserDomainModel result = CacheUtil.Get <UserDomainModel>(cacheKey); if (result == null || clear) { UserInfoModel basicInfo = GetUserModelByIdFromDatabase(userId); if (basicInfo != null) { result = new UserDomainModel(); result.BasicInfo = basicInfo; result.InGroupList = UserGroupInfoService.Instance.GetUserInGroupListFromDatabase(basicInfo.UserId); CacheUtil.Set(cacheKey, result); } } return(result); }
/// <summary> /// 获取js 接口 Ticket /// 内部已经处理缓存 /// </summary> /// <param name="type"></param> /// <returns></returns> public async Task <WxGetJsTicketResp> GetJsTicketAsync(WxJsTicketType type) { string key = string.Format(WxCacheKeysUtil.OffcialJsTicketKey, ApiConfig.AppId, type); var ticket = CacheUtil.Get <WxGetJsTicketResp>(key, ModuleNames.SocialCenter); if (ticket != null && ticket.expires_time > DateTime.Now) { return(ticket); } var req = new OsHttpRequest(); req.HttpMothed = HttpMothed.GET; req.AddressUrl = string.Concat(m_ApiUrl, string.Concat("cgi-bin/ticket/getticket?type=", type.ToString())); var ticketRes = await RestCommonOffcialAsync <WxGetJsTicketResp>(req); if (ticketRes.IsSuccess()) { ticketRes.expires_time = DateTime.Now.AddSeconds(ticketRes.expires_in); CacheUtil.AddOrUpdate(key, ticketRes, TimeSpan.FromSeconds(ticketRes.expires_in - 10), null, ModuleNames.SocialCenter); } return(ticketRes); }
public ResponseWrapper <List <MessageEntity> > ReceiveMessage(string clientId, string ticks) { ResponseWrapper <List <MessageEntity> > response = new ResponseWrapper <List <MessageEntity> >(); if (CacheUtil.Exists(clientId) == false) { response.ReturnCode = 0; response.Message = "Login Failed"; response.InnerMessage = "The client id is expired or does not exists."; response.Result = null; return(response); } DateTime endTime = new DateTime(long.Parse(ticks)); DateTime startTime = endTime.AddHours(-12); var MyQQEntity = (MyQQEntity)CacheUtil.Get(clientId); string qqAccount = MyQQEntity.QQAccount; List <MessageEntity> messages = myQQDAL.GetMessageList(qqAccount, startTime, endTime); response.ReturnCode = 1; response.Message = ""; response.InnerMessage = ""; response.Result = messages; return(response); }
/// <summary>显示产品详细内容的页面 /// </summary> /// <param name="id">要显示的产品的ID</param> /// <returns>产品详细页面</returns> public ActionResult Detail(int id) { Cart cart = (User as SolemartUser).Cart; CartItem item = cart.CartItems.FirstOrDefault(c => c.ProductID == id); if (item != null) { ViewBag.CartItem = item.Amount; } else { ViewBag.CartItem = 0; } string cacheKey = string.Format("product_{0}", id); ProductDetailViewModel model = null; if (CacheUtil.Exist(cacheKey)) { model = CacheUtil.Get <ProductDetailViewModel>(cacheKey); } else { SaledProductItem saleInfo = ProductManager.GetSaledProductByID(id); ProductItem product = ProductManager.GetProductWithBrandByID(id); List <ProductImageItem> images = ProductManager.GetProductNoLogoImage(id); int commentCount = ProductManager.GetProductCommentCount(id); string remainAmountString = string.Empty; if (product.Unit == "斤") { remainAmountString = string.Format("{0}", product.StockCount - product.ReserveCount); } else { remainAmountString = string.Format("{0:d}", (int)(product.StockCount - product.ReserveCount)); } model = new ProductDetailViewModel { ProductID = id, ProductName = product.ProductName, ProductDescription = product.Description, Price = saleInfo.Price, Unit = product.Unit, Discount = saleInfo.Discount, SpecialFlag = saleInfo.SpecialFlag, RemainAmount = remainAmountString, BrandDescription = product.Brand.Description, BrandLogo = product.Brand.BrandLogo, BrandUrl = product.Brand.BrandUrl, BrandName = product.Brand.ZhName, CommentCount = commentCount, Images = images }; CacheUtil.Add <ProductDetailViewModel>(cacheKey, model, 600); } return(View(model)); }
public Dictionary <string, CustomerExtAttributesModel> GetCustomerAttributeList(string extattributeid, bool clear) { if (string.IsNullOrEmpty(extattributeid)) { return(null); } Dictionary <string, CustomerExtAttributesModel> dict = null; string cacheKey = CacheKey.CUSTOMER_ATTRIBUTE_DICT.GetKeyDefine(extattributeid); dict = CacheUtil.Get <Dictionary <string, CustomerExtAttributesModel> >(cacheKey); if (dict == null || clear) { dict = GetProductCustomerAttributeListFromDatabase(extattributeid); if (dict != null) { CacheUtil.Set(cacheKey, dict); } else { CacheUtil.Remove(cacheKey); } } return(dict); }
/// <summary> /// 获取公众号的AccessToken /// </summary> /// <returns></returns> public async Task <WxOffAccessTokenResp> GetAccessTokenAsync() { var tokenResp = CacheUtil.Get <WxOffAccessTokenResp>(m_OffcialAccessTokenKey, ModuleNames.SocialCenter); if (tokenResp != null && tokenResp.expires_date >= DateTime.Now) { return(tokenResp); } var req = new OsHttpRequest { AddressUrl = $"{m_ApiUrl}/cgi-bin/token?grant_type=client_credential&appid={ApiConfig.AppId}&secret={ApiConfig.AppSecret}", HttpMothed = HttpMothed.GET }; tokenResp = await RestCommonJson <WxOffAccessTokenResp>(req); if (!tokenResp.IsSuccess()) { return(tokenResp); } tokenResp.expires_date = DateTime.Now.AddSeconds(tokenResp.expires_in - 600); CacheUtil.AddOrUpdate(m_OffcialAccessTokenKey, tokenResp, TimeSpan.FromSeconds(tokenResp.expires_in), null, ModuleNames.SocialCenter); return(tokenResp); }
/// <summary> /// 获取产品信息领域模型。 /// </summary> /// <param name="productId"></param> /// <param name="clear"></param> /// <returns></returns> public ProductInfoDomainModel GetProductDomainInfoByProductId(string productId, bool clear) { if (string.IsNullOrEmpty(productId)) { return(null); } string cacheKey = CacheKey.PRODUCT_DOMAIN_MODEL.GetKeyDefine(productId); ProductInfoDomainModel info = CacheUtil.Get <ProductInfoDomainModel>(cacheKey); if (info == null || clear) { info = GetProductDomainInfoByProductIdFromDatabase(productId); if (info != null) { CacheUtil.Set(cacheKey, info); } else { CacheUtil.Remove(cacheKey); } } return(info); }
/// <summary> /// 根据ID获取工单类型领域模型。 /// </summary> /// <param name="typeId"></param> /// <param name="clear"></param> /// <returns></returns> public WorkOrderTypeDomainModel GetTypeDomainModelById(string typeId, bool clear) { if (string.IsNullOrEmpty(typeId) || typeId == "All") { return(null); } string cacheKey = CacheKey.WORKORDER_TYPE_DOMAINMODEL.GetKeyDefine(typeId); WorkOrderTypeDomainModel model = CacheUtil.Get <WorkOrderTypeDomainModel>(cacheKey); if (model == null || clear) { model = GetWorkOrderTypeDomainModelFromDatabase(typeId); if (model != null) { CacheUtil.Set(cacheKey, model); } //else //{ // CacheUtil.Remove(cacheKey); //} } return(model); }
/// <summary> /// 根据ID获取自定义枚举信息。 /// </summary> /// <param name="dataId"></param> /// <returns></returns> public CustomDataDomainModel GetCustomDataDomainModelById(string dataId, bool clear) { if (string.IsNullOrEmpty(dataId)) { return(null); } string cacheKey = CacheKey.CUSTOM_DATA_INFO_BYID.GetKeyDefine(dataId); CustomDataDomainModel model = CacheUtil.Get <CustomDataDomainModel>(cacheKey); if (model == null || clear) { model = GetCustomDataDomainModelByIdFromDatabase(dataId); if (model != null) { CacheUtil.Set(cacheKey, model); } else { CacheUtil.Remove(cacheKey); } } return(model); }
/// <summary> /// 获取最近一个月登录系统的用户,从缓存服务器,登录接口获取,这样僵尸账户就会可以过滤了。 /// </summary> /// <returns>影响行数</returns> public int GetActiveUsers() { var result = 0; // 先把用户来源都修改为 空。 var commandText = "UPDATE " + BaseUserEntity.CurrentTableName + " SET " + BaseUserEntity.FieldUserFrom + " = NULL WHERE " + BaseUserEntity.FieldUserFrom + " = 'Base'"; result = ExecuteNonQuery(commandText); // 通过中天登录的,都设置为 "Base"; var key = string.Empty; result = 0; var i = 0; key = "Logon:UserCount:" + DateTime.Now.ToString("yyyy-MM"); var list = CacheUtil.Get <List <int> >(key); foreach (var id in list) { i++; commandText = "UPDATE " + BaseUserEntity.CurrentTableName + " SET " + BaseUserEntity.FieldUserFrom + " = 'Base' WHERE " + BaseUserEntity.FieldId + " = " + id; result += ExecuteNonQuery(commandText); Console.WriteLine("Count:" + i + "/" + list.Count + " Id:" + id); } return(result); }
public ResponseWrapper <List <GroupEntity> > GetGroupList(string clientId) { ResponseWrapper <List <GroupEntity> > response = new ResponseWrapper <List <GroupEntity> >(); if (CacheUtil.Exists(clientId) == false) { response.ReturnCode = 0; response.Message = "Login Failed"; response.InnerMessage = "The client id is expired or does not exists."; response.Result = null; return(response); } var MyQQEntity = (MyQQEntity)CacheUtil.Get(clientId); List <GroupEntity> groups = myQQDAL.GetQQGroupsByQQAccount(MyQQEntity.QQAccount); response.ReturnCode = 1; response.Message = ""; response.InnerMessage = ""; response.Result = groups; return(response); }
public Dictionary <string, ProductCategorySalesStatusModel> GetProductCategorySalesStatusList(string productCategoryId, bool clear) { if (string.IsNullOrEmpty(productCategoryId)) { return(null); } Dictionary <string, ProductCategorySalesStatusModel> dict = null; string cacheKey = CacheKey.PRODUCT_CATEGORY_SALESTATUS_DICT.GetKeyDefine(productCategoryId); dict = CacheUtil.Get <Dictionary <string, ProductCategorySalesStatusModel> >(cacheKey); if (dict == null || clear) { dict = GetProductCategorySalesStatusListFromDatabase(productCategoryId); if (dict != null) { CacheUtil.Set(cacheKey, dict); } else { CacheUtil.Remove(cacheKey); } } return(dict); }
/// <summary> /// 获取公众号的AccessToken /// </summary> /// <returns></returns> public WxOffAccessTokenResp GetOffcialAccessToken() { var tokenResp = CacheUtil.Get <WxOffAccessTokenResp>(m_OffcialAccessTokenKey, ModuleNames.SnsCenter); if (tokenResp == null || tokenResp.expires_date < DateTime.Now) { OsHttpRequest req = new OsHttpRequest(); req.AddressUrl = $"{m_ApiUrl}/cgi-bin/token?grant_type=client_credential&appid={ApiConfig.AppId}&secret={ApiConfig.AppSecret}"; req.HttpMothed = HttpMothed.GET; tokenResp = RestCommon <WxOffAccessTokenResp>(req); if (!tokenResp.IsSuccess) { return(tokenResp); } tokenResp.expires_date = DateTime.Now.AddSeconds(tokenResp.expires_in - 600); CacheUtil.AddOrUpdate(m_OffcialAccessTokenKey, tokenResp, TimeSpan.FromSeconds(tokenResp.expires_in), null, ModuleNames.SnsCenter); } return(tokenResp); }
/// <summary> /// Process Login Request /// </summary> /// <param name="token"></param> /// <param name="redirectUrl"></param> private async void ProcessLoginRequest(string clientId, string redirectUrl) { var MyQQEntity = (MyQQEntity)CacheUtil.Get(clientId); lock (MyQQEntity) { if (MyQQEntity.IsInitialized) { return; } else { MyQQEntity.IsInitialized = true; CacheUtil.Update(clientId, MyQQEntity); } } var smartQQWarapper = loginService.ProcessLoginRequest(redirectUrl); SmartQQ.AccountService accountService = new SmartQQ.AccountService(smartQQWarapper); MyQQEntity.QQAccount = smartQQWarapper.QQAccount; bool forceInit = !myQQDAL.InitializeMyQQEnity(MyQQEntity); if (MyQQEntity.GroupCount == 0) { smartQQWarapper.GroupAccounts = accountService.GetGroupList(true); System.Console.WriteLine("Initialize QQ groups successfully."); } if (MyQQEntity.DiscussionCount == 0) { smartQQWarapper.DiscussionAccounts = accountService.GetDiscussionGroupList(true); System.Console.WriteLine("Initialize QQ discussions successfully."); } if (MyQQEntity.FriendAccount == 0) { smartQQWarapper.FriendAccounts = accountService.GetFriendList(true); System.Console.WriteLine("Initialize QQ friends successfully."); } smartQQWarapper.Online = true; if (MyQQEntity.Name == null || MyQQEntity.Name == "") { smartQQWarapper = accountService.GetQQProfile(); System.Console.WriteLine("Initialize QQ profile successfully."); } myQQDAL.InitializeSmartQQ(smartQQWarapper); System.Console.WriteLine("Initialize MyQQ context successfully."); myQQDAL.InitializeMyQQEnity(MyQQEntity, forceInit); MyQQEntity.IsInitialized = false; CacheUtil.Update(clientId, MyQQEntity); MyQQRobot.LaunchMyQQRobot(smartQQWarapper); }
/// <summary> /// 从缓存中获取实体 /// </summary> /// <param name="key"></param> /// <returns></returns> public static BaseUserContactEntity GetCacheByKey(string key) { BaseUserContactEntity result = null; if (!string.IsNullOrWhiteSpace(key)) { result = CacheUtil.Get <BaseUserContactEntity>(key); } return(result); }
/// <summary> /// 从缓存获取 /// </summary> /// <param name="key"></param> /// <returns></returns> public static BaseOrganizationEntity GetCacheByKey(string key) { BaseOrganizationEntity result = null; if (!string.IsNullOrWhiteSpace(key)) { CacheUtil.Get <BaseOrganizationEntity>(key); } return(result); }
/// <summary> /// 获取List缓存 /// </summary> /// <param name="key"></param> /// <returns></returns> private static List <BaseModuleEntity> GetListCache(string key) { List <BaseModuleEntity> result = null; if (!string.IsNullOrWhiteSpace(key)) { result = CacheUtil.Get <List <BaseModuleEntity> >(key); } return(result); }
public void InsertCache() { for (int i = 0; i < 50; i++) { CacheUtil.Insert(i.ToString(), "值:" + i); } for (int i = 0; i < 50; i++) { var obj = CacheUtil.Get(i.ToString()); Console.WriteLine(obj); } }
// // 获取用户的最新 OpenId 的方法 // /// <summary> /// /// </summary> /// <param name="userInfo"></param> /// <param name="cachingSystemCode"></param> /// <param name="useCaching"></param> /// <param name="useDataBase"></param> /// <param name="useUserCenterHost"></param> /// <returns></returns> public static string GetUserOpenId(BaseUserInfo userInfo, string cachingSystemCode = null, bool useCaching = false, bool useDataBase = true, bool useUserCenterHost = false) { var result = string.Empty; if (useCaching && userInfo != null && userInfo.UserId > 0) { var key = string.Empty; if (string.IsNullOrEmpty(cachingSystemCode)) { key = "userId:" + userInfo.Id; } else { key = "userId:" + cachingSystemCode + ":" + userInfo.Id; } result = CacheUtil.Get <string>(key); // 2016-04-05 吉日嘎拉 这里代码有错误,不为空时进行处理 if (!string.IsNullOrWhiteSpace(result)) { userInfo.OpenId = result; HttpContext.Current.Session[SessionName] = userInfo; HttpContext.Current.Session["openId"] = userInfo.OpenId; // 2016-04-05 吉日嘎拉,这里可以提前结束了,提高效率 return(result); } if (useDataBase) { var userLogonManager = new BaseUserLogonManager(userInfo); result = userLogonManager.GetUserOpenId(userInfo, cachingSystemCode); } if (string.IsNullOrEmpty(result) && useUserCenterHost) { //停用远程获取 Troy.Cui 2018.07.23 //result = LogonHttpUtil.GetUserOpenId(userInfo, cachingSystemCode); } // 从数据库获取,这里要考虑读写分离的做法 if (!string.IsNullOrWhiteSpace(result)) { userInfo.OpenId = result; HttpContext.Current.Session[SessionName] = userInfo; HttpContext.Current.Session["openId"] = userInfo.OpenId; // 这里这样处理一下,提高下次处理的效率 SetUserOpenId(userInfo.Id.ToString(), userInfo.OpenId, cachingSystemCode); } } return(result); }
/// <summary> /// 验证验证码是否正确 /// </summary> /// <param name="loginName"></param> /// <param name="passcode"></param> /// <returns></returns> private static ResultMo CheckPasscode(string loginName, string passcode) { var key = string.Concat(GlobalKeysUtil.RegLoginVertifyCodePre, loginName); var code = CacheUtil.Get <string>(key); if (string.IsNullOrEmpty(code) || passcode != code) { return(new ResultMo(ResultTypes.ObjectStateError, "验证码错误")); } CacheUtil.Remove(key); return(new ResultMo()); }
public ActionResult ImagePreview(string guid) { guid = "preview-" + guid; if (CacheUtil.ExistCache(guid)) { byte[] imageBuffer = CacheUtil.Get <byte[]>(guid); return(File(imageBuffer, "image/Jpeg")); } else { return(Content("图片不存在!" + guid)); } }
public static string GetAuth(string account) { if (CacheUtil.ExistCache("Auth")) { var data = CacheUtil.Get <IDictionary <string, string> >("Auth"); if (data.ContainsKey(account)) { return(data[account]); } } string auth = SQL.QueryValue <string>("select Auth from Account where AccountName=@p0", account); SetAuth(account, auth); return(auth); }
public WorkOrderTypeTreeDomainModel GetWorkOrderTypeTree(bool clearCache) { string cacheKey = CacheKey.WORKORDER_TYPE_TREE; WorkOrderTypeTreeDomainModel tree = CacheUtil.Get <WorkOrderTypeTreeDomainModel>(cacheKey); if (tree == null || clearCache) { tree = GetWorkOrderTypeTreeFromDatabase(); if (tree != null) { CacheUtil.Set(cacheKey, tree); } } return(tree); }
/// <summary> /// 获取部门结构树。 /// </summary> /// <param name="clearCache"></param> /// <returns></returns> public DepartmentDomainModel GetDepartmentTree(bool clearCache) { string cacheKey = CacheKey.DEPARTMENT_TREE; DepartmentDomainModel tree = CacheUtil.Get <DepartmentDomainModel>(cacheKey); if (tree == null || clearCache) { tree = GetDepartmentTreeFromDatabase(); if (tree != null) { CacheUtil.Set(cacheKey, tree); } } return(tree); }
/// <summary> /// 获取用户组列表字典。 /// </summary> /// <param name="clear"></param> /// <returns></returns> public Dictionary <string, UserGroupInfoModel> GetUserGroupList(bool clear) { string cacheKey = CacheKey.USERGROUP_DICT; Dictionary <string, UserGroupInfoModel> dict = CacheUtil.Get <Dictionary <string, UserGroupInfoModel> >(cacheKey); if (dict == null || clear) { dict = GetUserGroupListFromDatabase(); if (dict != null) { CacheUtil.Set(cacheKey, dict); } } return(dict); }
///// <summary> ///// 获取客户扩展属性及分组列表。 ///// </summary> ///// <returns></returns> ///// <remarks> ///// Dictionary<属性名称,分组名称> ///// </remarks> //public Dictionary<string, string> GetCustomerExtAttributeNameAndGroupList() //{ // return null; //} /// <summary> /// 获取列表字典。 /// </summary> /// <param name="clear"></param> /// <returns></returns> public Dictionary <string, CustomerExtAttributesModel> GetCustomerAttributeList(bool clear) { string cacheKey = CacheKey.CUSTOMER_ATTRIBUTE_DICT; Dictionary <string, CustomerExtAttributesModel> dict = CacheUtil.Get <Dictionary <string, CustomerExtAttributesModel> >(cacheKey); if (dict == null || clear) { dict = GetCustometerAttriListFromDatabase(); if (dict != null) { CacheUtil.Set(cacheKey, dict); } } return(dict); }
// 在此添加你的代码... public PayPosMachineInfoModel GetPosMachineById(string posMachineId, bool clear) { string cacheKey = CacheKey.POS_MACHINE_DATAMODEL.GetKeyDefine(posMachineId); PayPosMachineInfoModel model = CacheUtil.Get <PayPosMachineInfoModel>(cacheKey); if (model == null || clear) { model = Retrieve(posMachineId); if (model != null) { CacheUtil.Set(cacheKey, model); } } return(model); }
/// <summary> /// 根据ID获取领域模型。 /// </summary> /// <param name="userId"></param> /// <param name="clear"></param> /// <returns></returns> public CustomerAttributeGroupInfoModel GetGroupInfoById(string Id, bool clear) { string cacheKey = CacheKey.GetKeyDefine(CacheKey.CUSTOMER_GroupInfo_DICT, Id); CustomerAttributeGroupInfoModel result = CacheUtil.Get <CustomerAttributeGroupInfoModel>(cacheKey); if (result == null || clear) { CustomerAttributeGroupInfoModel basicInfo = GetCustomerGroupFromDatabase(Id); if (basicInfo != null) { result = new CustomerAttributeGroupInfoModel(); result = basicInfo; CacheUtil.Set(cacheKey, result); } } return(result); }
public static void SetAuth(string account, string auth) { IDictionary <string, string> data; if (CacheUtil.ExistCache("Auth")) { data = CacheUtil.Get <IDictionary <string, string> >("Auth"); data[account] = auth; } else { data = new Dictionary <string, string> { { account, auth } }; CacheUtil.Set("Auth", data); } }