|
首先申请企业号获取对应应用中的CropID和Secret以及应用ID
这部分后面再进行添加
也可参考
www.iyunv.com/thread-142633-1-1.html
中的内容进行设置
1、将cacti中thold的报警内容导出至文本文件进行保存
进入cacti主目录
1
| vi plugins/thold/thold_functions.php
|
查找mailer。在如下位置插入后面的的语句
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| $msg_wx = strip_tags(str_replace('<br>', "\n", $message));//删除message中的html标签,并将<br>替换为换行符\n
$msg_wx = trim($msg_wx);//整理msg_wx字符串
$file_title = '/tmp/title.txt';//要写入文件的文件名(可以是任意文件名),如果文件不存在,将会创建一个
$file_message = '/tmp/message.txt';//要写入文件的文件名(可以是任意文件名),如果文件不存在,将会创建一个
if($f = file_put_contents($file_title, $subject)){//将subject参数的值保存到file_title中
}
if($f = file_put_contents($file_message, $msg_wx)){//将msg_wx参数的值保存到file_message中
}
shell_exec("/etc/wechat.sh");
|
然后创建微信发送脚本
1
2
| vi /etc/wechat.sh
chmod 750 /etc/wechat.sh
|
输入如下内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
| #微信企业号发送消息脚本
#By:Fenei QQ:407603129
#2015年12月26日
#!/bin/bash
CropID='企业号ID'
#此处为企业号ID
Secret='企业号密钥'
#此处为企业号密钥
GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret"
Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F\" '{print $4}')
PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"
function body() {
local int AppID=11
#此处为你所创建的消息型应用的ID号
local UserID=fenei
#此处为你所要发送的用户号
local PartyID=1
#此处为你所要发送的部门ID
local TagID=2
#此处为你所要发送的标签ID
Tit=$(cat /tmp/title.txt)
#读取/tmp/title文件中内容到变量Tit
Msg=$(cat /tmp/message.txt)
#读取/tmp/message文件中内容到变量Msg
Url=$(grep "http" /tmp/message.txt|sed 's/URL: //g')
#获取message.txt中的url行内容到变量Url
Pic=$(grep "http" /tmp/message.txt|sed 's/URL: //g'|sed 's/graph.php/graph_image.php/g')
#根据url行内容修改为添加Pic参数
printf '{\n'
printf '\t"touser": "'"$User"\"",\n"
printf '\t"toparty": "'"$PartyID"\"",\n"
printf '\t"totag": "'"$TagID"\"",\n"
printf '\t"msgtype": "news",\n'
printf '\t"agentid": "'" $AppID "\"",\n"
printf '\t"news": {\n'
printf '\t"articles": [\n'
printf '{\n'
printf '\t\t"title": "'"$Tit"\","\n"
printf '\t\t"description": "'"$Msg"\","\n"
printf '\t\t"url": "'"$Url"\","\n"
printf '\t\t"picurl": "'"$Pic"\","\n"
printf '\t}\n'
printf '\t]\n'
printf '\t}\n'
printf '}\n'
}
/usr/bin/curl --data-ascii "$(body )" $PURL
|
3 修改graph_img.php文件,取消graph_image.php的认证。
否则微信无法正常显示图片
1
2
3
| #include("./include/auth.php");
include_once("./lib/rrd.php");
include("./include/global.php");
|
|
|
|