Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更换PushPlus服务为WxPusher #18

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ jobs:
- run: npm run main
env:
GLADOS: ${{ secrets.GLADOS }}
NOTIFY: ${{ secrets.NOTIFY }}
WXPusherAppToken: ${{ secrets.WXPusherAppToken }}
WXPusherUIDS: ${{ secrets.WXPusherUIDS }}
15 changes: 8 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ const glados = async () => {
}

const notify = async (contents) => {
const token = process.env.NOTIFY
if (!token || !contents) return
await fetch(`https://www.pushplus.plus/send`, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

别直接删除,还有人在用

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议的写法:

用一个特殊标记, 区分是否使用 wxpusher, 如果没有标记, 则使用默认方式

const notify = async (contents) => {
  const token = process.env.NOTIFY
  if (!token || !contents) return
  if (token.startsWith('wxpusher:') {
  const [_, appToken, uids] = token.split(':')
  await fetch(`https://wxpusher.zjiecode.com/api/send/message`, {
    method: 'POST',
    headers: { 'content-type': 'application/json' },
    body: JSON.stringify({
      appToken,
      summary: contents[0],
      content: contents.join('<br>'),
      contentType: 3,
      uids: uids.split(','),
    }),
  })
  } else {
  await fetch(`https://www.pushplus.plus/send`, {
    method: 'POST',
    headers: { 'content-type': 'application/json' },
    body: JSON.stringify({
      token,
      title: contents[0],
      content: contents.join('<br>'),
      template: 'markdown',
    }),
  })
  }
}

配置格式: wxpusher:token:uids

const appToken = process.env.WXPusherAppToken
if (!appToken || !contents) return
await fetch(`https://wxpusher.zjiecode.com/api/send/message`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
token,
title: contents[0],
content: contents.join('<br>'),
template: 'markdown',
appToken,
'content': contents.join('<br>'),
'summary': 'GLADOS:' + contents[0],
'contentType': 3,
'uids': eval(process.env.WXPusherUIDS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

别用 eval, 用 split, 或者 JSON.parse

}),
})
}
Expand Down