Skip to content

Commit

Permalink
feat: pushplus 推送
Browse files Browse the repository at this point in the history
  • Loading branch information
vv314 committed Dec 1, 2021
1 parent cdc241b commit c90075c
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/grab-coupon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
# │ │ │ ┌──── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
- cron: '40 2 * * *'
- cron: '45 2 * * *'

jobs:
start:
Expand All @@ -39,3 +39,4 @@ jobs:
SC_SEND_KEY: ${{ secrets.SC_SEND_KEY }}
QYWX_SEND_CONF: ${{ secrets.QYWX_SEND_CONF }}
LARK_WEBHOOK: ${{ secrets.LARK_WEBHOOK }}
PUSHPLUS_TOKEN: ${{ secrets.PUSHPLUS_TOKEN }}
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

外卖神券天天领,超值红包享不停;以自动化的方式领取美团红包。

> ★ 专注领劵,不搞没用的<br/>★ 多帐号支持,全村都能配上<br/>★ 并行化任务,数管齐下更有效率<br/>★ 异常重试,一次不行再来一次<br/>★ 多路消息通知,总有一个到达你<br/>★ Github Actions 部署,从未如此简单
> ★ 专注领劵,不搞杂七杂八<br/>★ 多帐号支持,全村都能配上<br/>★ 并行化任务,数管齐下更有效率<br/>★ 异常重试,一次不行再来一次<br/>★ 多路消息通知,总有一个到达你<br/>★ Github Actions 部署,从未如此简单
## 一、📕 使用手册

Expand Down Expand Up @@ -57,13 +57,14 @@ Github Actions 工作流支持**手动**与**自动**两种触发方式

`TOKEN``JSON` 类型时,应包含以下属性:

| 属性名 | 类型 | 默认值 | 必填 | 说明 |
| ------- | ------ | ------ | ---- | ------------------------ |
| token | string | || 账号 token |
| alias | string | || 账号别名,便于区分多账户 |
| qywxUid | string | || 企业微信通知,用户 id |
| tgUid | string | || Telegram 通知,用户 id |
| barkKey | string | || Bark 通知,推送 Key |
| 属性名 | 类型 | 默认值 | 必填 | 说明 |
| ----------- | ------ | ------ | ---- | ------------------------ |
| token | string | || 账号 token |
| alias | string | || 账号别名,便于区分多账户 |
| qywxUid | string | || 企业微信通知,用户 id |
| tgUid | string | || Telegram 通知,用户 id |
| barkKey | string | || Bark 通知,推送 Key |
| larkWebhook | string | || 飞书通知,webhook 链接 |

_注意:企业微信通知需配置 `QYWX_SEND_CONF` Secret,Telegram 通知需配置 `TG_BOT_TOKEN` Secret,详见【消息通知】章节_

Expand Down Expand Up @@ -130,6 +131,7 @@ JSON 配置示例:
- Telegram
- 企业微信
- Server 酱
- pushplus

#### 1.3.1 Bark(仅 iOS 支持)

Expand Down Expand Up @@ -286,6 +288,14 @@ _已拥有企业微信应用?直接参考下节 **【配置企业应用】**_
2. 进入项目 "Settings" → "Secrets" 配置页,点击 `New repository secret`
- 新建 `SC_SEND_KEY` 项,填入 `SendKey`

#### 1.3.5 pushplus(仅支持全局通知)

[pushplus](https://www.pushplus.plus/) 推送加。是一个集成了微信、企业微信、钉钉、短信、邮件等渠道的信息推送平台。

1. 进入 [pushplus 官网](https://www.pushplus.plus/push1.html),登录后获取 pushplus `token`
2. 进入项目 "Settings" → "Secrets" 配置页,点击 `New repository secret`
- 新建 `PUSHPLUS_TOKEN` 项,填入 `token`

## 二、🔄 脚本更新

此项目将长期维护,为了确保副本能够及时享受到上游更新,请定期执行同步操作。
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const notifier = new Notifier({
larkWebhook: process.env.LARK_WEBHOOK,
workWechat: process.env.QYWX_SEND_CONF,
serverChanToken: process.env.SC_SEND_KEY,
pushplusToken: process.env.PUSHPLUS_TOKEN,
telegram: {
botToken: process.env.TG_BOT_TOKEN,
userId: process.env.TG_USER_ID
Expand Down
21 changes: 20 additions & 1 deletion lib/notifier/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
const sendBark = require('./vendor/bark')
const sendLark = require('./vendor/lark')
const sendServerChan = require('./vendor/server-chan')
const sendTelegram = require('./vendor/telegram')
const sendServerChan = require('./vendor/server-chan')
const sendPushplus = require('./vendor/pushplus')
const { sendWorkWechat, getQywxAccessToken } = require('./vendor/work-wechat')

class Notifier {
constructor(options) {
this.barkKey = options.barkKey
this.larkWebhook = options.larkWebhook
this.serverChanToken = options.serverChanToken
this.pushplusToken = options.pushplusToken
this.telegram = options.telegram
this.workWechat = null
this.qywxAccessToken = null
Expand Down Expand Up @@ -64,6 +66,7 @@ class Notifier {

/**
* 飞书通知
* https://www.feishu.cn/hc/zh-CN/articles/360040566333
*
* @param {String} title 标题
* @param {String} content 内容
Expand Down Expand Up @@ -123,6 +126,18 @@ class Notifier {
return sendServerChan({ title, content, token: this.serverChanToken })
}

/**
* pushplus 通知
* https://www.pushplus.plus/doc/guide/api.html
*
* @param {String} title 标题
* @param {String} content 内容
* @return {Promise<String>} 推送结果
*/
async sendPushplus(title = '', content = '') {
return sendPushplus({ title, content, token: this.pushplusToken })
}

/**
* 企业微信应用消息
* https://work.weixin.qq.com/api/doc/90000/90135/90236
Expand Down Expand Up @@ -184,6 +199,10 @@ class Notifier {
result.push(this.sendServerChan(title, content, options))
}

if (this.pushplusToken) {
result.push(this.sendPushplus(title, content, options))
}

return result
}
}
Expand Down
12 changes: 12 additions & 0 deletions lib/notifier/vendor/pushplus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { doPost } = require('../util')

async function sendPushplus({ title = '', content = '', token }) {
const url = `http://www.pushplus.plus/send`
const data = { token, title, content: content, template: 'txt' }

return doPost(url, data)
.then((res) => ({ success: true, msg: 'pushplus 推送成功' }))
.catch((e) => ({ success: false, msg: `pushplus 推送失败: ${e}` }))
}

module.exports = sendPushplus
9 changes: 4 additions & 5 deletions lib/parse-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ function tokenFormat(token, index = 0) {
index: index + 1,
tgUid: '',
qywxUid: '',
barkKey: ''
barkKey: '',
larkWebhook: ''
}

if (typeof token == 'string') {
Expand All @@ -18,10 +19,8 @@ function tokenFormat(token, index = 0) {
function parseToken(token) {
try {
token = JSON.parse(token)
console.log('传入的TOKEN变量是JSON对象')
} catch (e) {
console.log('传入的TOKEN变量是非JSON对象')
}
} catch (e) {}

const likeArray = token.constructor == Array
const likeObject = token.constructor == Object
let tokenList = []
Expand Down
6 changes: 5 additions & 1 deletion test/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const notifier = new Notifier({
larkWebhook: process.env.LARK_WEBHOOK,
workWechat: process.env.QYWX_SEND_CONF,
serverChanToken: process.env.SC_SEND_KEY,
pushplusToken: process.env.PUSHPLUS_TOKEN,
telegram: {
botToken: process.env.TG_BOT_TOKEN,
userId: process.env.TG_USER_ID
Expand All @@ -16,7 +17,10 @@ async function main() {

try {
const res = await Promise.all(
notifier.notify('推送测试', '这是推送测试的消息' + Date.now())
notifier.notify(
'推送测试',
`这是推送测试的消息:\n- 11111\n- 22222\n- ${Date.now()}`
)
)

console.log('result', res)
Expand Down

0 comments on commit c90075c

Please sign in to comment.