您好,登錄后才能下訂單哦!
//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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。