解析传递过来的XML,判断Event 为subscribe且EventKey不为空且包含qrscene_ 或者Event 为SCAN时,
1、获取场景号
int scanId = int.Parse(TXTMessage_T.EventKey.Replace("qrscene_", ""));
2、构建返回xml,消息发送方和接收方交换
XML = new XmlDocument();
XmlElement elem;
XmlCDataSection xc;
XmlNodeList nodelist;
XmlNode node;
///构造发送消息给用户XML节点内容
elem = XML.CreateElement("xml");
XML.AppendChild(elem);
nodelist = XML.SelectNodes("descendant::xml");
node = nodelist.Item(nodelist.Count - 1);
///把原来的消息发送者和接收者兑换
elem = XML.CreateElement("ToUserName");
xc = XML.CreateCDataSection(TXTMessage_T.FromUserName);
elem.AppendChild(xc);
node.AppendChild(elem);
elem = XML.CreateElement("FromUserName");
xc = XML.CreateCDataSection(TXTMessage_T.ToUserName);
elem.AppendChild(xc);
node.AppendChild(elem);
///时间转化为长整型
elem = XML.CreateElement("CreateTime");
elem.InnerText = Methods.FanliTime().ToString();
node.AppendChild(elem);
///构建图文消息XML
elem = XML.CreateElement("MsgType");
///图文消息
xc = XML.CreateCDataSection("news");
elem.AppendChild(xc);
node.AppendChild(elem);
///图文消息数量 最多为10
elem = XML.CreateElement("ArticleCount");
elem.InnerText = "1";
node.AppendChild(elem);
///图文消息内容
elem = XML.CreateElement("Articles");
node.AppendChild(elem);
nodelist = XML.SelectNodes("xml/Articles");
node = nodelist.Item(nodelist.Count - 1);
///单个图文消息item
elem = XML.CreateElement("item");
node.AppendChild(elem);
nodelist = XML.SelectNodes("xml/Articles/item");
node = nodelist.Item(nodelist.Count - 1);
///标题
elem = XML.CreateElement("Title");
xc = XML.CreateCDataSection(title);
elem.AppendChild(xc);
node.AppendChild(elem);
///描述
elem = XML.CreateElement("Description");
xc = XML.CreateCDataSection(title);
elem.AppendChild(xc);
node.AppendChild(elem);
///图片
elem = XML.CreateElement("PicUrl");
xc = XML.CreateCDataSection(Img);
elem.AppendChild(xc);
node.AppendChild(elem);
//链接
elem = XML.CreateElement("Url");
xc = XML.CreateCDataSection(scanUrl);
elem.AppendChild(xc);
node.AppendChild(elem);
//返回xml
System.Web.HttpContext.Current.Response.Write(XML.OuterXml);