Skip to content

Commit

Permalink
Merge pull request #329 from wangxinleo/feature/develop
Browse files Browse the repository at this point in the history
fix(wechat-public-account-push): 紧急修复0504微信测试号模板整改
  • Loading branch information
wangxinleo committed May 5, 2023
2 parents ab6aa9e + fdde1aa commit ff7a038
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 20 deletions.
34 changes: 27 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ wechat-public-account-push

**微信团队于2023-05-04日晚12点下线【自定义颜色】、【emoji表情符号】、【自定义换行】、【尾部/备注字段】。**

**现已严重影响【微信测试号】的推送服务,目前正修复中...**
**【微信测试号】的推送服务已受到影响,原有的推送模板需要用户自行修改,详见 [如何修复因2023-05-04微信推送服务规范整改,导致推送服务异常](https://github.com/wangxinleo/wechat-public-account-push/issues/326)**

**使用服务号推送不受影响**

Expand Down Expand Up @@ -290,12 +290,32 @@ wechat-public-account-push 实现自消息推送的原理,是通过调用一

**计时类**

| 参数 | 详细 | 示例 |
|-----------------------|---------------------------|---------------------------------------------------------------|
| ~~love_day.DATA~~ | 已预置, 但是可以删掉, 在配置中自定义, 见下文 | 2674 |
| ~~marry_day.DATA~~ | 已预置, 但是可以删掉, 在配置中自定义, 见下文 | 965 |
| birthday_message.DATA | 生日消息和节日消息 | 距离 宝贝 的生日还有122天,距离 中秋节还有30天 |
| course_schedule.DATA | 每日的课表 | 08:00-09:35 高等数学<br/> 09:35-10:35 大学语文 <br/> 10:35-11:35 大学英语 |
| 参数 | 详细 | 示例 |
|---------------------------------------|---------------------------|---------------------------------------------------------------|
| ~~love_day.DATA~~ | 已预置, 但是可以删掉, 在配置中自定义, 见下文 | 2674 |
| ~~marry_day.DATA~~ | 已预置, 但是可以删掉, 在配置中自定义, 见下文 | 965 |
| birthday_message.DATA (**微信测试号无法使用**) | 生日消息和节日消息 | 距离 宝贝 的生日还有122天,距离 中秋节还有30天 |
| course_schedule.DATA (**微信测试号无法使用**) | 每日的课表 | 08:00-09:35 高等数学<br/> 09:35-10:35 大学语文 <br/> 10:35-11:35 大学英语 |


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

> 用法示例:
>
> 距离第1近的生日消息和节日消息请填写
>
> **wx_birthday_0.DATA** -> 距离 宝贝 的生日还有122天
>
> 第2节课请填写
>
> **wx_course_schedule_1.DATA** -> 08:00-09:35 高等数学
>
> (请确保在配置文件中设置了正确的天数)
| 参数 | 详细 | 示例 |
|---------------------------------|-------------------------|-------------------|
| wx_birthday_{index}.DATA | 距离第{index-1}近的生日消息和节日消息 | 距离 宝贝 的生日还有122天 |
| wx_course_schedule_{index}.DATA | 第{index-1}节课 | 08:00-09:35 高等数学 |

**天行简单API**

Expand Down
49 changes: 36 additions & 13 deletions src/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const getAccessToken = async () => {
console.log('---')
} else {
console.log('---')
console.error('获取 accessToken: 请求失败', res.data.errmsg)
console.error('获取 accessToken: 请求失败', res.data.errmsg || res.data)
console.log('---')
console.log(`40001: 请检查appId,appSecret 填写是否正确;
如果第一次使用微信测试号请关闭测试号平台后重新扫码登陆测试号平台获取最新的appId,appSecret`)
Expand Down Expand Up @@ -426,7 +426,7 @@ export const getConstellationFortune = async (date, dateType) => {
/**
* 获取课程表
* @param courseSchedule {Array<Array<String>>|{benchmark: {date: string, isOdd: boolean}, courses: {odd: Array<Array<string>>, even:Array<Array<string>>}}}
* @returns {string}
* @returns
*/
export const getCourseSchedule = (courseSchedule) => {
if (config.SWITCH && config.SWITCH.courseSchedule === false) {
Expand All @@ -446,7 +446,19 @@ export const getCourseSchedule = (courseSchedule) => {
.set('millisecond', 0), 'millisecond')
const isSameKind = Math.floor(diff / 7 / 86400000) % 2 === 0
const kind = ((isSameKind && courseSchedule.benchmark.isOdd) || (!isSameKind && !courseSchedule.benchmark.isOdd)) ? 'odd' : 'even'
return ((courseSchedule.courses && courseSchedule.courses[kind] && courseSchedule.courses[kind][week]) || []).join(getLB())

const temp = ((courseSchedule.courses && courseSchedule.courses[kind] && courseSchedule.courses[kind][week]) || [])
const schedule = temp.join(getLB())
const wechatTestCourseSchedule = []
temp.forEach((item, index) => {
wechatTestCourseSchedule.push({
name: toLowerLine(`wxCourseSchedule_${index}`),
value: item,
color: getColor()
})
})

return {schedule, wechatTestCourseSchedule}
}

/**
Expand Down Expand Up @@ -502,6 +514,8 @@ export const getBirthdayMessage = (festivals) => {
}
})
let resMessage = ''
const wechatTestBirthdayMessage = []


birthdayList.forEach((item, index) => {
if (
Expand All @@ -521,29 +535,34 @@ export const getBirthdayMessage = (festivals) => {
}

if (item.diffDay === 0) {
message = `今天是 ${item.name}${age && item.isShowAge ? `${(item.useLunar ? 1 : 0) + age}岁` : ''}生日哦,祝${item.name}生日快乐!`
message = `今天是 ${item.name}${age && item.isShowAge ? `${(item.useLunar ? 1 : 0) + age}岁` : ''}${item.useLunar ? '阴历' : '公历'}生日哦,祝${item.name}生日快乐!`
} else {
message = `距离 ${item.name}${age && item.isShowAge ? `${age + 1}岁` : ''}生日还有${item.diffDay}天`
message = `距离 ${item.name}${age && item.isShowAge ? `${age + 1}岁` : ''}${item.useLunar ? '阴历' : '公历'}生日还有${item.diffDay}天`
}
}

// 节日相关
if (item.type === '节日') {
if (item.diffDay === 0) {
message = `今天是 ${item.name} 哦,要开心!`
message = `今天是 ${item.name} 哦,要开心!`
} else {
message = `距离 ${item.name} 还有${item.diffDay}天`
message = `距离 ${item.name} 还有${item.diffDay}天`
}
}

// 存储数据
if (message) {
resMessage += `${message} ${getLB()}`
wechatTestBirthdayMessage.push({
name: toLowerLine(`wxBirthday_${index}`),
value: message,
color: getColor()
})
}
}
})

return resMessage
return {resMessage, wechatTestBirthdayMessage}
}

/**
Expand Down Expand Up @@ -732,13 +751,13 @@ export const getAggregatedData = async () => {
}))

// 获取生日/生日信息
const birthdayMessage = getBirthdayMessage(user.festivals)
const { resMessage: birthdayMessage, wechatTestBirthdayMessage } = getBirthdayMessage(user.festivals)

// 获取星座运势
const constellationFortune = await getConstellationFortune(user.horoscopeDate, user.horoscopeDateType)

// 获取课表信息
const courseSchedule = getCourseSchedule(user.courseSchedule || config.courseSchedule) || DEFAULT_OUTPUT.courseSchedule
const {schedule:courseSchedule, wechatTestCourseSchedule} = getCourseSchedule(user.courseSchedule || config.courseSchedule) || DEFAULT_OUTPUT.courseSchedule

// 天行-早晚安
const tianApiGreeting = [{
Expand Down Expand Up @@ -795,6 +814,8 @@ export const getAggregatedData = async () => {
.concat(tianApiGreeting)
.concat(tianApiWeather)
.concat(tianApiNetworkHot)
.concat(wechatTestBirthdayMessage)
.concat(wechatTestCourseSchedule)

user.wxTemplateParams = wxTemplateParams
}
Expand Down Expand Up @@ -1084,9 +1105,11 @@ export const sendMessage = async (templateId, user, params, usePassage) => {
const wxTemplateData = {}
if (Object.prototype.toString.call(params) === '[object Array]') {
params.forEach((item) => {
wxTemplateData[item.name] = {
value: item.value,
color: item.color,
if (item && item.name) {
wxTemplateData[item.name] = {
value: item.value,
color: item.color,
}
}
})
}
Expand Down

0 comments on commit ff7a038

Please sign in to comment.