标签:local 一个 image col com int cal 消息 java
导语:现在越来越流行微信报警功能了。下面就来看看具体实现吧!
传送门:http://work.weixin.qq.com/



CorpID 在我的企业一栏中
AgentId
Secret 这2个都在应用中
API调试传送门:http://work.weixin.qq.com/api/devtools/devtool.php
1 #!/bin/bash
2 # -*- coding: utf-8 -*-
3 ###SCRIPT_NAME:weixin.sh###
4 ###send message from weixin for monitoring###
5 ###leo###
6 ###V1-2017-09-05
7
8 CropID=‘xxx‘
9 Secret=‘xxx‘
10 GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret"
11 Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F \" ‘{print $10}‘)
12 PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"
13 function body() {
14 local int AppID=xxx # 企业号中的应用id
15 local UserID=$1 # 部门成员id,zabbix中定义的微信接收者
16 #local PartyID=$2 # 部门id,定义了范围,组内成员都可接收到消息
17 local Msg="hello" # 过滤出zabbix中传递的第三个参数
18 printf ‘{\n‘
19 printf ‘\t"touser": "‘$UserID‘",\n‘
20 #printf ‘\t"toparty": "$PartyID",\n‘
21 printf ‘\t"msgtype": "text",\n‘
22 printf ‘\t"agentid": "‘$AppID‘",\n‘
23 printf ‘\t"text": {\n‘
24 printf ‘\t\t"content": "‘$Msg‘"\n‘
25 printf ‘\t},\n‘
26 printf ‘\t"safe":"0"\n‘
27 printf ‘}\n‘
28 }
29 #body $1
30 curl --data-ascii "$(body $1)" $PURL
31 printf ‘\n‘
32 echo "over!"
sh weixin.sh mei
{ "touser": "mei", "msgtype": "text", "agentid": "xxx", "text": { "content": "hello" }, "safe":"0" } over!
手机上

OK!到此,通过微信企业号发送报警就成功实现了!
标签:local 一个 image col com int cal 消息 java
原文地址:http://www.cnblogs.com/leomei91/p/7479562.html