/// <summary> /// Called by the ASP.NET MVC framework before the action method executes. /// </summary> /// <param name="filterContext">The filter context.</param> public override void OnActionExecuting(ActionExecutingContext filterContext) { if (ConfigSetting.isDebug) { if (!LoginHelper.IsLogin()) { LoginHelper.UserLogin(UserHelper.GetModelByUserID("6c188a35-68c9-45f5-a5df-adfccc357daf")); } base.OnActionExecuting(filterContext); return; } if (filterContext.HttpContext.Request.UserAgent.ToLower().Contains("micromessenger")) { #region 微信登陆验证 if (LoginHelper.IsLogin()) { base.OnActionExecuting(filterContext); return; } else { string code = filterContext.HttpContext.Request["code"]; if (string.IsNullOrEmpty(code)) { string url = string.Format( "{0}?appid={1}&redirect_uri={2}&response_type=code&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect" , ConfigSetting.WeiXinauthUrl , ConfigSetting.WeiXinAppID , HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.AbsoluteUri)); filterContext.Result = new RedirectResult(url); return; } //获取Token OAuth_Token token = Get_token1(code); if (token != null) { if (LoginHelper.UserLogin(token)) { base.OnActionExecuting(filterContext); } else { filterContext.Result = new ContentResult() { Content = "登录失败" }; return; } } else { filterContext.Result = new ContentResult() { Content = "授权失败" }; return; } } #endregion } else { filterContext.Result = new ContentResult() { Content = "请在微信里打开" }; } return; }