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 Msg=`echo ${Msg} | sed $'s/%/%&/g'`
15 message(){
16 printf '{\n'
17 printf '\t"touser": "'"$UserID"\"",\n"
18 # printf '\t"toparty": "'"$PartyID"\"",\n"
19 printf '\t"msgtype": "text",\n'
20 printf '\t"agentid": "'"$agentid"\"",\n"
21 printf '\t"text": {\n'
22 # printf '\t\t"content": "'"${Msg}"\""\n"
23 printf '\t\t"content":"'"${Msg}"'"'\n
24 printf '\t},\n'
25 printf '\t"safe":"0"\n'
26 printf '}\n'
27 }
28 /usr/bin/curl --data-ascii "$(message)" $PURL