C#微信群推动消息 您所在的位置:网站首页 微信群发消息怎么发给群组 C#微信群推动消息

C#微信群推动消息

2024-07-01 09:24| 来源: 网络整理| 查看: 265

C# 给企业微信群推动消息发送文本markdown类型图片类型图文类型消息发送频率限制

给企业微信群推动消息

在终端某个群组添加机器人之后,可以获取到webhook地址,然后开发者用户按以下说明构造post data向这个地址发起HTTP POST 请求,即可实现给该群组发送消息。下面举个简单的例子. 假设webhook是:https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=693a91f6-7xxx-4bc4-97a0-0ec2sifa5aaa

//文本信息发送给微信群里面的消息 String objectStr = "{\"msgtype\":\"text\",\"text\":{\"content\":\"hello world\"}}"; //当创建一个机器人,会给出对应的webhook string url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=04ec98e0-6332-490a-9766-c87131bee3c6"; //发送消息 string s = Post(url, objectStr); public static string Post(string Url, string jsonParas) { string strURL = Url; //创建一个HTTP请求 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL); //Post请求方式 request.Method = "POST"; //内容类型 request.ContentType = "application/json"; //设置参数,并进行URL编码 string paraUrlCoded = jsonParas;//System.Web.HttpUtility.UrlEncode(jsonParas); byte[] payload; //将Json字符串转化为字节 payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded); //设置请求的ContentLength request.ContentLength = payload.Length; //发送请求,获得请求流 Stream writer; try { writer = request.GetRequestStream();//获取用于写入请求数据的Stream对象 } catch (Exception) { writer = null; Console.Write("连接服务器失败!"); } //将请求参数写入流 writer.Write(payload, 0, payload.Length); writer.Close();//关闭请求流 // String strValue = "";//strValue为http响应所返回的字符流 HttpWebResponse response; try { //获得响应流 response = (HttpWebResponse)request.GetResponse(); } catch (WebException ex) { response = ex.Response as HttpWebResponse; } Stream s = response.GetResponseStream(); // Stream postData = Request.InputStream; StreamReader sRead = new StreamReader(s); string postContent = sRead.ReadToEnd(); sRead.Close(); return postContent;//返回Json数据 } 发送文本

如果只给微信群里发送文本信息如何设置字段与属性

{ "msgtype": "text", "text": { "content": "广州今日天气:29度,大部分多云,降雨概率:60%", "mentioned_list":["wangqing","@all"], "mentioned_mobile_list":["13800001111","@all"] } }

字段信息

markdown类型 { "msgtype": "markdown", "markdown": { "content": "实时新增用户反馈132例,请相关同事注意。\n >类型:用户反馈 >普通用户反馈:117例 >VIP用户反馈:15例" } }

markdown属性字段

图片类型 { "msgtype": "image", "image": { "base64": "DATA", "md5": "MD5" } }

在这里插入图片描述

图文类型 { "msgtype": "news", "news": { "articles" : [ { "title" : "中秋节礼品领取", "description" : "今年中秋节公司有豪礼相送", "url" : "www.qq.com", "picurl" : "http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png" } ] } }

在这里插入图片描述

消息发送频率限制

每个机器人发送的消息不能超过20条/分钟。

通过以上操作就可以完成借用企业微信群的机器人来发送消息了。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有