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



二、机器人配置说明
- 创建好的机器人都有一个唯一的
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',<?phpnamespace 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); }}
边栏推荐
- SMS sending + serial port printing based on stm32f103-sim900a
- Machine learning (IV) - PCA (principal component analysis) theory and code explanation
- 【TcaplusDB知识库】TcaplusDB-tcapulogmgr工具介绍(一)
- 如何基于Ceph设计与构建一套软件定义存储系统
- 即构推出行业首个数据流录制PaaS方案,低成本复刻头部大厂录制能力
- 秒云与趋动科技联合发布容器云平台与GPU资源池化整体解决方案
- 7.5.4:Spire Office for . NET New Version
- 【TcaplusDB知识库】TcaplusDB表数据缓写介绍
- 9、Wide&Deep简介
- 行业领先的界面组件包DevExpress 6月正式发布v21.2.8
猜你喜欢

全网最全,含面试题+答案
![[tcapulusdb knowledge base] Introduction to tcapulusdb analytical text export](/img/ab/e6241f635c6736a0d6877ae4cf10df.png)
[tcapulusdb knowledge base] Introduction to tcapulusdb analytical text export

Fuel scheme and product business modeling

9. Introduction to wide & deep

即构推出行业首个数据流录制PaaS方案,低成本复刻头部大厂录制能力

基于STM32F103——DS1302日期时间+串口打印

Wallys/Network_ Card/DR-NAS26/AR9223/2x2 MIMO

2022年二建《法规》科目答案已出,请收好

Cube 技术解读 | Cube 渲染设计的前世今生

浅谈常见的web攻击以及如何防范
随机推荐
一切的开始,测试学妹
QT的多线程详解(包含案例)
Kubernetes问题整理
The answer to the subject of "Regulations" of the second construction company in 2022 has been provided. Please keep it
Web development video tutorial, web development teaching
Details of fitfi sports money making chain game system development mode
机器学习(二)—逻辑回归理论与代码详解
Pulsar 消费者
Internal register type
The most complete network, including interview questions + Answers
基于STM32F103——SIM900A发送短信+串口打印
10、DCN 介绍
基于STM32F103——AS608指纹模块+串口打印
The industry-leading interface component package devaxpress officially released v21.2.8 in June
Tamigou equity project sharing: transfer of 1637900 shares of Beijing Huadahua New Technology Co., Ltd
5 locksupport and thread interruption
UNIX环境高级编程(APUE,第三版)---环境搭建
Cube 技术解读 | Cube 渲染设计的前世今生
IDEA 使用
SMS sending + serial port printing based on stm32f103-sim900a