shell微信机器人-webhook

官网:https://developer.work.weixin.qq.com/document/path/99110

支持语法:机器人支持文本(text)、markdown(markdown)、图片(image)、图文(news)、文件(file)、语音(voice)、模板卡片(template_card)七种消息类型。

text,发群消息

1
2
3
4
5
Webhook='https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=bdfdcb3b-6454-4382-81f6-afa463d1ccdd'
Message=哈喽
###################################################################

curl $Webhook -H 'Content-Type: application/json' -d "{\"msgtype\": \"text\",   \"text\": {\"content\": \"$Message\"}}"

text,发群消息时@多人

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
Webhook='https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=bdfdcb3b-6454-4382-81f6-afa463d1ccdd'
Message='第一行内容\n第二行内容'
#@多个用户使用空格分割,若空则仅发群消息不@用户id是英文不是昵称可企业微信网页版查看
USERID='ffing'
TEL='手机号'
###################################################################
#获取用户id
for i in `echo $USERID`;do 
if [ -z $SUM_USERID ];then SUM_USERID="\"$i\"";else SUM_USERID="$SUM_USERID,\"$i\"";fi
done
#获取手机号
for ii in `echo $TEL`;do
if [ -z $SUM_TEL ];then SUM_TEL="$ii";else SUM_TEL="\"$SUM_TEL\",\"$ii\"";fi
done
curl $Webhook -H 'Content-Type: application/json' -d "{\"msgtype\": \"text\",   \"text\": {\"content\": \"$Message\",\"mentioned_list\":[$SUM_USERID],\"mentioned_mobile_list\":[$SUM_TEL]}}"

text,多人范例

1
2
3
4
5
6
7
8
{
    "msgtype": "text",
    "text": {
        "content": "广州今日天气:29度,大部分多云,降雨概率:60%",
        "mentioned_list":["wangqing","@all"],
        "mentioned_mobile_list":["13800001111","@all"]
    }
}

创建微信机器人,并获取webhook