//asp.net C# 微信消息自動(dòng)回復(fù) asp.net版
protected void Page_Load(object sender, EventArgs e)
{
if (Request.HttpMethod == "POST")
{
string weixin = "";
weixin = PostInput();//獲取xml數(shù)據(jù)
if (!string.IsNullOrEmpty(weixin))
{
ResponseMsg(weixin);////調(diào)用消息適配器
}
}
}
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),語(yǔ)音等。
try
{
//textCase1(xmlMsg);
switch (messageType)
{
//當(dāng)消息為文本時(shí)
case "text":
textCase(xmlMsg);
break;
case "event":
}
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);
}
若有疑問(wèn),請(qǐng)聯(lián)系QQ:250063085
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。