Skip to content

Instantly share code, notes, and snippets.

@imbyc
Last active March 2, 2021 02:58
Show Gist options
  • Save imbyc/fff0e55358db1039b33614b5fe2d3f2a to your computer and use it in GitHub Desktop.
Save imbyc/fff0e55358db1039b33614b5fe2d3f2a to your computer and use it in GitHub Desktop.
[shell 调用企业微信接口发送通知] 使用curl发送 https://work.weixin.qq.com/api/doc/90000/90135/90236
#!/bin/bash
# 发送微信通知
# 企业ID https://work.weixin.qq.com/api/doc/90000/90135/90665#corpid
CORPID=填写企业ID
# 应用的凭证密钥 https://work.weixin.qq.com/api/doc/90000/90135/90665#secret
CORPSECRET=填写应用的凭证密钥
# 企业应用的id ,整型。企业内部开发,可在应用的设置页面查看
AGENTID=填写企业应用的id
# 获取token的接口地址 https://work.weixin.qq.com/api/doc/90000/90135/91039
TOKENURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CORPID&corpsecret=$CORPSECRET"
# 发送应用消息接口地址 https://work.weixin.qq.com/api/doc/90000/90135/90236
PUSHURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="
# 获取ACCESS_TOKEN
ACCESS_TOKEN=$(/usr/bin/curl -s -G $TOKENURL|awk -F\" '{print $10}')
# 参数文档 https://work.weixin.qq.com/api/doc/90000/90135/90236#文本消息
/usr/bin/curl \
-H 'Content-Type: application/json' \
-d '
{
"touser": "@all",
"msgtype": "text",
"agentid": '$AGENTID',
"text": {"content": "'"[ 消息通知 ] \n完成时间:$(date '+%F %T')"'"},
"safe": 0
}' "$PUSHURL""$ACCESS_TOKEN"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment