当前位置:网站首页>实战模拟│企业微信机器人实时报错预警
实战模拟│企业微信机器人实时报错预警
2022-06-13 10:11:00 【InfoQ】
一、创建机器人
选择群►右键►管理聊天信息►添加群机器人
- 完善机器人基本信息,包括头像、名称等



二、机器人配置说明
- 创建好的机器人都有一个唯一的
webhook地址
- 一定要保护好自己的
webhook地址,如果一旦泄露,可以通过移除机器人,再重新创建一个去处理
- 点击
webhook地址,可以看到文档说明,也可以进行普通的推送消息配置
- 其中的自定义推送消息,在机器人配置说明栏目里面有详细说明,但是需要自己开发


三、机器人信息推送
- 当前自定义机器人
支持文本(text)、markdown(markdown)、图片(image)、图文(news)四种消息类型
- 我们只要根据它的文档说明,将指定类型的消息发送给
webhook地址即可实现消息推送
// 文本消息类型
{
"msgtype": "text",
"text": {
"content": "广州今日天气:29度,大部分多云,降雨概率:60%",
"mentioned_list":["wangqing","@all"],
"mentioned_mobile_list":["13800001111","@all"]
}
}
// markdown消息类型
{
"msgtype": "markdown",
"markdown": {
"content": "实时新增用户反馈<font color=\"warning\">132例</font>,请相关同事注意。\n
>类型:<font color=\"comment\">用户反馈</font>
>普通用户反馈:<font color=\"comment\">117例</font>
>VIP用户反馈:<font color=\"comment\">15例</font>"
}
}
// 图片消息类型
{
"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"
}
]
}
}四、错误预警推送
- 这里以
Thinkphp框架为例,将错误预警整合到项目中,实现实时错误推送
- 首先在
config配置文件添加错误处理类,执行哪个文件来处理错误
- 配置完成后,项目只要遇到错误,程序都会走指定的文件去处理
- 然后在该文件中完善错误推送预警逻辑即可,一般错误预警都是用
markdown类型进行推送
'exception_handle' => '\\app\\common\\exception\\WorkWx',<?php
namespace app\common\exception;
use Exception;
use itbdw\Ip\IpLocation;
use app\common\util\Helper;
use think\exception\Handle;
use think\exception\HttpException;
use think\exception\ValidateException;
class WorkWx extends Handle
{
const WEBHOOK = '填写你自己的webhook地址';
public function render(Exception $e)
{
$clientIP = Helper::getClientIp();
$clientAddress = IpLocation::getLocation($clientIP);
unset($clientAddress['ip']);
$ipAddress = implode('-', $clientAddress);
// 参数验证错误
if ($e instanceof ValidateException) {
$data = [
'msgtype' => 'markdown',
'markdown' => [
'content' => "来自 **<font color=\"info\">天眼</font>** 的温馨提醒,请相关同事注意。
>**描述:** <font color=\"comment\">参数验证错误</font>
>**端IP:** <font color=\"comment\">{$clientIP}</font>
>**地址:** <font color=\"comment\">{$ipAddress}</font>
>**状态:** <font color=\"comment\">{$e->getCode()}</font>
>**行数:** <font color=\"comment\">{$e->getLine()}</font>
>**文件:** <font color=\"red\">{$e->getFile()}</font>
>**提示:** <font color=\"warning\">{$e->getError()}</font>
>**信息:** <font color=\"warning\">{$e->getMessage()}</font>"
]
];
return Helper::postCurl(self::WEBHOOK, json_encode($data));
}
// 请求异常
if ($e instanceof HttpException) {
$data = [
'msgtype' => 'markdown',
'markdown' => [
'content' => "来自 **<font color=\"info\">天眼</font>** 的温馨提醒,请相关同事注意。
>**描述:** <font color=\"comment\">请求异常</font>
>**端IP:** <font color=\"comment\">{$clientIP}</font>
>**地址:** <font color=\"comment\">{$ipAddress}</font>
>**状态:** <font color=\"comment\">{$e->getCode()}</font>
>**行数:** <font color=\"comment\">{$e->getLine()}</font>
>**文件:** <font color=\"red\">{$e->getFile()}</font>
>**信息:** <font color=\"warning\">{$e->getMessage()}</font>"
]
];
return Helper::postCurl(self::WEBHOOK, json_encode($data));
}
// 其他错误交给系统处理
return parent::render($e);
}
}
边栏推荐
- Introduction to knowledge map
- [pytorch environment installation]
- Consolas-with-Yahei
- go-zero微服务实战系列(三、API定义和表结构设计)
- SQL Server创建windows登录账户找不到用户或组
- Index query list injects MySQL and executes Oracle
- Matlab hub motor analysis fuzzy PID control vertical vibration analysis
- Système de gestion des défauts du projet Cynthia
- 第一章 第一节
- 大O记法解释
猜你喜欢
![[ssl1271] sort I [heap]](/img/4d/f1e1b400db244835f037049a9577bf.jpg)
[ssl1271] sort I [heap]
![[pytorch environment installation]](/img/00/78f6942ed3ff721675abb91504fb5c.png)
[pytorch environment installation]

苹果放大招!这件事干的太漂亮了……

go-zero微服务实战系列(三、API定义和表结构设计)

冗余码题型--后面加0的区别
![[51nod p3111] xiaoming'ai intercepts [Las]](/img/39/2d75a289c715fd010bf400d6eace71.jpg)
[51nod p3111] xiaoming'ai intercepts [Las]

五分钟内编写Pytorch模型

Node-RED系列(二五):集成高德地图并实现3d地图和轨迹回放

【ELM分类】基于粒子群优化卷积神经网络CNN结合极限学习机ELM实现数据分类附matlab代码

Talk about the bottom playing method of C # method overloading
随机推荐
A hot MySQL training topic, making you a master of SQL
【20220526】UE5.0.2 release d11782b
云计算企业崛起 甲骨文数据库市场主导地位动摇
Knowledge points of silicon steel sheet
C# 11 更加实用的 nameof
Node red series (27): instructions for S7 node of the extension node
虚拟机内存结构简述
WebRTC服务端工程实践和优化探索
格林纳达代表团团长孙宇晨出席WTO MC12 强调发展数字经济
Standard template library (STL)
[51nod p3058] Xiao ming'ai set [set]
36氪首发|打造国产精算预测引擎等产品,「深轻科技」连续完成三轮融资
基于单片机的简易电子钟设计
Tree and binary tree: storage structure of binary tree
The rise of cloud computing enterprises and the shaking of Oracle database market dominance
deepin系统中Qt5.12无法输入中文(无法切换中文输入法)解决办法
首个Laravel工作流引擎发布 V1.0正式版
【云享新鲜】社区周刊·Vol.66-华为伙伴暨开发者大会2022精彩议程公布
Write pytoch model in five minutes
Thingsboard tutorial (21): save data after processing using message types and data processing nodes