🎈 Create bot
-
选择群
► 右键
► 管理聊天信息
► 添加群机器人
- Improve the basic information of the robot, including avatar, name, etc.
🎈 Robot configuration instructions
- The created robot has a unique
webhook
address - Be sure to protect your
webhook
address. If it is leaked, you can remove the robot and create a new one to deal with - Click
webhook
address, you can see the documentation, and you can also configure ordinary push messages - The custom push messages are described in detail in the robot configuration description column, but they need to be developed by themselves
🎈 Robot information push
- The current custom robot
支持文本(text)、markdown(markdown)、图片(image)、图文(news)
four message types - We only need to send the specified type of message to the
webhook
address according to its documentation to achieve message push
// 文本消息类型
{
"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"
}
]
}
}
🎈 Error warning push
- Here we take the
Thinkphp
framework as an example to integrate error warning into the project to realize real-time error push - First add an error handling class to the
config
configuration file, which file is executed to handle the error - After the configuration is completed, as long as the project encounters an error, the program will go to the specified file to process it.
- Then perfect the error push warning logic in this file. Generally, error warnings are pushed with the
markdown
type.
'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);
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。