Enterprise micro-channel to send information shell

Enterprise micro-channel to send information shell

# Can be used as a shell function module calls for micro-channel notification, jenkins version micro letter sent notification, and
# micro-channel official API documentation https://work.weixin.qq.com/api/doc#90002/90151/90854

#!/bin/bash
# wechat.send.sh
# 微信企业号发送信息 shell
# blog https://www.cnblogs.com/elvi/p/11444388.html

##############################

function sendmsg() {

CorpID="wwe518*企业微信账号唯一ID"
Secret="自定义应用的密钥"
AgentId=1000004  #应用id

Url="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CorpID&corpsecret=$Secret"
Gtoken=$(curl -s -G $Url|awk -F\" '{print $10}')
PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"

[ `echo $Gtoken |wc -L` -gt 100 ] || { echo "get token error !";exit 1; }

curl -s --data-ascii '{
"toparty": "'"$1"'",
"msgtype": "text",
"agentid": "'"$AgentId"'",
"text": {"content": "'"$2"'"}
}' $PURL &>/tmp/wechat.log

if [ `grep "errmsg.*ok" /tmp/wechat.log |wc -l` -ne 1 ];then
    echo 'send error !'
    cat /tmp/wechat.log
    exit 1
fi

}

##############################
#测试 sendmsg

#内容
msg="@警告
主机:$(hostname)
信息:Node test
时间:$(date +"%F %T")
"

#  发送 "部门id" "内容"
sendmsg "3" "$msg"

##############################

Guess you like

Origin www.cnblogs.com/elvi/p/11444388.html