Arduion报警通知,企业微信机器人报警通知

直接调用我这个方法,即可发送通知。

企业微信机器人对接,通过  esp8266 或者 esp32 或者其他开发板发送通知

咱们以 知乎上这篇文章为例,做 8266的 post推送

利用机器人自动向微信群发送提醒消息 - 知乎

如何使用群机器人

  • 在终端某个群组添加机器人之后,创建者可以在机器人详情页看的该机器人特有的webhookurl。开发者可以按以下说明a向这个地址发起HTTP POST 请求,即可实现给该群组发送消息。下面举个简单的例子.
    假设webhook是:https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=693a91f6-7xxx-4bc4-97a0-0ec2sifa5aaa

特别特别要注意:一定要保护好机器人的webhook地址,避免泄漏!不要分享到github、博客等可被公开查阅的地方,否则坏人就可以用你的机器人来发垃圾消息了。

以下是用curl工具往群组推送文本消息的示例(注意要将url替换成你的机器人webhook地址,content必须是utf8编码):



  1. curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=693axxx6-7aoc-4bc4-97a0-0ec2sifa5aaa' \
  2. -H 'Content-Type: application/json' \
  3. -d '
  4. {
  5. "msgtype": "text",
  6. "text": {
  7. "content": "hello world"
  8. }
  9. }'
  • 当前自定义机器人支持文本(text)、markdown(markdown)、图片(image)、图文(news)四种消息类型。
  • 机器人的text/markdown类型消息支持在content中使用<@userid>扩展语法来@群成员

消息类型及数据格式

文本类型



  1. {
  2. "msgtype": "text",
  3. "text": {
  4. "content": "广州今日天气:29度,大部分多云,降雨概率:60%",
  5. "mentioned_list":["wangqing","@all"],
  6. "mentioned_mobile_list":["13800001111","@all"]
  7. }
  8. }
参数是否必填说明
msgtype消息类型,此时固定为text
content文本内容,最长不超过2048个字节,必须是utf8编码
mentioned_listuserid的列表,提醒群中的指定成员(@某个成员),@all表示提醒所有人,如果开发者获取不到userid,可以使用mentioned_mobile_list
mentioned_mobile_list手机号列表,提醒手机号对应的群成员(@某个成员),@all表示提醒所有人
#define BLINKER_WIFI
#include <ArduinoJson.h>
#include <Blinker.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecure.h>




void sendMSG2() {
  Blinker.vibrate();
  if (WiFi.status() == WL_CONNECTED) {
    WiFiClientSecure client;
    client.setInsecure();
    HTTPClient http;
    http.begin(client,"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=你的key");
    http.addHeader("Content-Type", "application/json");


    DynamicJsonDocument doc(1024);
    // Add string to "msgtype"
    doc["msgtype"] = "text";

    // Add nested object "text"
    JsonObject text = doc.createNestedObject("text");
    text["content"] = "我睡醒了,我睡醒了";
    String httpRequestData;
    // Add array to "mentioned_mobile_list"
  JsonArray mentioned_mobile_list = text.createNestedArray("mentioned_mobile_list");
  mentioned_mobile_list.add("13831111111");
  //mentioned_mobile_list.add("@all");

    serializeJson(doc, httpRequestData);

    int httpResponseCode = http.POST(httpRequestData);  //Send the actual POST request
    
    if (httpResponseCode > 0) {
      String response = http.getString();  //Get the response to the request
      Serial.println(httpResponseCode);    //Print return code
      Serial.println(response); 
    } else {
      Serial.print("Error on sending POST: ");
      Serial.println(httpResponseCode);
    }

    http.end();  //Free resources
  } else {
    Serial.println("Error in WiFi connection");
  }
}

Logo

鸿蒙生态一站式服务平台。

更多推荐