/// <summary> /// 发送文字消息 /// </summary> /// <param name="wx">获取的收发者信息 /// <param name="content">内容 /// <returns></returns> private string sendTextMessage(WeiXinTextMessage wx, string content) { XmlDocument xml = new XmlDocument(); xml.Load(AppDomain.CurrentDomain.BaseDirectory + "\\MsgFolder\\TextMsg.xml"); xml.SelectSingleNode("xml").SelectSingleNode("ToUserName").InnerText = xml.SelectSingleNode("xml").SelectSingleNode("ToUserName").InnerText.Replace("toUser", wx.FromUserName); xml.SelectSingleNode("xml").SelectSingleNode("FromUserName").InnerText = xml.SelectSingleNode("xml").SelectSingleNode("FromUserName").InnerText.Replace("fromUser", wx.ToUserName); xml.SelectSingleNode("xml").SelectSingleNode("CreateTime").InnerText = ConvertDateTimeInt(DateTime.Now).ToString(); xml.SelectSingleNode("xml").SelectSingleNode("MsgType").InnerText = xml.SelectSingleNode("xml").SelectSingleNode("MsgType").InnerText.Replace("MsgType", wx.MsgType); xml.SelectSingleNode("xml").SelectSingleNode("Content").InnerText = xml.SelectSingleNode("xml").SelectSingleNode("Content").InnerText.Replace("Content", content); string res = xml.InnerXml; return res; }
/// <summary> /// 获取微信请求消息 /// </summary> /// <returns></returns> public WeiXinTextMessage GetWXMessage() { WeiXinTextMessage wxMsg = new WeiXinTextMessage(); StreamReader str = new StreamReader(Request.InputStream, Encoding.UTF8); XmlDocument xml = new XmlDocument(); xml.Load(str); wxMsg.ToUserName = xml.SelectSingleNode("xml").SelectSingleNode("ToUserName").InnerText; wxMsg.FromUserName = xml.SelectSingleNode("xml").SelectSingleNode("FromUserName").InnerText; wxMsg.MsgType = xml.SelectSingleNode("xml").SelectSingleNode("MsgType").InnerText; if (wxMsg.MsgType.Trim() == "text") { wxMsg.Content = xml.SelectSingleNode("xml").SelectSingleNode("Content").InnerText; } if (wxMsg.MsgType.Trim() == "event") { wxMsg.EventName = xml.SelectSingleNode("xml").SelectSingleNode("Event").InnerText; } return wxMsg; }