新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

微信公众平台开发之发送文本消息.Net代码解析的示例分析-创新互联

这篇文章主要为大家展示了“微信公众平台开发之发送文本消息.Net代码解析的示例分析”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“微信公众平台开发之发送文本消息.Net代码解析的示例分析”这篇文章吧。

成都创新互联公司服务项目包括邛崃网站建设、邛崃网站制作、邛崃网页制作以及邛崃网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,邛崃网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到邛崃省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

.Net实现微信公共服务平台开发中的发送文本消息功能,具体内容如下

首先建立一个微信消息类。

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")
   {//刚关注时的时间,用于欢迎词
    string content = "";
    content = "/:rose欢迎北京永杰友信科技有限公司/:rose\n直接回复“你好”";
    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;
  }
 
/// 
  /// 发送文字消息 
  /// 
  /// 获取的收发者信息 
  /// 内容 
  /// 
  private string sendTextMessage(wxmessage wx, string content)
  {
   string res = string.Format(@" ",
    wx.FromUserName, wx.ToUserName, DateTime.Now, content);
   return res;
  }

以上是“微信公众平台开发之发送文本消息.Net代码解析的示例分析”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!


新闻名称:微信公众平台开发之发送文本消息.Net代码解析的示例分析-创新互联
文章位置:http://www.wjwzjz.com/article/dcsjhc.html
在线咨询
服务热线
服务热线:028-86922220
TOP