這篇文章主要介紹.NET微信開發(fā)如何實現(xiàn)自動內(nèi)容回復(fù)功能,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!

目前創(chuàng)新互聯(lián)公司已為成百上千的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)頁空間、網(wǎng)站運營、企業(yè)網(wǎng)站設(shè)計、甘德網(wǎng)站維護(hù)等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
ASP.NET開發(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
{
/// <summary>
/// v 的摘要說明
/// </summary>
public class v : IHttpHandler
{
/// <summary>
/// 開發(fā)者 驗證 模塊
/// </summary>
/// <param name="context"></param>
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";
//如果 是 驗證 則 直接 退出
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請求
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());//"<xml><description><![CDATA[木子屋:http://www.mzwu.com/]]></description></xml>");
//菜單 或者 用戶文本輸入
if (m.MsgType == MessageType.Text || (m.MsgType == MessageType.Event && m.InnerToXmlText().IndexOf("subscribe") < 0))
{
//讀取
string rr = "";
if (m.MsgType == MessageType.Text)
{
rr = xmlDoc.SelectSingleNode("//Content").FirstChild.InnerText.ToLower().Trim();
}
else
{
rr = xmlDoc.SelectSingleNode("//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;
}
}
}
}這段代碼中具有開發(fā)者驗證的功能,同時也考慮到了 由菜單發(fā)送到平臺的文本的接收和響應(yīng)。
以上是“.NET微信開發(fā)如何實現(xiàn)自動內(nèi)容回復(fù)功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
名稱欄目:.NET微信開發(fā)如何實現(xiàn)自動內(nèi)容回復(fù)功能
網(wǎng)頁網(wǎng)址:http://chinadenli.net/article32/ipjdpc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號、關(guān)鍵詞優(yōu)化、手機(jī)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計、外貿(mào)建站、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)