1 #!/bin/env bash 2 #set -x 3 CorpID="ww0597fbc0e83ed529" #企业ID 4 Secret="BQtxvc7qGV_I6FrmnA8LOaUWwfUC1ppYbwVwPrllxFU" #应用的Secret 5 GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CorpID&corpsecret=$Secret" 6 Token=$(/usr/bin/curl -s -G $GURL |awk -F ":" ‘{print $4}‘|awk -F \" ‘{print $2}‘) 7 echo $Token 8 PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Token" 9 UserID="@all" #成员ID列表 10 #PartyID=1 #部门ID 11 agentid=1000002 #企业应用的ID 12 Msg=$@ 13 Msg=`echo ${Msg} | sed $‘s/\"//g‘` 14 message(){ 15 printf ‘{\n‘ 16 printf ‘\t"touser": "‘"$UserID"\"",\n" 17 # printf ‘\t"toparty": "‘"$PartyID"\"",\n" 18 printf ‘\t"msgtype": "text",\n‘ 19 printf ‘\t"agentid": "‘"$agentid"\"",\n" 20 printf ‘\t"text": {\n‘ 21 printf ‘\t\t"content": "‘"${Msg}"\""\n" 22 printf ‘\t},\n‘ 23 printf ‘\t"safe":"0"\n‘ 24 printf ‘}\n‘ 25 } 26 /usr/bin/curl --data-ascii "$(message)" $PURL