-
Notifications
You must be signed in to change notification settings - Fork 18
/
push.sh
124 lines (101 loc) · 2.69 KB
/
push.sh
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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/sh
BASE_ROOT=$(cd "$(dirname "$0")";pwd)
TOOLS_DIR=${BASE_ROOT}/tools
cd ${BASE_ROOT}
. ./user.conf
TITLE="$1"
DIGE="$2"
PIC_URL="$4"
function urlencode() {
if [ ! $? -eq 0 ]; then echo -E "$1";return; fi
encode_str=$(echo -E "$1" |sed "s/%/%%/g")
printf -- "$encode_str" | "${TOOLS_DIR}"/curl -Gso /dev/null -w %{url_effective} --data-urlencode @- "" |cut -c 3-
}
BARK_TITLE=$(echo $(urlencode ${TITLE}))
BARK_DIGE=$(echo $(urlencode ${DIGE}))
function qywx()
{
RET=$("${TOOLS_DIR}"/curl -s https://qyapi.weixin.qq.com/cgi-bin/gettoken?"corpid="${CORPID}"&corpsecret="${CORP_SECRET}"")
KEY=$(echo ${RET} | "${TOOLS_DIR}"/jq -r .access_token)
cat>tmp_qywx<<EOF
{
"touser" : "${TOUSER}",
"msgtype" : "news",
"agentid" : "${AGENTID}",
"news" : {
"articles":[
{
"title": "${TITLE}",
"description": "${DIGE}",
"picurl": "${PIC_URL}"
}
]
},
"enable_id_trans": 0,
"enable_duplicate_check": 0,
"duplicate_check_interval": 1800
}
EOF
"${TOOLS_DIR}"/curl -d @tmp_qywx -XPOST https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="${KEY}"
echo ""
echo "删除临时文件"
rm ${BASE_ROOT}/tmp_qywx
}
function pushplus()
{
echo "token:" "${PUSHPLUS_TOKEN}"
cat>tmp_pushplus<<EOF
{
"token": "${PUSHPLUS_TOKEN}",
"title": "${TITLE}",
"content": "${CONTENT}",
"template": "html",
"topic": "${PUSHPLUS_GROUP}",
"channel": "${PUSHPLUS_CHANNEL}"
}
EOF
echo $(cat tmp_pushplus)
"${TOOLS_DIR}"/curl --location --request POST 'http://www.pushplus.plus/send' \
-H 'Content-Type: application/json' \
-d @tmp_pushplus
rm ${BASE_ROOT}/tmp_pushplus
}
function bark()
{
BARK_URL="${BARK_PUSH_URL}/${BARK_KEY}/${BARK_TITLE}/${BARK_DIGE}"
"${TOOLS_DIR}"/curl --location --request GET "${BARK_URL}"
}
function telegram()
{
TG_URL='https://api.telegram.org/bot'${TG_TOKEN}'/sendMessage'
cat>tmp_tg<<EOF
{
"chat_id": "${TG_CHAT_ID}",
"text": "${TITLE}\n\n${DIGE}\n${PIC_URL}"
}
EOF
"${TOOLS_DIR}"/curl --location --request POST ${TG_URL} --header 'Content-Type: application/json' -d @tmp_tg
echo ""
echo "删除临时文件"
rm ${BASE_ROOT}/tmp_tg
}
if [ ! -n "${CORP_SECRET}" ]; then
echo "未配置企业微信参数或者配置不全,跳过通知!"
else
qywx
fi
if [ ! -n "${PUSHPLUS_TOKEN}" ]; then
echo "未配置pushplus参数,跳过通知!"
else
pushplus
fi
if [ ! -n "${BARK_KEY}" ]; then
echo "未配置Bark参数,跳过通知!"
else
bark
fi
if [ ! -n "${TG_TOKEN}" ]; then
echo "未配置电报参数或者配置不全,跳过通知!"
else
telegram
fi