Skip to content

Commit

Permalink
Merge pull request #352 from wangxinleo/feature/develop
Browse files Browse the repository at this point in the history
feat(wechat-public-account-push): 常用字段拆分适配微信推送
  • Loading branch information
wangxinleo committed Aug 29, 2023
2 parents 545d220 + 8cb66b3 commit d31c02b
Show file tree
Hide file tree
Showing 2 changed files with 205 additions and 30 deletions.
73 changes: 59 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ wechat-public-account-push 实现自消息推送的原理,是通过调用一
| province.DATA | 省份 | 广东 |
| city.DATA | 城市 | 惠州 |

**天气类**
**天气类(由于是免费接口,服务器并不稳定会拿不到数据,推荐使用下方的天行接口)**

| 参数 | 详细 | 示例 |
|----------------------|--------|------------------------------------|
Expand All @@ -260,33 +260,78 @@ wechat-public-account-push 实现自消息推送的原理,是通过调用一
**节假日**
| 参数 | 详细 | 示例 |
|------------------------|----------------|----------------|
| holidaytts.DATA | 下一休息日综合提醒 | 还有3天就周六了,好好工作吧!距离国庆还有18天,早着呢 |
| holidaytts.DATA (**微信测试号无法使用**) | 下一休息日综合提醒 | 还有3天就周六了,好好工作吧!距离国庆还有18天,早着呢 |

`{index}`替换为要显示的第N-1个

> 用法示例:
>
> 为了能在微信推送中使用,长文本被截取成20个字符每段
>
> **wx_holidaytts_0.DATA** -> 今天是工作日啊~距离下个周六,还有3天;
>
> **wx_holidaytts_1.DATA** -> 距离最近的一个节日是9月29日的中秋节,
>
> ...
>
> **wx_holidaytts_999.DATA**
>
| 参数 | 详细 | 示例 |
|---------------------------------|-------------------------|-------------------|
| wx_holidaytts_{index}.DATA | 下一休息日综合提醒 | 还有3天就周六了,好好工作吧!距离国庆还有18天,早着呢 |

**每日N句**

| 参数 | 详细 | 示例 |
|--------------------------|-----------|-------------------------------------------------------|
| note_en.DATA | 金山每日一句-英文 | Nothing in this world that's worth having comes easy. |
| note_ch.DATA | 金山每日一句-中文 | 这世界上凡是值得拥有的东西,都不易获得。 |
| one_talk.DATA | 每日一言-内容 | 愿你遍布祖国山河,觉得人生也值得 |
| note_en.DATA (**微信测试号无法使用**) | 金山每日一句-英文 | Nothing in this world that's worth having comes easy. |
| note_ch.DATA (**微信测试号无法使用**) | 金山每日一句-中文 | 这世界上凡是值得拥有的东西,都不易获得。 |
| one_talk.DATA (**微信测试号无法使用**) | 每日一言-内容 | 愿你遍布祖国山河,觉得人生也值得 |
| talk_from.DATA | 每日一言-来源 | 晓良 |
| earthy_love_words.DATA | 土味情话(彩虹屁) | 我今晚会很忙,忙着跟你过日子 |
| moment_copyrighting.DATA | 朋友圈文案 | 错过太阳就不要再错过月亮了 |
| poison_chicken_soup.DATA | 毒鸡汤 | 我从不以强凌弱,我欺负他之前,真不晓得他比我弱。 |
| poetry_content.DATA | 古诗古文-内容 | 举头望明月,低头思故乡。 |
| earthy_love_words.DATA (**微信测试号无法使用**) | 土味情话(彩虹屁) | 我今晚会很忙,忙着跟你过日子 |
| moment_copyrighting.DATA (**微信测试号无法使用**) | 朋友圈文案 | 错过太阳就不要再错过月亮了 |
| poison_chicken_soup.DATA (**微信测试号无法使用**) | 毒鸡汤 | 我从不以强凌弱,我欺负他之前,真不晓得他比我弱。 |
| poetry_content.DATA (**微信测试号无法使用**) | 古诗古文-内容 | 举头望明月,低头思故乡。 |
| poetry_title.DATA | 古诗古文-标题 | 静夜思 |
| poetry_author.DATA | 古诗古文-作者 | 李白 |
| poetry_dynasty.DATA | 古诗古文-朝代 | 唐代 |


`{index}`替换为要显示的第N-1个

> 用法示例:
>
> 为了能在微信推送中使用,长文本被截取成20个字符每段
>
> **wx_one_talk_0.DATA** -> 风起,花飘零,梦醒时分,却有几多愁,上
>
> **wx_one_talk_1.DATA** -> 心头。
>
> ...
>
> **wx_one_talk_999.DATA**
>
| 参数 | 详细 | 示例 |
|---------------------------------|-------------------------|-------------------|
| wx_note_en_{index}.DATA | 金山每日一句-英文 | Nothing in this world that's worth having comes easy. |
| wx_note_ch_{index}.DATA | 金山每日一句-中文 | 这世界上凡是值得拥有的东西,都不易获得。 |
| wx_one_talk_{index}.DATA | 每日一言-内容 | 愿你遍布祖国山河,觉得人生也值得 |
| wx_earthy_love_words_{index}.DATA | 土味情话(彩虹屁) | 我今晚会很忙,忙着跟你过日子 |
| wx_moment_copyrighting_{index}.DATA | 朋友圈文案 | 错过太阳就不要再错过月亮了 |
| wx_poison_chicken_soup_{index}.DATA | 毒鸡汤 | 我从不以强凌弱,我欺负他之前,真不晓得他比我弱。 |
| wx_poetry_content_{index}.DATA | 古诗古文-内容 | 举头望明月,低头思故乡。 |

**星座运势**

| 参数 | 详细 | 示例 |
|------------------------------|------|-------------------|
| comprehensive_horoscope.DATA | 综合运势 | 太多了,不示例了,自己调用查看效果 |
| love_horoscope.DATA | 爱情运势 | 太多了,不示例了,自己调用查看效果 |
| career_horoscope.DATA | 事业学业 | 太多了,不示例了,自己调用查看效果 |
| wealth_horoscope.DATA | 财富运势 | 太多了,不示例了,自己调用查看效果 |
| healthy_horoscope.DATA | 健康运势 | 太多了,不示例了,自己调用查看效果 |
| comprehensive_horoscope.DATA (**微信测试号无法使用**) | 综合运势 | 太多了,不示例了,自己调用查看效果 |
| love_horoscope.DATA (**微信测试号无法使用**) | 爱情运势 | 太多了,不示例了,自己调用查看效果 |
| career_horoscope.DATA (**微信测试号无法使用**) | 事业学业 | 太多了,不示例了,自己调用查看效果 |
| wealth_horoscope.DATA (**微信测试号无法使用**) | 财富运势 | 太多了,不示例了,自己调用查看效果 |
| healthy_horoscope.DATA (**微信测试号无法使用**) | 健康运势 | 太多了,不示例了,自己调用查看效果 |

**计时类**

Expand Down
162 changes: 146 additions & 16 deletions src/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,34 @@ export const getCIBA = async () => {
}).catch((err) => err)

if (res.status === 200 && res) {
return res.data
const data = res.data
const keys = [{
from: 'content',
to: 'note_en'
}, {
from: 'note',
to: 'note_ch'
}]
keys.forEach(obj => {
const value = data[obj.from]
const arr = []
for (let j = 0, i = 0; j < value.length; j += 20) {
arr.push({
name: `wx_${obj.to}_${i}`,
value: value.slice(j, j + 20),
color: getColor()
})
i++
}
data[`wx_${obj.to}`] = arr
})

return {
noteEn: data['content'],
wxNoteEn: data['wx_note_en'],
noteCh: data['note'],
wxNoteCh: data['wx_note_ch'],
}
}
console.error('金山词霸每日一句: 发生错误', res)
return {}
Expand All @@ -201,12 +228,28 @@ export const getHolidaytts = async () => {

const url = 'https://wangxinleo.cn/api/wx-push/holiday/getHolidaytts'
const res = await axios.get(url).catch((err) => err)
let data = DEFAULT_OUTPUT.holidaytts

if (res.status === 200 && res.data && res.data.code === 0) {
return res.data.tts
data = res.data.tts
} else {
console.error('获取下一休息日tts: 发生错误', res)
}

const arr = []
for (let j = 0, i = 0; j < data.length; j += 20) {
arr.push({
name: `wx_holidaytts_${i}`,
value: data.slice(j, j + 20),
color: getColor()
})
i++
}

return {
holidaytts: data,
wxHolidaytts: arr
}
console.error('获取下一休息日tts: 发生错误', res)
return null
}

/**
Expand All @@ -226,7 +269,25 @@ export const getOneTalk = async (type) => {
const res = await axios.get(url).catch((err) => err)

if (res && res.status === 200) {
return res.data
const data = res.data
const keys = [{
from: 'hitokoto',
to: 'one_talk'
}]
keys.forEach(obj => {
const value = data[obj.from]
const arr = []
for (let j = 0, i = 0; j < value.length; j += 20) {
arr.push({
name: `wx_${obj.to}_${i}`,
value: value.slice(j, j + 20),
color: getColor()
})
i++
}
data[`wx_${obj.to}`] = arr
})
return data
}

console.error('每日一言: 发生错误', res)
Expand Down Expand Up @@ -268,7 +329,23 @@ export const getEarthyLoveWords = async () => {
if (config.SWITCH && config.SWITCH.earthyLoveWords === false) {
return ''
}
return getWordsFromApiShadiao('chp')

const data = await getWordsFromApiShadiao('chp') || DEFAULT_OUTPUT.earthyLoveWords

const arr = []
for (let j = 0, i = 0; j < data.length; j += 20) {
arr.push({
name: `wx_earthy_love_words_${i}`,
value: data.slice(j, j + 20),
color: getColor()
})
i++
}

return {
earthyLoveWords: data,
wxEarthyLoveWords: arr
}
}

/**
Expand All @@ -279,8 +356,22 @@ export const getMomentCopyrighting = async () => {
if (config.SWITCH && config.SWITCH.momentCopyrighting === false) {
return ''
}
const data = await getWordsFromApiShadiao('pyq') || DEFAULT_OUTPUT.momentCopyrighting

return getWordsFromApiShadiao('pyq')
const arr = []
for (let j = 0, i = 0; j < data.length; j += 20) {
arr.push({
name: `wx_moment_copyrighting_${i}`,
value: data.slice(j, j + 20),
color: getColor()
})
i++
}

return {
momentCopyrighting: data,
wxMomentCopyrighting: arr
}
}

/**
Expand All @@ -292,7 +383,22 @@ export const getPoisonChickenSoup = async () => {
return ''
}

return getWordsFromApiShadiao('du')
const data = await getWordsFromApiShadiao('du') || DEFAULT_OUTPUT.poisonChickenSoup

const arr = []
for (let j = 0, i = 0; j < data.length; j += 20) {
arr.push({
name: `wx_poison_chicken_soup_${i}`,
value: data.slice(j, j + 20),
color: getColor()
})
i++
}

return {
poisonChickenSoup: data,
wxPoisonChickenSoup: arr
}
}

/**
Expand All @@ -317,10 +423,22 @@ export const getPoetry = async () => {
console.error('古诗古文:发生错误', warning || '')
return {}
}
const { content = '', origin } = data || {}
const { content = DEFAULT_OUTPUT.poetryContent, origin } = data || {}

const wxContent = []
for (let j = 0, i = 0; j < content.length; j += 20) {
wxContent.push({
name: `wx_poetry_content_${i}`,
value: content.slice(j, j + 20),
color: getColor()
})
i++
}

const { title = '', author = '', dynasty = '' } = origin || {}
return {
content,
wxContent,
title,
author,
dynasty,
Expand Down Expand Up @@ -701,28 +819,32 @@ export const getAggregatedData = async () => {
const weekList = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
// 获取金山词霸每日一句
const {
content: noteEn = DEFAULT_OUTPUT.noteEn,
note: noteCh = DEFAULT_OUTPUT.noteCh,
noteEn = DEFAULT_OUTPUT.noteEn,
wxNoteEn = '',
noteCh = DEFAULT_OUTPUT.noteCh,
wxNoteCh = ''
} = await getCIBA()
// 获取下一休息日
const holidaytts = await getHolidaytts() || DEFAULT_OUTPUT.holidaytts
const {holidaytts, wxHolidaytts} = await getHolidaytts()
// 获取每日一言
const {
hitokoto: oneTalk = DEFAULT_OUTPUT.oneTalk,
wx_one_talk: wxOneTalk = '',
from: talkFrom = DEFAULT_OUTPUT.talkFrom,
} = await getOneTalk(config.LITERARY_PREFERENCE)
// 获取土味情话
const earthyLoveWords = await getEarthyLoveWords() || DEFAULT_OUTPUT.earthyLoveWords
const {earthyLoveWords, wxEarthyLoveWords} = await getEarthyLoveWords()
// 获取朋友圈文案
const momentCopyrighting = await getMomentCopyrighting() || DEFAULT_OUTPUT.momentCopyrighting
const {momentCopyrighting, wxMomentCopyrighting} = await getMomentCopyrighting()
// 获取毒鸡汤
const poisonChickenSoup = await getPoisonChickenSoup() || DEFAULT_OUTPUT.poisonChickenSoup
const {poisonChickenSoup, wxPoisonChickenSoup} = await getPoisonChickenSoup()
// 获取古诗古文 poetry
const {
dynasty: poetryDynasty = DEFAULT_OUTPUT.poetryDynasty,
author: poetryAuthor = DEFAULT_OUTPUT.poetryAuthor,
title: poetryTitle = DEFAULT_OUTPUT.poetryTitle,
content: poetryContent = DEFAULT_OUTPUT.poetryContent,
content: poetryContent,
wxContent: wxPoetryContent
} = await getPoetry()
// 获取插槽中的数据
const slotParams = getSlotList().map((item) => ({ name: item.keyword, value: item.checkout, color: getColor() }))
Expand Down Expand Up @@ -816,6 +938,14 @@ export const getAggregatedData = async () => {
.concat(tianApiNetworkHot)
.concat(wechatTestBirthdayMessage)
.concat(wechatTestCourseSchedule)
.concat(wxNoteEn)
.concat(wxNoteCh)
.concat(wxOneTalk)
.concat(wxEarthyLoveWords)
.concat(wxMomentCopyrighting)
.concat(wxPoisonChickenSoup)
.concat(wxPoetryContent)
.concat(wxHolidaytts)

user.wxTemplateParams = wxTemplateParams
}
Expand Down

0 comments on commit d31c02b

Please sign in to comment.