新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
.NET微信開(kāi)發(fā)如何實(shí)現(xiàn)自動(dòng)內(nèi)容回復(fù)功能-創(chuàng)新互聯(lián)
這篇文章主要介紹.NET微信開(kāi)發(fā)如何實(shí)現(xiàn)自動(dòng)內(nèi)容回復(fù)功能,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
ASP.NET開(kāi)發(fā)的 接收微信消息和響應(yīng)用戶消息代碼如下:
文件名 : v.ashx
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Xml; using Td.Weixin.Public.Common; using Td.Weixin.Public.Message; namespace WeiWeiXin.Net6 { ////// v 的摘要說(shuō)明 /// public class v : IHttpHandler { ////// 開(kāi)發(fā)者 驗(yàn)證 模塊 /// /// public bool ProcessRequest2(HttpContext context) { context.Response.ContentType = "text/plain"; // context.Response.Write("Hello World"); try { string echoStr = context.Request["echoStr"]; if (!string.IsNullOrEmpty(echoStr)) { context.Response.Write(echoStr); return true; } else { // context.Response.Write("end"); // context.Response.End(); } } catch (Exception e) { // context.Response.Write("end" + e.Message + e.ToString()); // context.Response.End(); } return false; } public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //如果 是 驗(yàn)證 則 直接 退出 if (ProcessRequest2(context)) return; context.Response.ContentType = "text/plain"; var m = ReceiveMessage.ParseFromContext(); if (m == null) return; //被關(guān)注 if (m.MsgType == MessageType.Event && m.InnerToXmlText().IndexOf("subscribe") >= 0) { //發(fā)送AIML請(qǐng)求 var r2 = m.GetTextResponse(); string result = "[微笑]歡迎關(guān)注"; r2.Data = (TextMsgData)result; r2.Response(); return; } //數(shù)據(jù)解析 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(m.ToXmlText());//""); //菜單 或者 用戶文本輸入 if (m.MsgType == MessageType.Text || (m.MsgType == MessageType.Event && m.InnerToXmlText().IndexOf("subscribe") < 0)) { //讀取 string rr = ""; if (m.MsgType == MessageType.Text) { rr = xmlDoc.SelectSingleNode("http://Content").FirstChild.InnerText.ToLower().Trim(); } else { rr = xmlDoc.SelectSingleNode("http://EventKey").FirstChild.InnerText.ToLower().Trim(); } //發(fā)送 var r2 = m.GetTextResponse(); string result = "歡迎使用,您發(fā)送的是:" +rr;// r2.Data = (TextMsgData)result; r2.Response(); return; } } public bool IsReusable { get { return false; } } } }
這段代碼中具有開(kāi)發(fā)者驗(yàn)證的功能,同時(shí)也考慮到了 由菜單發(fā)送到平臺(tái)的文本的接收和響應(yīng)。
以上是“.NET微信開(kāi)發(fā)如何實(shí)現(xiàn)自動(dòng)內(nèi)容回復(fù)功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
網(wǎng)站標(biāo)題:.NET微信開(kāi)發(fā)如何實(shí)現(xiàn)自動(dòng)內(nèi)容回復(fù)功能-創(chuàng)新互聯(lián)
當(dāng)前地址:http://fisionsoft.com.cn/article/dhpjeh.html