62,041
社区成员
发帖
与我相关
我的任务
分享
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string postStr = "";
if (context.Request.HttpMethod.ToLower() == "post")
{
System.IO.Stream s = System.Web.HttpContext.Current.Request.InputStream;
byte[] b = new byte[s.Length];
s.Read(b, 0, (int)s.Length);
postStr = System.Text.Encoding.UTF8.GetString(b);
if (!string.IsNullOrEmpty(postStr))
{
ResponseMsg(postStr);
}
}
}
public void ResponseMsg(string weixinXML)
{
//回复消息的部分:你的代码写在这里
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(weixinXML);
System.Xml.XmlNodeList list = doc.GetElementsByTagName("xml");
System.Xml.XmlNode xn = list[0];
string FromUserName = xn.SelectSingleNode("//FromUserName").InnerText;
string ToUserName = xn.SelectSingleNode("//ToUserName").InnerText;
string content ="";
content = xn.SelectSingleNode("//Content").InnerText;
if (content.Equals("nihao"))
{
content = "你好";
}
else if(content.Equals("hello"))
{
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 + "]]></Content>";
strresponse = strresponse + "<FuncFlag>0</FuncFlag>";
strresponse = strresponse + "</xml>";
HttpContext.Current.Response.Write(strresponse);
}
public void ResponseMsg(string weixinXML)
{
//回复消息的部分:你的代码写在这里
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(weixinXML);
System.Xml.XmlNodeList list = doc.GetElementsByTagName("xml");
System.Xml.XmlNode xn = list[0];
string FromUserName = xn.SelectSingleNode("//FromUserName").InnerText;
string ToUserName = xn.SelectSingleNode("//ToUserName").InnerText;
string content = "";
content = xn.SelectSingleNode("//Content").InnerText;
if (content.ToLower().Equals("hello2bizuser"))
{
content = "感谢您关注微信小助手";
}
if (content.Equals("nihao"))
{
content = "你好";
}
else if(content.Equals("hello"))
{
content = "您好,您已经测试成功了";
}
else
{
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 + "]]></Content>";
strresponse = strresponse + "<FuncFlag>1</FuncFlag>";
strresponse = strresponse + "</xml>";
HttpContext.Current.Response.Write(strresponse);
}
请问我这代码哪里出错了??每次点击关注的时候,都不行。。。都收不到消息,咋回事?