public void TestGetTextMessage() { string content = @"<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>1348831860</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[this is a test]]></Content> <MsgId>1234567890123456</MsgId> </xml>"; HttpPostRequest request = new HttpPostRequest(content); 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); }