Пример #1
0
        /// <summary>
        /// 微信公众号引导页
        /// </summary>
        /// <param name="url">微信前端传递的跳转url</param>
        /// <returns>成功时,重定向至获取用户信息</returns>
        public ActionResult Index(string url)
        {
            if (!string.IsNullOrEmpty(url))
            {
                url = WXHelper.DecodeBase64(url);
                string state = EncryptHelper.MD5Encrypt(url);
                //判断url根据MD5生成的密文在缓存中是否存在
                object objUrl = CacheHelper.GetCache(state);
                if (objUrl == null)
                {
                    CacheHelper.AddCache(state, url, 5);//不存在则将url和对应的密文存储在缓存中,存储时长为5分钟
                }
                else
                {
                    CacheHelper.SetCache(state, url, 5);//存在则将url和对应的密文在缓存中更新,更新存储时长为5分钟
                }
                return(Redirect(string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_base&state={2}#wechat_redirect", appId, ConfigurationManager.AppSettings["zp_apppath"] + "/Recruitment/Auth/GetUserInfo", state)));
            }
            else
            {
                ViewData["errmsg"] = "重定向url不能为空!";
            }

            return(View());
        }