-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathwxsend.sh
More file actions
50 lines (44 loc) · 1.36 KB
/
wxsend.sh
File metadata and controls
50 lines (44 loc) · 1.36 KB
1
2
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
#!/bin/bash
text=$1
sendKey=${WXSENDKEY}
wx_push_url=${WXPUSH_URL}
wx_token=${WX_TOKEN}
title="msg_from_serv00-play"
URL="https://sctapi.ftqq.com/$sendKey.send?"
if [[ -z "$1" ]]; then
echo "错误:未提供要发送的消息内容。"
echo "用法: $0 \"你的消息\""
exit 1
fi
if [[ -z "${wx_push_url}" ]]; then
if [[ -z ${sendKey} ]]; then
echo "未配置微信推送的sendKey,通过 https://sct.ftqq.com/r/13223 注册并登录server酱,取得sendKey"
else
res=$(timeout 20s curl -s -X POST $URL -d title=${title} -d desp="${text}")
if [ $? == 124 ]; then
echo "发送消息超时"
exit 1
fi
err=$(echo "$res" | jq -r ".data.error")
if [ "$err" == "SUCCESS" ]; then
echo "微信推送成功"
else
echo "微信推送失败, error:$err"
fi
fi
else
if [[ -z ${wx_token} ]]; then
echo "未配置wxpush微信推送的wx_token,请参考https://github.com/frankiejun/wxpush 获取wx_token"
else
res=$(timeout 20s curl -s -X POST "${wx_push_url}" -H "Authorization: $wx_token" -H "Content-Type: application/json" -d "{\"token\":\"${wx_token}\",\"title\":\"${title}\",\"content\":\"${text}\",\"contentType\":1,\"uids\":[],\"topicIds\":[]}")
if [ $? == 124 ]; then
echo "发送消息超时"
exit 1
fi
if echo "$res" | grep -q "Successfully"; then
echo "微信推送成功"
else
echo "微信推送失败, res:$res"
fi
fi
fi