原来微信的报警脚本:
#!/bin/bash
CropID='企业id'
Secret='app secret'
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=1
local UserID=$1
local PartyID=1
local Msg=$(echo "$@" | cut -d" " -f3-)
printf '{\n'
printf '\t"touser": "'"$UserID"\"",\n"
printf '\t"toparty": "1",\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 '\t"safe":"0"\n'
printf '}\n'
}
/usr/bin/curl --data-ascii "$(body $1 $2 $3)" $PURL
如果报警消息中含有%,将会被转义,微信发送消息的结果中不能够正确的显示,以下是修改后的脚本,将不用之前的body方法:
#!/bin/bash
Gtoken=$(/usr/bin/curl -s -G $GURL|awk -F\" '{print $10}' )
PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"
text(){
userid=$1
appid=5
partyid=4
Msg=$3
message='{ "touser": "'$userid'", "toparty": "'$partyid'", "totag": "1", "msgtype": "text", "agentid": "'$appid'", "text": { "content": "'$Msg'" }, "safe":"0" }'
echo "$message"
}
echo $(text $1 $2 "$3")
/usr/bin/curl --data-ascii "$(text $1 $2 "$3")" $PURL
CropID='企业id'
Secret='app secret'
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"
text(){
userid=$1
appid=5
partyid=4
Msg=$3
message='{ "touser": "'$userid'", "toparty": "'$partyid'", "totag": "1", "msgtype": "text", "agentid": "'$appid'", "text": { "content": "'$Msg'" }, "safe":"0" }'
echo "$message"
}
echo $(text $1 $2 "$3")
/usr/bin/curl --data-ascii "$(text $1 $2 "$3")" $PURL