public static string GetCartID(HttpContext ctx) { string name = "Cart_OrderNo"; string cartID = CookieHelper.Get(ctx, name); try { if (string.IsNullOrEmpty(cartID)) { cartID = GenerateCartID(); CookieHelper.Set(ctx, name, cartID); } } catch (Exception ex) { ZLLog.L("GetCartID,购物车ID生成出错,原因:" + ex.Message); } return(cartID); }
//最终用于清除的方法,过期与主动都调用其 public static void ClearByKeys(string keys) { keys = keys.TrimEnd(','); if (!string.IsNullOrEmpty(keys)) { try { foreach (string key in keys.Split(',')) { //后期改为缓存事件分发 M_Cache model = UserSession[key]; B_User.UpdateField("LastActiveTime", (DateTime.Now.AddMinutes(-ActiveSpan)).ToString(), model.UserID, false); UserSession.Remove(key); } } catch (Exception ex) { ZLLog.L(Model.ZLEnum.Log.labelex, "用户缓存出错:" + ex.Message); } } }
public static string GetCartID(HttpContext context = null) { string cartID = ""; try { if (context == null) { context = HttpContext.Current; } if (context.Request.Cookies["Shopby"] == null || context.Request.Cookies["Shopby"]["OrderNo"] == null) { context.Response.Cookies["Shopby"]["OrderNo"] = GenerateCartID(); } cartID = context.Request.Cookies["Shopby"]["OrderNo"]; } catch (Exception ex) { ZLLog.L("GetCartID,购物车ID生成出错,原因:" + ex.Message); } return(cartID); }
/// <summary> /// 获取GET提交 /// </summary> /// <param name="html">模板html</param> /// <returns></returns> public string GetRequest(string html) { string pattern = @"\{\$GetRequest\([a-z0-9]*\)\$\}";//{$GetRequest(变量名)$} string url = rawurl.ToLower(); string query = url.Contains("?") ? url.Split('?')[1] : ""; MatchCollection matchs = Regex.Matches(html, pattern, RegexOptions.IgnoreCase); for (int i = 0; i < matchs.Count; i++) { MatchCollection Smallmatchs = Regex.Matches(matchs[i].ToString(), pattern, RegexOptions.IgnoreCase); foreach (Match Smallmatch in Smallmatchs) { string requesttxt = (Smallmatch.ToString().Replace(@"{$GetRequest(", "").Replace(@")$}", "") ?? "").ToLower();//变量名 string result = ""; try { //从query中取值 result = StrHelper.GetValFromUrl(url, requesttxt); //如为空,则检测是否为路由页面 /Shop/1 /Item/1 if (string.IsNullOrEmpty(result) && (requesttxt.Equals("id") || requesttxt.Equals("itemid"))) { result = GetIDVal(url); } // /class_1/default if (string.IsNullOrEmpty(result) && requesttxt.Equals("nodeid")) { result = Regex.Split(url, Regex.Escape("class_"))[1].Split('/')[0]; } result = SafeValue(result); //ZLLog.L(url + "|" + result + "|" + Smallmatchs[0].Value); } catch (Exception ex) { ZLLog.L(Model.ZLEnum.Log.exception, ex.Message); } result = HttpUtility.HtmlEncode(result); if (!string.IsNullOrEmpty(result) && SafeSC.CheckData(result)) { result = ""; ZLLog.L(ZLEnum.Log.safe, "GetRequest:" + result); } html = html.Replace(Smallmatch.ToString(), result); } } return(html); }
/// <summary> /// 获取粉丝信息模型,该接口需要公众号已认证,否则无法获取粉丝信息 /// </summary> public M_WX_User GetWxUserModel(string openid) { M_WX_User userMod = new M_WX_User(); userMod.OpenID = openid; string result = APIHelper.GetWebResult(apiurl + "user/info?access_token=" + AccessToken + "&openid=" + openid); JObject obj = JsonConvert.DeserializeObject <JObject>(result); try { userMod.Name = obj["nickname"].ToString(); userMod.Sex = DataConverter.CLng(obj["sex"]); userMod.City = obj["city"].ToString(); userMod.Province = obj["province"].ToString(); userMod.Country = obj["country"].ToString(); userMod.HeadImgUrl = obj["headimgurl"].ToString(); userMod.Groupid = DataConverter.CLng(obj["groupid"]); } catch (Exception ex) { ZLLog.L("GetWxUserModel出错,原因:" + ex.Message + ",返回:" + result); } return(userMod); }
private void WriteLog(string func, string label, string message, string remind = "") { string tlp = "来源:B_CreateShopHtml,方法名:{0},标签:{1},报错:{2},备注:{3}"; ZLLog.L(ZLEnum.Log.labelex, string.Format(tlp, func, label, message, remind)); }