https://www.cnblogs.com/LuckWJL/p/9076510.html
#!/bin/bash
#set -x
#运维工程师 王初一
CorpID=
"********"
#我的企业下面的CorpID
Secret=
"***************"
#创建的应用那有Secret
GURL=
"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CorpID&corpsecret=$Secret"
Token=$(
/usr/bin/curl
-s -G $GURL |
awk
-F\":
'{print $4}'
|
awk
-F\"
'{print $2}'
)
#echo $Token
PURL=
"https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Token"
function
body(){
local
int agentid=1000066
#改为AgentId 在创建的应用那里看
local
UserID=$1
#发送的用户位于$1的字符串
local
PartyID=35
#第一步看的通讯录中的部门ID
local
Msg=$(
echo
"$@"
|
cut
-d
" "
-f3-)
printf
'{\n'
printf
'\t"touser": "'
"$UserID
"\""
,\n"
printf
'\t"toparty": "'
"$PartyID
"\""
,\n"
printf
'\t"msgtype": "text",\n'
printf
'\t"agentid": "'
"$agentid
"\""
,\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
测试 bash wechat.sh WangJinLong 告警测试 注意这是一条告警测试信息