Exemplo n.º 1
0
        protected override void ProcessRequestPath(WebParameter p, GoData d)
        {
            var context = p.CurrentHttpContext;

            //抓取请求资源
            p.RequestResourcePath = ComFunc.nvl(context.Request.Path).Replace("\\", "/").Replace(weixinroothome.Replace("~", ""), "");
            if (p.RequestResourceName == "" && p.RequestResourcePath == "/")
            {
                p.RequestResourcePath = p.RequestResourcePath + weixinhome;
            }

            var ext = Path.GetExtension(p.RequestResourcePath);

            if (ext != "")
            {
                string   reqpath = Path.GetFileNameWithoutExtension(p.RequestResourcePath);
                string[] ss      = reqpath.Split('.');
                p.Action = ss.Length > 1 ? ss[1] : "";
                p.RequestResourceName = ss.Length > 0 ? ss[0] : "";
                p.RequestResources    = ss;
            }
            else
            {
                var turl = p.RequestResourcePath.Replace("~", "");
                turl = turl.StartsWith("/") ? turl.Substring(1) : turl;
                string[] ss = turl.Split('/');
                p.Action = ss.Length > 1 ? ss[1] : "";
                p.RequestResourceName = ss.Length > 0 ? ss[0] : "";
                p.RequestResources    = ss;
            }
        }
Exemplo n.º 2
0
 protected override void InvokeAction(WebParameter p, GoData d)
 {
     if (IsValid4Invoke(p, d))
     {
         base.InvokeAction(p, d);
     }
 }
Exemplo n.º 3
0
        protected override bool IsValid4Invoke(WebParameter p, GoData d)
        {
            var rtn = true;

//            if (!GlobalPrepare.IsIgnoreLoginAuth(p))
//            {
//                if (p.LoginInfo == null)
//                {
//                    rtn = false;
//                    if(ComFunc.nvl(p.CurrentHttpContext.Request.Headers["x-requested-with"].FirstOrDefault()) == "XMLHttpRequest"
//                        && ComFunc.nvl(p.CurrentHttpContext.Request.Headers["x-request-async"].FirstOrDefault()) == "true")
//                    {
//                        d.ResponseData = FrameDLRObject.CreateInstance(@"{
//__isneedlogin__:true,
//__loginurl__:'/admin'
//}");
//                    }
//                    else
//                    {
//                        d.ResponseData = FrameDLRObject.CreateInstance();
//                        d.RedirectUri = "/admin";
//                    }

//                }
//            }
            return(rtn);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 业务逻辑执行之前的检核判定,如果为true,则执行业务逻辑模块,否则不执行
        /// </summary>
        /// <param name="p"></param>
        /// <param name="d"></param>
        /// <returns></returns>
        protected virtual bool IsValid4Invoke(WebParameter p, GoData d)
        {
            var isrun = true;

            if (!IsWeixinSignValid(p, d))
            {
                isrun = false;
            }
            return(isrun);
        }
Exemplo n.º 5
0
        public static void RenderView(WebParameter wp, GoData gd, HttpContext context, TextWriter writer)
        {
            RouteData         rd = new RouteData();
            ControllerContext cc = new ControllerContext();//new ControllerContext(new HttpContextWrapper(context), new RouteData(), new MyController());

            cc.HttpContext = new HttpContextWrapper(context);
            cc.RouteData   = new RouteData();
            cc.RouteData.Values.Add("controller", wp.RequestResourceName);
            cc.RouteData.Values.Add("action", "Process");
            //添加Mvc Module数据
            ViewDataDictionary vdd = null;

            if (gd.MvcModuleData != null)
            {
                vdd = new ViewDataDictionary(gd.MvcModuleData);
            }
            else
            {
                vdd = new ViewDataDictionary();
            }
            //添加ViewData
            foreach (var val in gd.Domain(DomainKey.VIEW_LIST))
            {
                if (vdd.ContainsKey(val.Key))
                {
                    vdd[val.Key] = val.Value;
                }
                else
                {
                    vdd.Add(val.Key, val.Value);
                }
            }

            TempDataDictionary tdd = new TempDataDictionary();

            if (string.IsNullOrEmpty(gd.ViewPath))
            {
                throw new Exception("没有获得ViewPath,无法展现页面");
            }
            WMvcView   rv  = new WMvcView(gd.ViewPath);
            TextWriter _tw = new StringWriter();

            try
            {
                ViewContext vc = new ViewContext(cc, rv, vdd, tdd, _tw);
                rv.Render(vc, writer);
            }
            finally
            {
                _tw.Close();
                _tw.Dispose();
                _tw = null;
                rv.Dispose();
            }
        }
Exemplo n.º 6
0
        protected override void FinishedProcess(WebParameter p, GoData d)
        {
            base.FinishedProcess(p, d);
            var logkey = ComFunc.nvl(p.GetValue("logkey"));

            if (logmsg.ContainsKey(logkey))
            {
                var dobj = (FrameDLRObject)logmsg[logkey];
                DebugLog(string.Format("标号{0}微信请求处理记录:\n{1}", logkey, dobj.ToJSONString()), p);
            }
        }
Exemplo n.º 7
0
 protected override void InvokeAction(WebParameter p, GoData d)
 {
     if (IsValid4Invoke(p, d))
     {
         base.InvokeAction(p, d);
     }
     else
     {
         throw new Exception("无效访问,可能原因,缺少访问授权信息或密钥不正确");
     }
 }
Exemplo n.º 8
0
        protected override bool IsValid4Invoke(WebParameter p, GoData d)
        {
            var rtn = base.IsValid4Invoke(p, d);

            if (!rtn)
            {
                return(rtn);
            }

            var ext = Path.GetExtension(CurrentContext.Request.Path).Replace(".", "").ToLower();

            if (ext == "go")
            {
            }

            return(rtn);
        }
Exemplo n.º 9
0
        protected override void SetResponseContent(WebParameter p, GoData d)
        {
            if (d.ResponseData is FrameDLRObject)
            {
                var re = (FrameDLRObject)d.ResponseData;

                var content = ToXml(re);

                if (p.ExtentionObj.weixin.encrypt_type == "aes")
                {
                    var    createTime = re.GetValue("CreateTime") == null ? DateTime.Now : (DateTime)re.GetValue("CreateTime");
                    int    timeStamp  = ToWeixinTime(createTime);
                    Random random     = new Random();
                    string nonce      = random.Next().ToString();

                    WXBizMsgCrypt wxcpt      = new WXBizMsgCrypt(p.ExtentionObj.weixin.token, p.ExtentionObj.weixin.encrypt_key, p.ExtentionObj.weixin.appid);
                    string        xmlEncrypt = "";
                    //加密消息
                    if (wxcpt.EncryptMsg(content, timeStamp.ToString(), nonce, ref xmlEncrypt) == WXBizMsgCrypt.WXBizMsgCryptErrorCode.WXBizMsgCrypt_OK)
                    {
                        content = xmlEncrypt;
                    }
                }

                var msgbytelength = Encoding.UTF8.GetByteCount(content);
                CurrentContext.Response.Headers.Add("Content-Length", msgbytelength + "");
                CurrentContext.Response.ContentType = ResponseHeader_ContentType.xml + ";charset=utf-8";
                CurrentContext.Response.StatusCode  = 200;
                CurrentContext.Response.WriteAsync(content);
            }
            else
            {
                var msgbytelength = Encoding.UTF8.GetByteCount(ComFunc.nvl(d.ResponseData));
                CurrentContext.Response.Headers.Add("Content-Length", msgbytelength + "");
                if (d.ContentType == GoResponseDataType.String)
                {
                    CurrentContext.Response.ContentType = ResponseHeader_ContentType.html + ";charset=utf-8";
                }
                else
                {
                    CurrentContext.Response.ContentType = ResponseHeader_ContentType.xml + ";charset=utf-8";
                }
                CurrentContext.Response.StatusCode = 200;
                CurrentContext.Response.WriteAsync(ComFunc.nvl(d.ResponseData));
            }
        }
Exemplo n.º 10
0
        private bool IsWeixinSignValid(WebParameter p, GoData d)
        {
            var    rtn       = true;
            string token     = p.ExtentionObj.weixin.token;
            string signature = p.ExtentionObj.weixin.signature;
            string timestamp = p.ExtentionObj.weixin.timestamp;
            string nonce     = p.ExtentionObj.weixin.nonce;

            if (string.IsNullOrWhiteSpace(signature) || string.IsNullOrWhiteSpace(timestamp) || string.IsNullOrWhiteSpace(nonce))
            {
                rtn = false;
                var dobj = FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase);
                dobj.ToUserName   = p[DomainKey.POST_DATA, "FromUserName"];
                dobj.FromUserName = p[DomainKey.POST_DATA, "ToUserName"];
                dobj.CreateTime   = DateTime.Now;
                dobj.MsgType      = "text";
                dobj.Content      = "检验无效,微信请求参数不正确";
                dobj.FuncFlag     = 0;
                d.ResponseData    = dobj;
            }
            else
            {
                string[] infos = new string[] { token, timestamp, nonce };
                Array.Sort <string>(infos);
                string info = string.Format("{0}{1}{2}", infos[0], infos[1], infos[2]);
                rtn = string.Compare(signature, GetSha1Hash(info, Encoding.ASCII), true) == 0;
                if (!rtn)
                {
                    var dobj = FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase);
                    dobj.ToUserName   = p[DomainKey.POST_DATA, "FromUserName"];
                    dobj.FromUserName = p[DomainKey.POST_DATA, "ToUserName"];
                    dobj.CreateTime   = DateTime.Now;
                    dobj.MsgType      = "text";
                    dobj.Content      = "检验无效,不是微信访问接口";
                    dobj.FuncFlag     = 0;
                    d.ResponseData    = dobj;
                }
            }

            return(rtn);
        }
Exemplo n.º 11
0
        protected override void LoadConfig(WebParameter p, GoData d)
        {
            base.LoadConfig(p, d);
            bool bvalue = true;

            foreach (var item in MyConfig.GetConfigurationList("Weixin"))
            {
                if (bool.TryParse(ComFunc.nvl(item.Value), out bvalue))
                {
                    p[DomainKey.CONFIG, item.Key] = bool.Parse(ComFunc.nvl(item.Value));
                }
                else if (DateTimeStd.IsDateTime(item.Value))
                {
                    p[DomainKey.CONFIG, item.Key] = DateTimeStd.ParseStd(item.Value).Value;
                }
                else
                {
                    p[DomainKey.CONFIG, item.Key] = ComFunc.nvl(item.Value);
                }
            }
        }
Exemplo n.º 12
0
        protected override void ProcessRequestInfo(WebParameter p, GoData d)
        {
            base.ProcessRequestInfo(p, 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.ExtentionObj.weixin.agentid             = ComFunc.nvl(p[DomainKey.CONFIG, "weixin_AgentId"]);

            p.ExtentionObj.weixinmp                       = FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase);
            p.ExtentionObj.weixinmp.appid                 = ComFunc.nvl(p[DomainKey.CONFIG, "weixinmp_Appid"]);
            p.ExtentionObj.weixinmp.appsecret             = ComFunc.nvl(p[DomainKey.CONFIG, "weixinmp_Appsecret"]);
            p.ExtentionObj.weixinmp.weixinmp_mch_ssl_path = ComFunc.nvl(p[DomainKey.CONFIG, "weixinmp_Mch_SSL_Path"]);
            p.ExtentionObj.weixinmp.weixinmp_mch_ssl_pass = ComFunc.nvl(p[DomainKey.CONFIG, "weixinmp_Mch_SSL_Pass"]);
        }
Exemplo n.º 13
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";
            }
        }
Exemplo n.º 14
0
            /// <summary>
            /// 呼叫本地logic
            /// </summary>
            /// <param name="logic"></param>
            /// <param name="action"></param>
            /// <param name="p"></param>
            /// <param name="d"></param>
            /// <returns></returns>
            private object CallLocalLogic(string logic, string action, WebParameter p, GoData d)
            {
                object od = d;

                GlobalCommon.Proxys["gobusi"].CallModule(ref od, p);
                return(d.ResponseData);
            }
Exemplo n.º 15
0
        protected virtual void SetContent(WebParameter p, GoData d)
        {
            System.Collections.Specialized.NameValueCollection obj = CurrentContext.Request.Headers;
            String agent = ComFunc.nvl(obj["USER-AGENT"]);

            if (d.ResponseData == null)
            {
                throw new Exception("ResponseData is null!");
            }
            if (d.ContentType == GoResponseDataType.Pic_Jpg)
            {
                byte[] b = null;
                if (d.ResponseData is Stream)
                {
                    b = StreamToBytes((Stream)d.ResponseData);
                }
                else
                {
                    b = ((byte[])d.ResponseData);
                }

                CurrentContext.Response.AppendHeader("Content-Length", b.Length + "");
                CurrentContext.Response.ContentType = "image/jpeg";
                CurrentContext.Response.BinaryWrite(b);
            }
            else if (d.ContentType == GoResponseDataType.Pic_Gif)
            {
                byte[] b = null;
                if (d.ResponseData is Stream)
                {
                    b = StreamToBytes((Stream)d.ResponseData);
                }
                else
                {
                    b = ((byte[])d.ResponseData);
                }

                CurrentContext.Response.AppendHeader("Content-Length", b.Length + "");
                CurrentContext.Response.ContentType = "image/gif";
                CurrentContext.Response.BinaryWrite(b);
            }
            else if (d.ContentType == GoResponseDataType.Pic_Bmp)
            {
                byte[] b = null;
                if (d.ResponseData is Stream)
                {
                    b = StreamToBytes((Stream)d.ResponseData);
                }
                else
                {
                    b = ((byte[])d.ResponseData);
                }

                CurrentContext.Response.AppendHeader("Content-Length", b.Length + "");
                CurrentContext.Response.ContentType = "image/bmp";
                CurrentContext.Response.BinaryWrite(b);
            }
            else if (d.ContentType == GoResponseDataType.Pic_png)
            {
                byte[] b = null;
                if (d.ResponseData is Stream)
                {
                    b = StreamToBytes((Stream)d.ResponseData);
                }
                else
                {
                    b = ((byte[])d.ResponseData);
                }

                CurrentContext.Response.AppendHeader("Content-Length", b.Length + "");
                CurrentContext.Response.ContentType = "image/png";
                CurrentContext.Response.BinaryWrite(b);
            }
            else if (d.ContentType == GoResponseDataType.Excel)
            {
                CurrentContext.Response.Buffer  = true;
                CurrentContext.Response.Charset = "UTF-8";
                //CurrentContext.Response.ClearHeaders();
                CurrentContext.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(ComFunc.nvl(d["__download_filename__"]), Encoding.UTF8));
                CurrentContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
                CurrentContext.Response.ContentType     = ResponseHeader_ContentType.xls;
                if (d.ResponseData is byte[])
                {
                    CurrentContext.Response.BinaryWrite((byte[])d.ResponseData);
                }
                else if (d.ResponseData is Stream)
                {
                    CurrentContext.Response.BinaryWrite(StreamToBytes((Stream)d.ResponseData));
                }
                else
                {
                    CurrentContext.Response.Write(d.ResponseData);
                }
                CurrentContext.Response.Flush();
            }
            else if (d.ContentType == GoResponseDataType.Word)
            {
                CurrentContext.Response.Buffer  = true;
                CurrentContext.Response.Charset = "UTF-8";
                //CurrentContext.Response.ClearHeaders();
                CurrentContext.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(ComFunc.nvl(d["__download_filename__"]), Encoding.UTF8));
                CurrentContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
                CurrentContext.Response.ContentType     = ResponseHeader_ContentType.doc;
                if (d.ResponseData is byte[])
                {
                    CurrentContext.Response.BinaryWrite((byte[])d.ResponseData);
                }
                else if (d.ResponseData is Stream)
                {
                    CurrentContext.Response.BinaryWrite(StreamToBytes((Stream)d.ResponseData));
                }
                else
                {
                    CurrentContext.Response.Write(d.ResponseData);
                }
                CurrentContext.Response.Flush();
            }
            else if (d.ContentType == GoResponseDataType.PDF)
            {
                CurrentContext.Response.Buffer  = true;
                CurrentContext.Response.Charset = "UTF-8";
                //CurrentContext.Response.ClearHeaders();
                if (agent != null && agent.IndexOf("MSIE") == -1 && agent.IndexOf("Chrome") == -1 && agent.IndexOf("Opera") == -1)
                {
                    //非IE非Chrom
                    CurrentContext.Response.AppendHeader("Content-Disposition", "attachment;filename=" + ComFunc.nvl(d["__download_filename__"]));
                }
                else
                {
                    CurrentContext.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(ComFunc.nvl(d["__download_filename__"]), Encoding.UTF8));
                }

                CurrentContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
                CurrentContext.Response.ContentType     = ResponseHeader_ContentType.pdf;
                if (d.ResponseData is byte[])
                {
                    CurrentContext.Response.BinaryWrite((byte[])d.ResponseData);
                }
                else if (d.ResponseData is Stream)
                {
                    CurrentContext.Response.BinaryWrite(StreamToBytes((Stream)d.ResponseData));
                }
                else
                {
                    CurrentContext.Response.Write(d.ResponseData);
                }
                CurrentContext.Response.Flush();
            }
            else if (d.ContentType == GoResponseDataType.Json)
            {
                CurrentContext.Response.Charset     = "UTF-8";
                CurrentContext.Response.ContentType = ResponseHeader_ContentType.json;
                if (d.ResponseData is FrameDLRObject)
                {
                    CurrentContext.Response.Write(ComFunc.FormatJSON((FrameDLRObject)d.ResponseData).ToJSONString());
                }
                else
                {
                    CurrentContext.Response.Write(ComFunc.FormatJSON(ComFunc.nvl(d.ResponseData)).ToJSONString());
                }
            }
            else if (d.ContentType == GoResponseDataType.HostView)
            {
                if (d.ResponseData is FrameDLRObject)
                {
                    var dobj = (FrameDLRObject)d.ResponseData;
                    //获取view路径
                    string viewpath = ComFunc.nvl(d.ExtentionObj.hostviewpath);
                    viewpath = viewpath.Replace("~", GlobalCommon.HostCommon.RootPath + HostJsConstants.COMPILED_VIEW_PATH);
                    if (File.Exists(viewpath))
                    {
                        //调用hostview引擎进行渲染
                        HostJsView hjv = (HostJsView)p.ExtentionObj.hostviewengine;
                        hjv.CurrentContext.SetDataModel(dobj.ToDictionary());
                        var html = hjv.Render(File.ReadAllText(viewpath, Encoding.UTF8));

                        CurrentContext.Response.Charset     = "UTF-8";
                        CurrentContext.Response.ContentType = ResponseHeader_ContentType.html;
                        CurrentContext.Response.Write(html);
                    }
                    else
                    {
                        CurrentContext.Response.Write("File Not Found!");
                    }
                }
            }
            else if (d.ContentType == GoResponseDataType.RazorView)
            {
                //Mvc进行视图展示
                StringWriter sw = new StringWriter();
                WMvcView.RenderView(p, d, CurrentContext, sw);
                d.SetValue("ViewHtmlCode", sw.ToString());
                if (!IsWebSocket)
                {
                    CurrentContext.Response.Charset     = "UTF-8";
                    CurrentContext.Response.ContentType = ResponseHeader_ContentType.html;
                    CurrentContext.Response.Write(sw.ToString());
                }
                else
                {
                    CurrentContext.Response.Charset     = "UTF-8";
                    CurrentContext.Response.ContentType = ResponseHeader_ContentType.json;
                    var v      = ComFunc.FormatJSON(sw.ToString());
                    var buffer = new ArraySegment <byte>(Encoding.UTF8.GetBytes(v.ToJSONString()));
                    CurrentSocket.SendAsync(buffer, WebSocketMessageType.Text, true, System.Threading.CancellationToken.None);
                }
            }
            else
            {
                CurrentContext.Response.Write(d.ResponseData);
            }
        }
Exemplo n.º 16
0
 protected override bool IsValid4Invoke(WebParameter p, GoData d)
 {
     //企业微信的来源校验不同
     return(true);
 }
Exemplo n.º 17
0
        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";
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// 业务逻辑执行之前的检核判定,如果为true,则执行业务逻辑模块,否则不执行
 /// </summary>
 /// <param name="p"></param>
 /// <param name="d"></param>
 /// <returns></returns>
 protected virtual bool IsValid4Invoke(WebParameter p, GoData d)
 {
     return(true);
 }
Exemplo n.º 19
0
 protected override void ProcessRequestInfo(WebParameter p, GoData d)
 {
     base.ProcessRequestInfo(p, d); ProcessRequestInfoWeixin(p, d);
 }