1.下载微信接口

git clone https://github.com/lealife/WeiXin-Private-API

将微信接口移动至zabbix默认脚本路径

zabbix默认脚本路径:/usr/lib/zabbix/alertscripts/

[root@zabbix alertscripts]# vim WeiXin-Private-API/config.php

<?php

// 全局配置

$G_ROOT = dirname(__FILE__);

$G_CONFIG["weiXin"] = array(
'account' => '3133187148@qq.com',  ###微信公众账号
'password' => '微信公众账号密码',
'cookiePath' => $G_ROOT. '/cache/cookie', // cookie缓存文件路径
'webTokenPath' => $G_ROOT. '/cache/webToken', // webToken缓存文件路径
);

[root@zabbix alertscripts]# vim WeiXin-Private-API/test.php

<?php
require "config.php";
require "include/WeiXin.php";

$weiXin = new WeiXin($G_CONFIG['weiXin']);

#$testFakeId = "oIzQiwod4i3VoLqTB5cgTQUUz76s";         
$testFakeId = "$argv[1]";

$msg="$argv[3]";


#print_r($weiXin->send($testFakeId, "test"));
echo "<pre>";
print_r($weiXin->send($testFakeId, "$msg"));

[root@zabbix alertscripts]# pwd
/usr/lib/zabbix/alertscripts
[root@zabbix alertscripts]# vim weixin.sh

/usr/bin/php /usr/lib/zabbix/alertscripts/WeiXin-Private-API/test.php "$1" "$2" "$3"

进行测试

[root@zabbix alertscripts]# /usr/lib/zabbix/alertscripts/weixin.sh "oIzQiwod4i3VoLqTB5cgTQUUz76s" "" "hi"

stdClass Object
(
[base_resp] => stdClass Object
(
[ret] => 0
[err_msg] => ok
)

)

 测试成功!

!!!注意:若遇到以下情况,清除缓存

stdClass Object
(
[base_resp] => stdClass Object
(
[ret] => 200003
[err_msg] => invalid session
)

)

[root@zabbix alertscripts]# cd WeiXin-Private-API/
[root@zabbix WeiXin-Private-API]# ls
cache config.php include README.md test.php
[root@zabbix WeiXin-Private-API]# cd cache/
[root@zabbix cache]# ls
cookie webToken
[root@zabbix cache]# rm -fr *

 

网页添加weixin报警媒介

 

转载于:https://www.cnblogs.com/xfbc/p/5330121.html

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐