예제 #1
0
        public string DealWith(HttpRequestBase Request, MenuItem Root)
        {
            mRoot = Root;
            string token     = TOKEN;
            string signature = (Request.QueryString.AllKeys.Count(r => r == "signature") > 0) ? Request.QueryString["signature"].ToString() : "";
            string timestamp = (Request.QueryString.AllKeys.Count(r => r == "timestamp") > 0) ? Request.QueryString["timestamp"].ToString() : "";
            string nonce     = (Request.QueryString.AllKeys.Count(r => r == "nonce") > 0) ? Request.QueryString["nonce"].ToString() : "";
            string echostr   = (Request.QueryString.AllKeys.Count(r => r == "echostr") > 0) ? Request.QueryString["echostr"].ToString() : "";

            if (CheckSignature(signature, timestamp, nonce, token))
            {
                string responseContent;
                if (Request.HttpMethod.ToUpper() == "POST")
                {
                    //处理微信发送的数据
                    using (Stream stream = Request.InputStream)
                    {
                        Byte[] postBytes = new Byte[stream.Length];
                        stream.Read(postBytes, 0, (Int32)stream.Length);
                        string postString = Encoding.UTF8.GetString(postBytes);
                        responseContent = WXMessageHelper.ReturnMessage(postString);
                    }
                }
                else
                {
                    responseContent = echostr;
                }

                logger.Log(LogLevel.Trace, "Response[" + responseContent + "]");
                return(responseContent);
            }
            return("");
        }
예제 #2
0
 public WXHelper(string token, string appID, string appSecret, string accessToken)
 {
     TOKEN       = token;
     APPID       = appID;
     APPSECRET   = appSecret;
     ACCESSTOKEN = accessToken;
     WXMessageHelper.WelComeDG   WCDG = new WXMessageHelper.WelComeDG(WelComeFun);
     WXMessageHelper.MenuDG      MDG  = new WXMessageHelper.MenuDG(MenuFun);
     WXMessageHelper.AutoReplyDG ARDG = new WXMessageHelper.AutoReplyDG(AutoReplyFun);
     WXMessageHelper.SetDelegate(WCDG, MDG, ARDG);
 }
예제 #3
0
        //返回消息
        public static string ReturnMessage(string postStr)
        {
            string      responseContent = "";
            XmlDocument xmldoc          = new XmlDocument();

            xmldoc.Load(new MemoryStream(Encoding.GetEncoding("GB2312").GetBytes(postStr)));
            XmlNode MsgType = xmldoc.SelectSingleNode("/xml/MsgType");

            if (MsgType != null)
            {
                logger.Log(LogLevel.Trace, MsgType.InnerText);
                switch (MsgType.InnerText)
                {
                case "event":
                {
                    //事件处理
                    responseContent = WXMessageHelper.EventHandle(xmldoc);
                    break;
                }

                case "text":
                {
                    //接受文本消息处理
                    responseContent = WXMessageHelper.TextHandle(xmldoc);
                    break;
                }

                case "image":
                {
                    //接受图片消息处理
                    responseContent = WXMessageHelper.ImageHandle(xmldoc);
                    break;
                }

                case "voice":
                {
                    //接受语音消息处理
                    responseContent = WXMessageHelper.VoiceHandle(xmldoc);
                    break;
                }

                case "video":
                {
                    //接受视频消息处理
                    responseContent = WXMessageHelper.VideoHandle(xmldoc);
                    break;
                }

                default:
                    break;
                }
            }
            return(responseContent);
        }