asp.net C# 微信消息自动回复 asp.net版
//asp.net C# 微信消息自动回复 asp.net版
protected void Page_Load(object sender, EventArgs e)
{
if (Request.HttpMethod == "POST")
{
string weixin = "";
weixin = PostInput();//获取xml数据
if (!string.IsNullOrEmpty(weixin))
{
ResponseMsg(weixin);////调用消息适配器
}
}
}
private string PostInput()
{
Stream s = System.Web.HttpContext.Current.Request.InputStream;
byte[] b = new byte[s.Length];
s.Read(b, 0, (int)s.Length);
return Encoding.UTF8.GetString(b);
}
private void ResponseMsg(string weixin)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(weixin);//读取xml字符串
XmlElement root = doc.DocumentElement;
ExmlMsg xmlMsg = GetExmlMsg(root);
string messageType = xmlMsg.MsgType;//获取收到的消息类型。文本(text),图片(image),语音等。
try
{
//textCase1(xmlMsg);
switch (messageType)
{
//当消息为文本时
case "text":
textCase(xmlMsg);
break;
case "event":
break;
}
Response.End();
}
private void textCase1(ExmlMsg xmlMsg)
{
string resxml = string.Format(ReplyType.Message_Text,
xmlMsg.FromUserName,
xmlMsg.ToUserName,
DateTime.Now.Ticks,
xmlMsg.MsgType);
Response.Write(resxml);
}
若有疑问,请联系QQ:250063085
本文出自 “纯纯的暧昧” 博客,转载请与作者联系!