Skip to content

Commit

Permalink
feat(wechat-public-account-push): 增加server-chan推送方式
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxinleo committed Oct 11, 2022
1 parent 1e1dba9 commit 9e27d7c
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 25 deletions.
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,28 @@ wechat-public-account-push 实现自消息推送的原理,是通过调用一

**其他通道**

> 测试号的标题不能修改为自定义的名称,不能修改测试号的头像
>
> 推送的消息必须要点进订阅号才能收到
>
> 每次要修改内容必须要自定义模版
>
> 此通道[可能会被腾讯弃用](https://developers.weixin.qq.com/community/minihome/doc/000a46c7eb8468ba1a1cc863e51401),请评估风险后再选择
[⭐微信测试号 >>> 点击使用](./docs/message-channel/test-number.md)

> 免费用户每天允许推送5条消息,付费用户每天1000条
> 免费版每个接收用户每天允许推送5条消息,付费版每个接收用户每天1000条
>
> 消息推送时显示的是 **设备通知**,标题需要**进入公众号查看**
>
> 消息放置在消息列表,方便随时查看
>
> 不再是xxxx测试号,而是方糖服务号,更美观
>
> 此通道[可能会被腾讯弃用](https://developers.weixin.qq.com/community/minihome/doc/000a46c7eb8468ba1a1cc863e51401),请评估风险后再选择
>
[⭐server酱服务号 >>> 点击使用](./docs/message-channel/server-chan.md)

> 测试号的标题**不能**修改为自定义的名称,**不能**修改测试号的头像
>
> 推送的消息必须要点进订阅号才能收到
>
> 每次要修改内容必须要自定义模版
>
> 此通道[可能会被腾讯弃用](https://developers.weixin.qq.com/community/minihome/doc/000a46c7eb8468ba1a1cc863e51401),请评估风险后再选择
⭐server酱服务号 >>>(接入中)
[⭐微信测试号 >>> 点击使用](./docs/message-channel/test-number.md)

> 2022年6月20日后创建的应用需要填写可信IP,且可信IP不可公用,因此新应用无法按此配置通道
>
Expand All @@ -157,7 +159,7 @@ wechat-public-account-push 实现自消息推送的原理,是通过调用一

### 1.2. 第二步:完成配置文件,并运行wechat-public-account-push

#### 1.2.1 方式一:使用网页工具自动生成Github-Action配置(不准时,排队执行,胜在免费)
#### 1.2.1 方式一:(可能仅支持微信测试号)使用网页工具自动生成Github-Action配置(不准时,排队执行,胜在免费)

> 以下为@shuangxunian ShuangxuNian大佬 提供的网页配置插件
>
Expand Down
23 changes: 11 additions & 12 deletions docs/message-channel/push-deer.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,49 +36,48 @@
## Ⅱ. 配置PushDeer

1. 通过apple账号(或微信账号·仅Android版支持)登录
### 1. 通过apple账号(或微信账号·仅Android版支持)登录
![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/message-channel/push-deer-app1.jpg)

2. 切换到「设备」标签页,点击右上角的加号,注册当前设备
### 2. 切换到「设备」标签页,点击右上角的加号,注册当前设备
![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/message-channel/push-deer-app2.jpg)

3. 切换到「Key」标签页,点击右上角的加号,创建一个Key
### 3. 切换到「Key」标签页,点击右上角的加号,创建一个Key
![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/message-channel/push-deer-app3.jpg)

4. 保存好 Key ,等会儿在第二步中需要用到
### 4. 保存好 Key ,等会儿在第二步中需要用到



## Ⅲ. 进行模板配置

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

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

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

## Ⅳ. 进行基础config配置

打开仓库中`config/index.cjs`的进行,进行编辑
### 打开仓库中`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. 使用pushdeer模式
### 1. 使用pushdeer模式
```javascript
// 请将以下代码按照图示粘贴到对应位置
USE_PASSAGE: 'push-deer',
```
![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/message-channel/use-push-deer4.png)

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

2. KEY填到哪里?
### 2. KEY填到哪里?

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

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

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

Expand Down
61 changes: 61 additions & 0 deletions docs/message-channel/server-chan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[📌返回首页 >>>](../../README.md)

# 使用PushDeer

运行图示:

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

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

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

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

## Ⅰ. 注册并使用server-chan服务

- 浏览器打开并登录 [server-chan首页](https://sct.ftqq.com/login)

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

- 复制SendKey保存备用

![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/message-channel/use-server-chan2.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. 使用server-chan模式
```javascript
// 请将以下代码按照图示粘贴到对应位置
USE_PASSAGE: 'server-chan',
```
![图片无法查看请移步顶部访问 国内备用仓库地址](../../img/message-channel/use-server-chan3.png)

### 2. KEY填到哪里?

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

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

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


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

[📌返回首页 >>>](../../README.md)
Binary file added img/message-channel/server-chan.jpg
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/server-chan2.jpg
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/server-chan3.jpg
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/server-chan4.jpg
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/template-config.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-server-chan.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-server-chan2.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-server-chan3.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-server-chan4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions src/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,34 @@ const sendMessageByPushDeer = async (user, templateId, wxTemplateData) => {
}
}

const sendMessageByServerChan = async (user, templateId, wxTemplateData) => {
// 模板拼装
const modelData = model2Data(templateId, wxTemplateData, true, true)
if (!modelData) {
return {
name: user.name,
success: false,
}
}

const url = `https://sctapi.ftqq.com/${user.id}.send?title=${modelData.title}&desp=${modelData.desc}`
// 发送消息
const res = await axios.get(url).catch((err) => err)

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

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

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

0 comments on commit 9e27d7c

Please sign in to comment.