1 #!/bin/bash 2 #==================================================== 3 # Author: VizierBi 4 # Create Date: 2018-10-19 5 # Description:微信监控报警脚本 6 #==================================================== 7 CropID=\'wwaebf94b1310467a9\' 8 Secret=\'W6ahrPd1vg-M2I1CbXa9MYhRW_Vp10NNmOQNov2ELvY\' 9 GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret" 10 Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F\" \'{print $10}\') 11 PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken" 12 13 function body(){ 14 local int AppID=1000002 15 local UserID=$1 16 local PartyID=1 17 local Msg=$(echo "$@" | cut -d" " -f3-) 18 printf \'{\n\' 19 printf \'\t"touser": "\'"$User"\"",\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 /usr/bin/curl --data-ascii "$(body $1 $2 $3)" $PURL