当前位置:网站首页>实战模拟│企业微信机器人实时报错预警
实战模拟│企业微信机器人实时报错预警
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);
}
}
边栏推荐
- Système de gestion des défauts du projet Cynthia
- 格林纳达代表团团长孙宇晨出席WTO MC12 强调发展数字经济
- MySQL利用E-R模型的数据库概念设计
- Pxxx local socket communication
- Tree and binary tree: basic operation and implementation of binary tree
- [51nod 2493] sum of binary distances [bit operation]
- C# Oracle 多表查询
- 【云享新鲜】社区周刊·Vol.66-华为伙伴暨开发者大会2022精彩议程公布
- matlab轮毂电机分析模糊pid控制垂向振动分析
- Queue and stack
猜你喜欢

检验冗余码是否出错题型解法-摘录

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

Cynthia項目缺陷管理系統

Smart210 uses SD card to burn uboot

Knowledge points of silicon steel sheet

ASCII码值是怎么计算的,怎么计算arccos的值

Node red series (27): instructions for S7 node of the extension node

A hot MySQL training topic, making you a master of SQL
![[51nod p3111] xiaoming'ai intercepts [Las]](/img/39/2d75a289c715fd010bf400d6eace71.jpg)
[51nod p3111] xiaoming'ai intercepts [Las]

SQL Server创建windows登录账户找不到用户或组
随机推荐
类文件结构和类加载过程执行引擎简述
Matlab hub motor analysis fuzzy PID control vertical vibration analysis
【ELM分类】基于粒子群优化卷积神经网络CNN结合极限学习机ELM实现数据分类附matlab代码
Node-RED系列(二七):扩展节点之s7节点的使用说明
苹果放大招!这件事干的太漂亮了……
MySQL monitoring tool PMM, let you go to a higher level (Part 2)
[ssl1271] sort I [heap]
Test redundancy code for error problem type solution - excerpt
C language structure
Tree and binary tree: application of binary tree traversal
虚拟机内存结构简述
Write pytoch model in five minutes
Exception handling operation
Node red series (25): integrate Gaode map and realize 3D map and track playback
C 11 new feature: static abstract members in interfaces
Tree and binary tree: operation and storage structure of tree
MySQL事务隔离级别和MVCC
Redundancy code question type -- the difference between adding 0 after
Trees and binary trees: Construction of binary trees
简述请求过程