最近搜索

企业微信 怎么实现机器人发送消息。 群助手 订单助手。

浏览:81
管理员 2025-10-02 11:44



根据企业微信官方文档,群机器人Webhook的发送频率有以下限制:

‌基础限制‌:

每个Webhook地址每分钟最多发送20条消息

每条消息间隔建议至少3秒以上

单次请求大小不超过2048字节


这个就需要,观察消息有没有发送成功。  没有发生成功的。需要补发。 需要一个数据库表记录没有发送成功的消息。 

再写个定时器,去补发。


image.png


import requests
import json

webhook_url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=81232131321331232131232139a"

# 文本消息示例
text_message = {
    "msgtype": "text",
    "text": {
        "content": "预定单\n" +
                   "入住酒店:太适逸·童梦园民宿\n" +
                   "预订日期:10.13-15\n" +
                   "预订姓名: 1明\n" +
                   "联系方式: 132323232323232\n" +
                   "预订人数:11/人"
        ,
        "mentioned_mobile_list": ["@all"]  # @所有人
    }
}

response = requests.post(webhook_url, json=text_message)
print(response.json())




public static void main(String[] args) throws  Exception {
   JSONObject obj = new JSONObject();
   String webhook_url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=81232131321331232131232139a";
   obj.put("msgtype","text");
   obj.put("mentioned_mobile_list","text");

   JSONObject content = new JSONObject();
   content.put("content","预定单测试信息\n" +
         "入住酒店:测试信息太适逸·童梦园民宿\n" +
         "预订日期:10.13-15测试信息\n" +
         "预订姓名: 1明\n" +
         "联系方式: 123123123测试信息\n" +
         "预订人数:11/人测试信息");
   obj.put("text",content);
   List<String> list = new ArrayList<>();
   list.add("@all");
   obj.put("mentioned_mobile_list",list);
   System.out.println("数据内容:"+obj.toString());
   String result  = post(webhook_url,obj.toString());
   System.out.println("返回结果:"+result);
   //返回结果:{"errcode":93000,"errmsg":"invalid webhook url, hint: [1761541313614782513829808], from ip: 120.219.21.16, more info at https://open.work.weixin.qq.com/devtool/query?e=93000"}
}

/**
 * data 这是json格式的数据。{"content":"34524"}
 * object.put("content", msg);
 * String contentString = object.toString();
 * 传来的就是contentString
 */
public static String post(String url, String data) throws ClientProtocolException, IOException {
   CloseableHttpClient httpclient = HttpClients.createDefault();
   HttpPost httppost = new HttpPost(url);
   String result = "";
   StringEntity entity = new StringEntity(data, "utf-8");// 解决中文乱码问题
   entity.setContentEncoding("UTF-8");
   entity.setContentType("application/json");
   httppost.setEntity(entity);
   CloseableHttpResponse response = httpclient.execute(httppost);
   HttpEntity httpEntity = response.getEntity();
   if (httpEntity != null) {
      result = EntityUtils.toString(httpEntity, "UTF-8");
   }
   response.close();
   httpclient.close();
   return result;
}


联系站长

站长微信:xiaomao0055

站长QQ:14496453