您好,登录后才能下订单哦!
//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),图片(p_w_picpath),语音等。
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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。