Exemple #1
0
        public virtual void BeforeInit(EventArgs e)
        {
            //System key
            s_systemPostFields.Add("__EVENTTARGET");
            s_systemPostFields.Add("__EVENTARGUMENT");
            s_systemPostFields.Add("__VIEWSTATEFIELDCOUNT");
            s_systemPostFields.Add("__VIEWSTATE");
            s_systemPostFields.Add("__VIEWSTATEENCRYPTED");
            s_systemPostFields.Add("__PREVIOUSPAGE");
            s_systemPostFields.Add("__CALLBACKID");
            s_systemPostFields.Add("__CALLBACKPARAM");
            s_systemPostFields.Add("__LASTFOCUS");
            s_systemPostFields.Add(UniqueFilePathSuffixID);
            s_systemPostFields.Add("__redir");
            s_systemPostFields.Add("__EVENTVALIDATION");

            //获取请求的资源和参数
            ResourceManage rema = new ResourceManage();

            _wp.SetValue <ResourceManage>(ParameterKey.RESOURCE_MANAGER, rema);
            _wp[DomainKey.SESSION, "SessionID"] = Context.Session.SessionID;
            _wp.SetValue(DomainKey.APPLICATION_ENVIRONMENT, "ServerRootPath", Context.Server.MapPath("~"));
            _wp.SetValue(DomainKey.APPLICATION_ENVIRONMENT, "ServerRootPath_URL", Context.Request.Url.AbsoluteUri.Replace(Context.Request.FilePath, ""));

            _wp.SetValue(DomainKey.APPLICATION_ENVIRONMENT, "WebPath", Context.Request.Url.AbsoluteUri.Replace(Context.Request.RawUrl, ""));
            //设置serverinfo
            _wp[DomainKey.APPLICATION_ENVIRONMENT, "server_servername"] = Context.Server.MachineName;
            _wp[DomainKey.APPLICATION_ENVIRONMENT, "serverinfo_ip"]     = Context.Request.ServerVariables["LOCAl_ADDR"];
            //设置clientinfo
            _wp[DomainKey.APPLICATION_ENVIRONMENT, "clientinfo_ip"]             = Context.Request.UserHostAddress;
            _wp[DomainKey.APPLICATION_ENVIRONMENT, "clientinfo_browserversion"] = Context.Request.Browser.Version;
            _wp[DomainKey.APPLICATION_ENVIRONMENT, "clientinfo_platform"]       = Context.Request.Browser.Platform;
            _wp[DomainKey.APPLICATION_ENVIRONMENT, "clientinfo_userhostname"]   = Context.Request.UserHostName;


            if (Context.Request.Path != "/")
            {
                _wp.RequestResourcePath = Context.Request.PhysicalPath;
                string   reqpath = Path.GetFileNameWithoutExtension(_wp.RequestResourcePath);
                string[] ss      = reqpath.Split('.');
                _wp.Action = ss.Length > 1 ? ss[1] : "";
                _wp.RequestResourceName = ss[0];
            }

            foreach (string s in Context.Request.QueryString.Keys)
            {
                _wp[DomainKey.QUERY_STRING, s] = Context.Request.QueryString[s];
            }
        }
Exemple #2
0
        protected virtual void ProcessRequestInfoWeixin(WebParameter p, GoData d)
        {
            //微信相关信息
            p.ExtentionObj.weixin                     = FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase);
            p.ExtentionObj.weixin.signature           = ComFunc.nvl(p[DomainKey.QUERY_STRING, "signature"]);
            p.ExtentionObj.weixin.timestamp           = ComFunc.nvl(p[DomainKey.QUERY_STRING, "timestamp"]);
            p.ExtentionObj.weixin.nonce               = ComFunc.nvl(p[DomainKey.QUERY_STRING, "nonce"]);
            p.ExtentionObj.weixin.token               = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_token"]);
            p.ExtentionObj.weixin.encrypt_type        = ComFunc.nvl(p[DomainKey.QUERY_STRING, "encrypt_type"]);
            p.ExtentionObj.weixin.encrypt_key         = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_encry_key"]);
            p.ExtentionObj.weixin.appid               = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_Appid"]);
            p.ExtentionObj.weixin.appsecret           = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_Appsecret"]);
            p.ExtentionObj.weixin.weixin_mch_ssl_path = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_Mch_SSL_Path"]);
            p.ExtentionObj.weixin.weixin_mch_ssl_pass = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_Mch_SSL_Pass"]);

            p.SetValue("logkey", DateTime.Now.ToString("yyyyMMddHHmmssfff"));
            string content = string.Empty;

            if (CurrentContext.Request.Method.ToLower() == "post")
            {
                content = p.RequestContent;

                //如果内容为aes加密
                if (p.ExtentionObj.weixin.encrypt_type == "aes")
                {
                    WXBizMsgCrypt wxcpt  = new WXBizMsgCrypt(p.ExtentionObj.weixin.token, p.ExtentionObj.weixin.encrypt_key, p.ExtentionObj.weixin.appid);
                    string        msg    = "";
                    var           result = wxcpt.DecryptMsg(p.ExtentionObj.weixin.signature, p.ExtentionObj.weixin.timestamp, p.ExtentionObj.weixin.nonce, content, ref msg);
                    content = msg;
                }
                var contentobj = FrameDLRObject.IsXmlThen(content, null, FrameDLRFlags.SensitiveCase);

                if (contentobj != null)
                {
                    var root = (FrameDLRObject)contentobj.GetValue("xml");
                    foreach (var item in root.Items)
                    {
                        if (item.Key == "CreateTime")
                        {
                            p[DomainKey.POST_DATA, item.Key] = new DateTime(1970, 1, 1).AddSeconds(IntStd.IsNotIntThen(item.Value));
                        }
                        else
                        {
                            p[DomainKey.POST_DATA, item.Key] = item.Value;
                        }

                        if (item.Value is FrameDLRObject)
                        {
                            foreach (var sub in ((FrameDLRObject)item.Value).Items)
                            {
                                if (sub.Key == "CreateTime")
                                {
                                    p[DomainKey.POST_DATA, sub.Key] = new DateTime(1970, 1, 1).AddSeconds(IntStd.IsNotIntThen(sub.Value));
                                }
                                else
                                {
                                    p[DomainKey.POST_DATA, sub.Key] = sub.Value;
                                }
                            }
                        }
                    }
                }
                //微信推送过来的xml对象
                p.ExtentionObj.weixin.RecieveXMLObject = contentobj;
                //事件触发时的action处理
                if (ComFunc.nvl(p[DomainKey.POST_DATA, "MsgType"]) == "event")
                {
                    p.Action = "event_" + ComFunc.nvl(p[DomainKey.POST_DATA, "Event"]);
                }
                else
                {
                    //普通消息处理,action为消息类型
                    p.Action = "msg_" + ComFunc.nvl(p[DomainKey.POST_DATA, "MsgType"]);
                }
            }
            else
            {
                //action为api_valid的时候为微信服务器的验证请求
                p.Action = "api_valid";
            }
        }
        protected override void ProcessRequestInfoWeixin(WebParameter p, GoData d)
        {
            //微信相关信息
            p.ExtentionObj.weixin = FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase);
            // 微信企业号的加密签名为msg_signature而不是signature,所以得重写
            p.ExtentionObj.weixin.signature           = ComFunc.nvl(p[DomainKey.QUERY_STRING, "msg_signature"]);
            p.ExtentionObj.weixin.timestamp           = ComFunc.nvl(p[DomainKey.QUERY_STRING, "timestamp"]);
            p.ExtentionObj.weixin.nonce               = ComFunc.nvl(p[DomainKey.QUERY_STRING, "nonce"]);
            p.ExtentionObj.weixin.token               = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_token"]);
            p.ExtentionObj.weixin.encrypt_type        = ComFunc.nvl(p[DomainKey.QUERY_STRING, "encrypt_type"]) == "" ? "aes" : ComFunc.nvl(p[DomainKey.QUERY_STRING, "encrypt_type"]);
            p.ExtentionObj.weixin.encrypt_key         = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_encry_key"]);
            p.ExtentionObj.weixin.appid               = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_Appid"]);
            p.ExtentionObj.weixin.appsecret           = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_Appsecret"]);
            p.ExtentionObj.weixin.weixin_mch_ssl_path = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_Mch_SSL_Path"]);
            p.ExtentionObj.weixin.weixin_mch_ssl_pass = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_Mch_SSL_Pass"]);
            // 20171124 Ge.Song 针对企业微信添加AgentId
            p.ExtentionObj.weixin.agentid = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_AgentId"]);

            p.SetValue("logkey", DateTime.Now.ToString("yyyyMMddHHmmssfff"));
            string content = string.Empty;

            if (CurrentContext.Request.Method.ToLower() == "post")
            {
                content = p.RequestContent;
                WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(p.ExtentionObj.weixin.token, p.ExtentionObj.weixin.encrypt_key, p.ExtentionObj.weixin.appid);
                string        msg   = "";
                wxcpt.DecryptMsg(p.ExtentionObj.weixin.signature, p.ExtentionObj.weixin.timestamp, p.ExtentionObj.weixin.nonce, content, ref msg);
                content = msg;

                if (content != "")
                {
                    XmlDocument doc = new XmlDocument();
                    //防范xxe攻击
                    doc.XmlResolver = null;
                    doc.LoadXml(content);
                    var root = doc.FirstChild;
                    foreach (XmlNode node in root.ChildNodes)
                    {
                        // 一般来说企业微信事件只会回传AgentID,ToUserName,Encrypt
                        p[DomainKey.POST_DATA, node.Name] = node.Name == "CreateTime"
                                                            ? (object)new DateTime(1970, 1, 1).AddSeconds(int.Parse(node.InnerText))
                                                            : node.InnerText;
                        if (node.HasChildNodes)
                        {
                            foreach (XmlNode sub in node.ChildNodes)
                            {
                                if (node.Name == "CreateTime")
                                {
                                    p[DomainKey.POST_DATA, sub.Name] = new DateTime(1970, 1, 1).AddSeconds(int.Parse(sub.InnerText));
                                }
                                else
                                {
                                    p[DomainKey.POST_DATA, sub.Name] = sub.InnerText;
                                }
                            }
                        }
                    }
                }
                //事件触发时的action处理
                if (ComFunc.nvl(p[DomainKey.POST_DATA, "MsgType"]) == "event")
                {
                    p.Action = "event_" + ComFunc.nvl(p[DomainKey.POST_DATA, "Event"]);
                }
                else
                {
                    //普通消息处理,action为消息类型
                    p.Action = "msg_" + ComFunc.nvl(p[DomainKey.POST_DATA, "MsgType"]);
                }
            }
            else
            {
                //action为api_valid的时候为微信服务器的验证请求
                p.Action = "api_valid";
            }
        }