Пример #1
0
        public void ProcessRequest(System.Web.HttpContext context)
        {
            System.Web.HttpRequest request = context.Request;
            string weixinToken             = SettingsManager.GetMasterSettings(false).WeixinToken;
            string signature = request["signature"];
            string nonce     = request["nonce"];
            string timestamp = request["timestamp"];
            string s         = request["echostr"];

            if (request.HttpMethod == "GET")
            {
                if (CheckSignature.Check(signature, timestamp, nonce, weixinToken))
                {
                    context.Response.Write(s);
                }
                else
                {
                    context.Response.Write("");
                }
                context.Response.End();
                return;
            }
            try
            {
                CustomMsgHandler customMsgHandler = new CustomMsgHandler(request.InputStream);
                customMsgHandler.Execute();
                Globals.Debuglog(customMsgHandler.RequestDocument.ToString(), "_Debuglog.txt");
                context.Response.Write(customMsgHandler.ResponseDocument);
            }
            catch (System.Exception ex)
            {
                Globals.Debuglog(ex.Message, "_Debuglog.txt");
            }
        }
Пример #2
0
        public void ProcessRequest(HttpContext context)
        {
            NameValueCollection nameValueCollection = new NameValueCollection
            {
                context.Request.Form,
                context.Request.QueryString
            };
            HttpRequest request     = context.Request;
            string      weixinToken = SettingsManager.GetMasterSettings().WeixinToken;
            string      signature   = request["signature"];
            string      nonce       = request["nonce"];
            string      timestamp   = request["timestamp"];
            string      s           = request["echostr"];

            if (request.HttpMethod == "GET")
            {
                if (Hishop.Weixin.MP.Util.CheckSignature.Check(signature, timestamp, nonce, weixinToken))
                {
                    context.Response.Write(s);
                }
                else
                {
                    context.Response.Write("");
                }
                context.Response.End();
            }
            else
            {
                try
                {
                    XDocument xDocument = null;
                    if (this.NewWXHandler(request, out xDocument))
                    {
                        this.SaveMenuClick(xDocument);
                    }
                    else
                    {
                        this.SaveMenuClick(xDocument);
                        CustomMsgHandler customMsgHandler = new CustomMsgHandler(xDocument.ToString());
                        customMsgHandler.Execute();
                        context.Response.Write(customMsgHandler.ResponseDocument);
                    }
                }
                catch (Exception)
                {
                }
            }
        }
Пример #3
0
        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request     = context.Request;
            string      weixinToken = SettingsManager.GetMasterSettings(false).WeixinToken;
            string      signature   = request["signature"];
            string      nonce       = request["nonce"];
            string      timestamp   = request["timestamp"];
            string      s           = request["echostr"];


            if (request.HttpMethod == "GET")
            {
                if (CheckSignature.Check(signature, timestamp, nonce, weixinToken))
                {
                    context.Response.Write(s);
                }
                else
                {
                    context.Response.Write("");
                }
                context.Response.End();
            }
            else
            {
                try
                {
                    StreamReader stream = new StreamReader(request.InputStream);
                    string       xml    = stream.ReadToEnd();
                    Utils.LogWriter.SaveLog("wx xml:" + xml);

                    CustomMsgHandler handler = new CustomMsgHandler(xml);

                    handler.Execute();

                    //Utils.LogWriter.SaveLog("wx ResponseDocument:" + handler.ResponseDocument);

                    context.Response.Write(handler.ResponseDocument);
                }
                catch (Exception ex)
                {
                    Utils.LogWriter.SaveLog("wx:" + ex.Message);
                }
            }
        }
Пример #4
0
        public void ProcessRequest(System.Web.HttpContext context)
        {
            System.Web.HttpRequest request = context.Request;
            string weixinToken             = SettingsManager.GetMasterSettings(false).WeixinToken;
            string signature = request["signature"];
            string nonce     = request["nonce"];
            string timestamp = request["timestamp"];
            string s         = request["echostr"];

            if (request.HttpMethod == "GET")
            {
                if (CheckSignature.Check(signature, timestamp, nonce, weixinToken))
                {
                    context.Response.Write(s);
                }
                else
                {
                    context.Response.Write("");
                }
                context.Response.End();
            }
            else
            {
                try
                {
                    CustomMsgHandler handler = new CustomMsgHandler(request.InputStream);
                    handler.Execute();
                    context.Response.Write(handler.ResponseDocument);
                }
                catch (System.Exception exception)
                {
                    System.IO.StreamWriter writer = System.IO.File.AppendText(context.Server.MapPath("error.txt"));
                    writer.WriteLine(exception.Message);
                    writer.WriteLine(exception.StackTrace);
                    writer.WriteLine(System.DateTime.Now);
                    writer.Flush();
                    writer.Close();
                }
            }
        }
Пример #5
0
        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request     = context.Request;
            string      weixinToken = SettingsManager.GetMasterSettings(false).WeixinToken;
            string      signature   = request["signature"];
            string      nonce       = request["nonce"];
            string      timestamp   = request["timestamp"];
            string      s           = request["echostr"];

            if (request.HttpMethod == "GET")
            {
                if (CheckSignature.Check(signature, timestamp, nonce, weixinToken))
                {
                    context.Response.Write(s);
                }
                else
                {
                    context.Response.Write("");
                }
                context.Response.End();
            }
            else
            {
                try
                {
                    CustomMsgHandler handler = new CustomMsgHandler(request.InputStream);
                    handler.Execute();
                    Globals.Debuglog(handler.RequestDocument.ToString(), "_Debuglog.txt");
                    context.Response.Write(handler.ResponseDocument);
                }
                catch (Exception exception)
                {
                    Globals.Debuglog(exception.Message, "_Debuglog.txt");

                    //                 Hidistro.UI.Web.API.CustomMsgHandler.OnTextRequest(TextRequest textRequest)
                    //在 Hishop.Weixin.MP.Handler.RequestHandler.Execute()
                    //在 Hidistro.UI.Web.API.wx.ProcessRequest(HttpContext context)
                }
            }
        }
Пример #6
0
 public void ProcessRequest(HttpContext context)
 {
     HttpRequest request = context.Request;
     string weixinToken = SettingsManager.GetMasterSettings(false).WeixinToken;
     string signature = request["signature"];
     string nonce = request["nonce"];
     string timestamp = request["timestamp"];
     string s = request["echostr"];
     if (request.HttpMethod == "GET")
     {
         if (CheckSignature.Check(signature, timestamp, nonce, weixinToken))
         {
             context.Response.Write(s);
         }
         else
         {
             context.Response.Write("");
         }
         context.Response.End();
     }
     else
     {
         try
         {
             CustomMsgHandler handler = new CustomMsgHandler(request.InputStream);
             handler.Execute();
             context.Response.Write(handler.ResponseDocument);
         }
         catch (Exception exception)
         {
             StreamWriter writer = File.AppendText(context.Server.MapPath("error.txt"));
             writer.WriteLine(exception.Message);
             writer.WriteLine(exception.StackTrace);
             writer.WriteLine(DateTime.Now);
             writer.Flush();
             writer.Close();
         }
     }
 }
Пример #7
0
        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request = context.Request;

            //string weixinToken = SettingsManager.GetMasterSettings(false).WeixinToken;
            Chenduo.Model.sf_website website;
            string wid = request["wid"];

            if (string.IsNullOrEmpty(wid))
            {
                context.Response.Write("参数非法");
                return;
            }

            website = new Chenduo.BLL.sf_website().GetModelByWid(wid);
            if (string.IsNullOrEmpty(website.token_value))
            {
                context.Response.Write("不存在该微信号");
                return;
            }

            string signature = request["signature"];
            string nonce     = request["nonce"];
            string timestamp = request["timestamp"];
            string s         = request["echostr"];

            if (request.HttpMethod == "GET")
            {
                if (CheckSignature.Check(signature, timestamp, nonce, website.token_value))
                {
                    context.Response.Write(s);//返回随机字符串则表示验证通过
                }
                else
                {
                    context.Response.Write("failed:" + signature + ",token:" + website.token_value + " " + CheckSignature.GetSignature(timestamp, nonce, website.token_value) +
                                           "。如果你在浏览器中看到这句话,说明此地址可以被作为微信公众账号后台的Url,请注意保持Token一致。");
                }
                context.Response.End();
            }
            else
            {
                try
                {
                    CustomMsgHandler handler = new CustomMsgHandler(request.InputStream);
                    handler.wid = wid;

                    //测试时可开启此记录,帮助跟踪数据
                    if (HiConfiguration.LOG_LEVENL >= 3)
                    {
                        handler.RequestDocument.Save(context.Server.MapPath("~/logs/" + DateTime.Now.Ticks + "_Request_" +
                                                                            handler.RequestMessage.FromUserName + ".txt"));
                    }
                    handler.Execute();

                    if (handler.ResponseDocument != null && HiConfiguration.LOG_LEVENL >= 3)
                    {
                        handler.ResponseDocument.Save(context.Server.MapPath("~/logs/" + DateTime.Now.Ticks + "_Response_" +
                                                                             handler.ResponseMessage.ToUserName + ".txt"));
                    }
                    context.Response.Write(handler.ResponseDocument == null ? string.Empty : handler.ResponseDocument.ToString());
                }
                catch (Exception exception)
                {
                    StreamWriter writer = File.AppendText(context.Server.MapPath("error.txt"));
                    writer.WriteLine(exception.Message);
                    writer.WriteLine(exception.StackTrace);
                    writer.WriteLine(DateTime.Now);
                    writer.Flush();
                    writer.Close();
                }
            }
        }