Example #1
0
        public void TestCheckSignature()
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("name", "jun");
            dic.Add("signature", "babb2bb874eb3f8304f6d69987bf7b62c2837e18");
            dic.Add("timestamp", "1341554");
            dic.Add("nonce", "523");
            dic.Add("echostr", "good");
            HttpGetRequest request = new HttpGetRequest(dic);

            WeixinService service = new WeixinService(request);
            string responseStr = service.GetResponse();
            return;
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string responseStr = string.Empty;

            if (context.Request.HttpMethod.ToUpper().Equals("GET"))
            {
                Dictionary<string, string> dic = new Dictionary<string, string>();
                string signature = context.Request["signature"];
                string timestamp = context.Request["timestamp"];
                string nonce = context.Request["nonce"];
                string echostr = context.Request["echostr"];

                dic.Add("signature", signature);
                dic.Add("timestamp", timestamp);
                dic.Add("nonce", nonce);
                dic.Add("echostr", echostr);

                HttpGetRequest request = new HttpGetRequest(dic);
                WeixinService service = new WeixinService(request);
                responseStr = service.GetResponse();
            }
            else
                if (context.Request.HttpMethod.ToUpper().Equals("POST"))
                {
                    using (Stream s = context.Request.InputStream)
                    {
                        using (StreamReader reader = new StreamReader(s, Encoding.UTF8))
                        {
                            string content = reader.ReadToEnd();

                            HttpPostRequest request = new HttpPostRequest(content);
                            WeixinService service = new WeixinService(request);
                            responseStr = service.GetResponse();
                        }
                    }
                }

            context.Response.Write(responseStr);
        }