文本类型,只可以@一个人的
新建一个send.sh并且赋予可执行权限
#!/bin/bash
# 钉钉机器人 webhook 地址
webhook_url="https://oapi.dingtalk.com/robot/send?access_token=自己的token"
# 消息内容
subject="$1"
message="$2"
at_mobiles="$3"
# 组装 JSON 数据
json="{\"msgtype\":\"text\",\"text\":{\"content\":\"${subject}\n${message}\"},\"at\":{\"atMobiles\":[\"${at_mobiles}\"],\"isAtAll\":false}}"
# 发送 POST 请求
curl -s -H "Content-Type: application/json" -X POST --data "${json}" "${webhook_url}" >/dev/null 2>&1
如何运行:
./send.sh 123 456 手机号
文本类型,可以@多个人的
新建一个send.sh并且赋予可执行权限
#!/bin/bash
# 钉钉机器人 webhook 地址
webhook_url="https://oapi.dingtalk.com/robot/send?access_token=自己的token"
# 消息内容
subject="$1"
message="$2"
at_mobiles=( "$3" "$4" "$5" ) # 将需要@的手机号码放入一个数组中
# 组装 JSON 数据
at_list=""
for mobile in "${at_mobiles[@]}"
do
at_list+="\"$mobile\","
done
at_list="${at_list%,}" # 去除最后一个逗号
json="{\"msgtype\":\"text\",\"text\":{\"content\":\"${subject}\n${message}\"},\"at\":{\"atMobiles\":[${at_list}],\"isAtAll\":false}}"
# 发送 POST 请求
curl -s -H "Content-Type: application/json" -X POST --data "${json}" "${webhook_url}" >/dev/null 2>&1
如何运行:
./send.sh 123 456 手机号1 手机号2
当然也可以@100个人
#!/bin/bash
# 钉钉机器人 webhook 地址
webhook_url="https://oapi.dingtalk.com/robot/send?access_token=自己的token"
# 消息内容
subject="$1"
message="$2"
at_mobiles=( "$3" "$4" "$5" "$6" "$7" "$8" "$9" "${10}" "${11}" "${12}" "${13}" "${14}" "${15}" "${16}" "${17}" "${18}" "${19}" "${20}" "${21}" "${22}" "${23}" "${24}" "${25}" "${26}" "${27}" "${28}" "${29}" "${30}" "${31}" "${32}" "${33}" "${34}" "${35}" "${36}" "${37}" "${38}" "${39}" "${40}" "${41}" "${42}" "${43}" "${44}" "${45}" "${46}" "${47}" "${48}" "${49}" "${50}" "${51}" "${52}" "${53}" "${54}" "${55}" "${56}" "${57}" "${58}" "${59}" "${60}" "${61}" "${62}" "${63}" "${64}" "${65}" "${66}" "${67}" "${68}" "${69}" "${70}" "${71}" "${72}" "${73}" "${74}" "${75}" "${76}" "${77}" "${78}" "${79}" "${80}" "${81}" "${82}" "${83}" "${84}" "${85}" "${86}" "${87}" "${88}" "${89}" "${90}" "${91}" "${92}" "${93}" "${94}" "${95}" "${96}" "${97}" "${98}" "${99}" "${100}" )
# 组装 JSON 数据
at_list=""
for mobile in "${at_mobiles[@]}"
do
at_list+="\"$mobile\","
done
at_list="${at_list%,}" # 去除最后一个逗号
json="{\"msgtype\":\"text\",\"text\":{\"content\":\"${subject}\n${message}\"},\"at\":{\"atMobiles\":[${at_list}],\"isAtAll\":false}}"
# 发送 POST 请求
curl -s -H "Content-Type: application/json" -X POST --data "${json}" "${webhook_url}" >/dev/null 2>&1
**
终极大招,可以@1个人,也可以@无数个人
**
手机号码用英文状态下的,隔开,并传参数
#!/bin/bash
# 钉钉机器人 webhook 地址
webhook_url="https://oapi.dingtalk.com/robot/send?access_token=自己的token"
# 消息内容
subject="$1"
message="$2"
at_mobiles="$3" # 将包含手机号码的字符串赋值给变量
# 将分隔符设置为逗号
IFS=','
# 将 $at_mobiles 字符串分解为数组
read -ra mobiles_array <<< "$at_mobiles"
# 组装 JSON 数据
at_list=""
for mobile in "${mobiles_array[@]}"
do
at_list+="\"$mobile\","
done
at_list="${at_list%,}" # 去除最后一个逗号
json="{\"msgtype\":\"text\",\"text\":{\"content\":\"${subject}\n${message}\"},\"at\":{\"atMobiles\":[${at_list}],\"isAtAll\":false}}"
# 发送 POST 请求
curl -s -H "Content-Type: application/json" -X POST --data "${json}" "${webhook_url}" >/dev/null 2>&1
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/181665.html