码迷,mamicode.com
首页 > 其他好文 > 详细

扫码带参数二维码扫码关注

时间:2016-04-06 13:23:48      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

解析传递过来的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);

 

扫码带参数二维码扫码关注

标签:

原文地址:http://www.cnblogs.com/l36i90u/p/5358466.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!