微信企业号 发送信息 shell

微信企业号发送信息shell

#可作为shell函数模块调用,用于微信通知、jenkins发版微信通知等等
# 微信API官方文档 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"

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

转载于:https://www.cnblogs.com/elvi/p/11444388.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值