ASP.NET微信公共平台
实现微信回复
/// <summary>
/// 返回信息结果(微信信息返回)
/// </summary>
/// <param name="weixinXML"></param>
private void ResponseMsg(string weixinXML)
{
//回复消息的部分:你的代码写在这里
System.Xml.XmlDocument doc = new XmlDocument();
doc.LoadXml(weixinXML);
XmlNodeList list = doc.GetElementsByTagName("xml");
XmlNode xn = list[0];
string FromUserName = xn.SelectSingleNode("//FromUserName").InnerText;
string ToUserName = xn.SelectSingleNode("//ToUserName").InnerText;
WriteLog("测试1");
string MsgType = xn.SelectSingleNode("//MsgType").InnerText;
string content = "", menu = "";
if (MsgType.Equals("event"))
{
content = "欢迎你的加入!";
}
else
{
content = xn.SelectSingleNode("//Content").InnerText;
}
WriteLog("测试2");
//content就是你要回复的内容,此间的业务逻辑可以自己定义
string strresponse = "<xml>";
strresponse = strresponse "<ToUserName><![CDATA[" FromUserName "]]></ToUserName>";
strresponse = strresponse "<FromUserName><![CDATA[" ToUserName "]]></FromUserName>";
strresponse = strresponse "<CreateTime>" DateTime.Now.Ticks.ToString() "</CreateTime>";
strresponse = strresponse "<MsgType><![CDATA[text]]></MsgType>";
strresponse = strresponse "<Content><![CDATA[" content menu "]]></Content>";
strresponse = strresponse "<FuncFlag>0<FuncFlag>";
strresponse = strresponse "</xml>";
WriteLog("postStr:" content);
Response.Write(strresponse);
WriteLog("测试3");
}
评论