Skip to content

Commit

Permalink
feat(wechat-public-account-push): 增加push-plus推送方式
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxinleo committed Oct 22, 2022
1 parent bbec0ec commit 266118c
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 1 deletion.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ wechat-public-account-push 实现自消息推送的原理,是通过调用一

**其他通道**

> 免费版每个接收用户每天允许推送200条消息,付费版每个接收用户每天1000条
>
> 1分钟内接收5次请求,超出的请求将不再推送。另外对于相同的内容,1小时内限制发送3条。
>
> 消息推送时显示的是 **设备通知**,标题需要**进入公众号查看**
>
> 消息放置在消息列表,方便随时查看
>
> 不再是xxxx测试号,而是推送加服务号,更美观
>
> 此通道[可能会被腾讯弃用](https://developers.weixin.qq.com/community/minihome/doc/000a46c7eb8468ba1a1cc863e51401),请评估风险后再选择
>
[⭐pushplus推送加服务号 >>> 点击使用](./docs/message-channel/push-plus.md)

> 免费版每个接收用户每天允许推送5条消息,付费版每个接收用户每天1000条
>
> 消息推送时显示的是 **设备通知**,标题需要**进入公众号查看**
Expand Down Expand Up @@ -172,6 +187,8 @@ wechat-public-account-push 实现自消息推送的原理,是通过调用一

[❓配置自动生成 教程 >>>](https://github.com/shuangxunian/wechat-form)

[❓配置完成后如何手动运行或者更改自动运行时间? 点开链接查看4. 5. >>>](./docs/how-to-use/github-actions.md)

#### 1.2.2 方式二:使用Github-Action(不准时,排队执行,胜在免费)
> 世界上最大的同性交友平台(不是),需要一定的英语基础,**编辑的时候请不要使用网页的自动翻译**
Expand Down
3 changes: 2 additions & 1 deletion docs/how-to-use/config-demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ const USER_CONFIG = {
* 基本配置
*/

// 使用的推送通道:['push-deer', 'wechat-test', 'server-chan']
// 使用的推送通道:['push-deer', 'wechat-test', 'server-chan', 'push-plus']
// 默认使用 【微信测试号】
// 使用【pushDeer】请填写 push-deer
// 使用【微信测试号】请填写 wechat-test
// 使用【方糖服务号】请填写 server-chan
// 使用【pushplus推送加服务号】请填写 push-plus
USE_PASSAGE: 'wechat-test',

// 使用微信测试号时才需要填写:公众号APP_ID
Expand Down
63 changes: 63 additions & 0 deletions docs/message-channel/push-plus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[📌返回首页 >>>](../../README.md)

# 使用PushDeer

运行图示:

![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/message-channel/server-chan3.jpg)

![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/message-channel/server-chan4.jpg)

![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/message-channel/server-chan2.jpg)

![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/message-channel/push-plus.png)

## Ⅰ. 注册并使用push-plus服务

- 浏览器打开并登录 [push-plus首页](https://www.pushplus.plus/login.html)

![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/message-channel/use-push-plus.png)

![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/message-channel/use-push-plus-2.png)

- 复制你的token保存备用

![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/message-channel/use-push-plus-4.png)

## Ⅱ. 进行模板配置

仓库`config/template-config.cjs` 已内置两个模板,可以根据个人需求进行相应修改

> 模板中{{***.DATA}}都对应相应的数据,需要就保留,不需要就删掉
![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/message-channel/template-config.png)

## Ⅲ. 进行基础config配置

### 打开仓库中`config/index.cjs`的进行,进行编辑

![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/how-to-use/github-into-config.png)

![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/how-to-use/github-into-config-2.png)

![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/how-to-use/github-into-config-3.png)

### 1. 使用push-plus模式
```javascript
// 请将以下代码按照图示粘贴到对应位置
USE_PASSAGE: 'push-plus',
```
![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/message-channel/use-push-plus-3.png)

### 2. 你的token填到哪里?

![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/message-channel/use-push-deer.png)

### 3. Ⅲ. 中的模板id填到哪里?

![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/message-channel/use-push-deer2.png)


**以上步骤完成后请返回首页继续进行后续操作**

[📌返回首页 >>>](../../README.md)
Binary file added img/message-channel/push-plus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/message-channel/use-push-plus-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/message-channel/use-push-plus-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/message-channel/use-push-plus-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/message-channel/use-push-plus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions src/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,50 @@ const sendMessageByPushDeer = async (user, templateId, wxTemplateData) => {
}
}

/**
* 使用pushplus
* @param user
* @param templateId
* @param wxTemplateData
* @returns {Promise<{success: boolean, name}>}
*/
const sendMessageByPushPlus = async (user, templateId, wxTemplateData) => {
// 模板拼装
const modelData = model2Data(templateId, wxTemplateData, false, false)
if (!modelData) {
return {
name: user.name,
success: false,
}
}

const url = 'http://www.pushplus.plus/send'
// 发送消息
const res = await axios.post(url, {
token: user.id,
title: modelData.title,
content: modelData.desc,
template: 'markdown',
}, {
headers: {
'Content-Type': 'application/json',
},
}).catch((err) => err)

if (res.data && res.data.code === 200) {
console.log(`${user.name}: 推送消息成功`)
return {
name: user.name,
success: true,
}
}
console.error(`${user.name}: 推送消息失败`, res)
return {
name: user.name,
success: false,
}
}

/**
* 使用server-chan
* @param user
Expand Down Expand Up @@ -1019,6 +1063,9 @@ export const sendMessage = async (templateId, user, params, usePassage) => {
} if (usePassage === 'server-chan') {
console.log('使用server-chan推送')
return sendMessageByServerChan(user, templateId, wxTemplateData)
} if (usePassage === 'push-plus') {
console.log('使用push-plus推送')
return sendMessageByPushPlus(user, templateId, wxTemplateData)
}

console.log('使用微信测试号推送')
Expand Down

0 comments on commit 266118c

Please sign in to comment.