public ActionResult Wechat() { if (Request.HttpMethod.ToLower() == "post") { StreamReader str = new StreamReader(Request.InputStream, System.Text.Encoding.UTF8); XmlDocument xml = new XmlDocument(); xml.Load(str); XmlNode xn = xml.SelectSingleNode("xml"); //返回标签名为“xml”的所有节点,返回的是数组 string xmlDoc = ""; for (int i = 0; i < xn.ChildNodes.Count; i++) { xmlDoc += "\r\n" + xn.ChildNodes[i].Name + ":" + xn.ChildNodes[i].InnerText; } ToUserName = xn.SelectSingleNode("ToUserName").InnerText; //获取用户的OpenID; FromUserName = xn.SelectSingleNode("FromUserName").InnerText; //获取用户的OpenID MsgType = xn.SelectSingleNode("MsgType").InnerText; //获得用户发来的信息类型:text,image,location,link,event等 if (!string.IsNullOrWhiteSpace(MsgType)) { switch (MsgType.ToLower()) { case "text": myContent = xn.SelectSingleNode("Content").InnerText; if (myContent.Substring(0, 1).ToLower() == "v") { ToWXStr = ReplayText(myContent); } else { ToWXStr = Normal_Text(myContent); } break; case "event": switch (xn.SelectSingleNode("Event").InnerText) { case "subscribe": ToWXStr = ReplayText(SubscribeEvent()); break; case "unsubscribe": break; case "click": string EventKey = xn.SelectSingleNode("EventKey").InnerText; ToWXStr = ReplayText("您好,我们的攻城狮们正在研发此功能,请期待!"); break; } break; default: ToWXStr = ReplayText("您好,您的消息我们已经收到,客服看到后会在第一时间内给您回复!"); break; } } } else { string echoStr = Request.QueryString["echoStr"]; if (CheckSignature()) { if (!string.IsNullOrEmpty(echoStr)) { return(Content(echoStr)); } } } return(Content(ToWXStr, "text/xml")); }