佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > 微信公眾平臺開發(fā)之發(fā)送文本消息.Net代碼解析

微信公眾平臺開發(fā)之發(fā)送文本消息.Net代碼解析

熱門標簽:電子圍欄 硅谷的囚徒呼叫中心 智能手機 呼叫中心 解決方案 地方門戶網(wǎng)站 服務(wù)器配置 蘋果

.Net實現(xiàn)微信公共服務(wù)平臺開發(fā)中的發(fā)送文本消息功能,具體內(nèi)容如下

首先建立一個微信消息類。 

 class wxmessage 
 { 
  public string FromUserName { get; set; } 
  public string ToUserName { get; set; } 
  public string MsgType { get; set; } 
  public string EventName { get; set; } 
  public string Content { get; set; }
  public string EventKey { get; set; } 
 } 

 后臺代碼如下: 

protected void Page_Load(object sender, EventArgs e)
  {
   wxmessage wx = GetWxMessage();
   string res = "";

   if (!string.IsNullOrEmpty(wx.EventName)  wx.EventName.Trim() == "subscribe")
   {//剛關(guān)注時的時間,用于歡迎詞
    string content = "";
    content = "/:rose歡迎北京永杰友信科技有限公司/:rose\n直接回復(fù)“你好”";
    res = sendTextMessage(wx, content);
   }
   else
   {
    if (wx.MsgType == "text"  wx.Content == "你好")
    {
     res = sendTextMessage(wx, "你好,歡迎使用北京永杰友信科技有限公司公共微信平臺!");
    }
    else
    {
     res = sendTextMessage(wx, "你好,未能識別消息!");
    }
   }

   Response.Write(res);
  }

 private wxmessage GetWxMessage()
  {
   wxmessage wx = new wxmessage();
   StreamReader str = new StreamReader(Request.InputStream, System.Text.Encoding.UTF8);
   XmlDocument xml = new XmlDocument();
   xml.Load(str);
   wx.ToUserName = xml.SelectSingleNode("xml").SelectSingleNode("ToUserName").InnerText;
   wx.FromUserName = xml.SelectSingleNode("xml").SelectSingleNode("FromUserName").InnerText;
   wx.MsgType = xml.SelectSingleNode("xml").SelectSingleNode("MsgType").InnerText;
   if (wx.MsgType.Trim() == "text")
   {
    wx.Content = xml.SelectSingleNode("xml").SelectSingleNode("Content").InnerText;
   }
   if (wx.MsgType.Trim() == "event")
   {
    wx.EventName = xml.SelectSingleNode("xml").SelectSingleNode("Event").InnerText;
   }

   
   return wx;
  }

/// 
  /// 發(fā)送文字消息 
  /// 
  /// 獲取的收發(fā)者信息 
  /// 內(nèi)容 
  /// 
  private string sendTextMessage(wxmessage wx, string content)
  {
   string res = string.Format(@" ",
    wx.FromUserName, wx.ToUserName, DateTime.Now, content);
   return res;
  }

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • 微信公眾平臺開發(fā)之地理位置.Net代碼解析
  • 微信公眾平臺開發(fā)之發(fā)送圖文消息.Net代碼解析
  • 微信公眾平臺開發(fā)之自定義菜單.Net代碼解析
  • .Net微信開發(fā)之如何解決access_token過期問題
  • .net實現(xiàn)微信公眾賬號接口開發(fā)實例代碼
  • .net開發(fā)微信公眾平臺實例教程
  • asp.net微信開發(fā)(永久素材管理)
  • asp.net開發(fā)微信公眾平臺之獲取用戶消息并處理
  • asp.net微信開發(fā)(開發(fā)者接入)
  • .NET微信公眾號 用戶分組管理

標簽:喀什 佳木斯 泰安 玉林 房產(chǎn) 德宏 呂梁

巨人網(wǎng)絡(luò)通訊聲明:本文標題《微信公眾平臺開發(fā)之發(fā)送文本消息.Net代碼解析》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    修武县| 吴川市| 乐亭县| 舞阳县| 安西县| 延安市| 钟祥市| 自治县| 榆中县| 天门市| 四平市| 沙坪坝区| 竹溪县| 阜城县| 文山县| 桃源县| 陇西县| 平山县| 永嘉县| 福州市| 信阳市| 钟山县| 和政县| 东乡族自治县| 来凤县| 阜阳市| 汤原县| 天祝| 元谋县| 沅陵县| 启东市| 天峻县| 榕江县| 娱乐| 郑州市| 北票市| 仁布县| 关岭| 勃利县| 衢州市| 濮阳市|