微信公众号实现zaabix报警2017脚本(升级企业微信后)

#!/bin/bash

CropID='xxxxxxxxxxxxxxxxx'
Secret='xxxxxxxxxxxxxxxx'
GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret"
Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F\" '{print $10}')

PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"

function body() {
        local int AppID=28
        local UserID=$1
        local PartyID=3
        local Msg=$(echo "$@" | cut -d" " -f3-)
        printf '{\n'
        printf '\t"touser" : "'"$UserID"\"",\n"
        printf '\t"toparty" : "'"$PartyID"\"",\n"
        printf '\t"totag" : "'"1"\"",\n"
        printf '\t"msgtype" : "text",\n'
        printf '\t"agentid" : "'"$AppID"\"",\n"
        printf '\t"text" : {\n'
        printf '\t\t"content" : "'"$Msg"\""\n"
        printf '\t}\n'
        printf '}\n'
}
/usr/bin/curl --data-ascii "$(body  $1 $2 $3)" $PURL

 

posted @ 2017-06-05 14:27  杨小愚  阅读(754)  评论(0编辑  收藏  举报