侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

微信公众平台开发之发送文本消息.Net代码解析

微信(小程序)  /  管理员 发布于 2年前   186

.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代码解析
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 微信小程序前端使用七牛云官方SDK上传七牛云代码示例(0个评论)
    • 百度小程序审核未通过,真机审核存在点击返回键退出小程序...解决方式之一tabBar(0个评论)
    • 百度小程序详情页中使用wxapp-rich-text组件解析html标签并展示出来(0个评论)
    • 百度小程序列表中点击跳转详情页流程步骤(0个评论)
    • 百度小程序封装get post请求等全局函数及实现请求后端api数据循环展示功能(0个评论)
    • 近期文章
    • zongscan祝大家2023元宵节快乐(0个评论)
    • 2023年国内最新注册苹果开发者账号之申请邓白氏编码流程步骤(0个评论)
    • 2023年国内最新注册苹果个人开发者账号及支付会员年费流程步骤(0个评论)
    • 在js中使用URL类用来解析处理URL的示例代码(0个评论)
    • js中动画事件:requestAnimationFrame、transitionend、animation...(0个评论)
    • Laravel 9.49版本发布(0个评论)
    • 在Laravel应用程序如何减少代码重复编写(0个评论)
    • 在laravel项目中提高安全性方式推荐:CSP内容安全策略(0个评论)
    • 在go语言中从值中获取常量名称代码示例(0个评论)
    • 在go语言中如何通过名称获得结构字段和值代码示例(0个评论)
    • 近期评论
    • 博主 在

      2023年国务院办公厅春节放假通知:1月21日起休7天中评论 @ xiaoB 你只管努力,剩下的叫给天意;天若有情天亦老,..
    • xiaoB 在

      2023年国务院办公厅春节放假通知:1月21日起休7天中评论 会不会春节放假后又阳一次?..
    • BUG4 在

      你翻墙过吗?国内使用vpn翻墙可能会被网警抓,你需了解的事中评论 不是吧?..
    • 博主 在

      go语言+beego框架中获取get,post请求的所有参数中评论 @ t1  直接在router.go文件中配就ok..
    • Jade 在

      如何在MySQL查询中获得当月记录中评论 Dear zongscan.com team, We can skyroc..
    • 2017-10
    • 2018-01
    • 2020-03
    • 2021-06
    • 2021-10
    • 2022-03
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客