using RFrameGenerate.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;

namespace System.Web.Mvc
{
    /// <summary>
    /// 是否要在微信中打开
    /// </summary>
    public class IsWeiXinOpenAttribute : ActionFilterAttribute
    {
        public bool IsWeiXinOpen = true;
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (IsWeiXinOpen == true)
            {
                if (RFrameGenerate.Common.CurrentManage.IsDebug == true)
                    return;
                var Request = filterContext.HttpContext.Request;
                var weixinopen = Request.UserAgent.ToString();
                if (weixinopen.Contains("MicroMessenger") == false)
                {
                    string url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7582db883b74dba0&redirect_uri=http%3A%2F%2Fhongbao.super.cn%2Findex%2Ftotal%3Fhelp%26ownerID%3DoPGaIjkZYBTaChHOK9Pgck1exbgE&response_type=code&scope=snsapi_userinfo&state=&connect_redirect=1#wechat_redirect";
                    filterContext.Result = new RedirectResult(url);
                    return;
                }
            }
        }
    }
}