feat(微信订阅): 接入歌曲排期模板并加固部署流程

订阅消息(小程序侧唯一能主动触达用户的通道):
- 新增 server/utils/wechatSubscribeFields.ts:按微信字段类型裁剪值(thing≤20、
  phrase 必须 5 个汉字、time/date/character_string 各自上限),空白压成一行,
  北京时间 time 由 playTime 的开始时间生成,解析不出退化为当天 00:00。
- wechatSubscribeService 内置 SONG_SELECTED 模板(站长新给的那个模板 ID),
  并转发上述纯函数;notificationService.createSongSelectedNotification 现在会带上
  playDate/playTime/sequence,三个排期接口(schedule / publish / bulk-publish)补传 sequence。
- 新增 test/wechatSubscribeFields.test.mjs(10 例,node --test 全绿)。
- test-subscribe 管理接口支持 vars 覆盖并返回真实发送值,方便站长核对字段名。

部署流程(Gitea Actions 容器里没有 buildx 插件,旧流程在此硬失败):
- 每个 job 各自安装/探测 docker-buildx(v0.19.3,走 gh-proxy 再退直连),
  不把 `buildx version` 当唯一依据;装不上时降级为普通 `docker build` 继续发布,
  不再因为缺插件整条流水线失败。

注意:SONG_SELECTED 的字段名(thing2/date4/time1/character_string3/phrase5)是按常见
命名推断的,需在公众平台后台核对;不一致时用环境变量覆盖,模板 ID 变更后老用户需重新授权。
This commit is contained in:
2026-10-11 00:04:14 +08:00
parent ebf1c3a127
commit 3eff710d5d
31 changed files with 659 additions and 189 deletions
+20 -2
View File
@@ -12,7 +12,7 @@ import {
} from '~/drizzle/schema'
import { and, eq, gte, inArray } from 'drizzle-orm'
import { sendBatchMeowNotifications, sendMeowNotificationToUser } from './meowNotificationService'
import { sendWechatSubscribeToUser } from './wechatSubscribeService'
import { buildWechatTimeValue, sendWechatSubscribeToUser } from './wechatSubscribeService'
import { sendBatchEmailNotifications, sendEmailNotificationToUser } from './smtpService'
import { formatDateTime, getBeijingTime } from '~/utils/timeUtils'
@@ -122,6 +122,8 @@ export async function createSongSelectedNotification(
title: string
artist: string
playDate: Date
/** 排期在该时段里的序号(微信「歌曲排期」模板的排期序号字段用) */
sequence?: number | null
},
ipAddress?: string
) {
@@ -207,7 +209,23 @@ export async function createSongSelectedNotification(
}
// 同步发送 微信订阅消息(只有绑了微信、且刚点过授权的用户收得到,见 wechatSubscribeService)
try {
await sendWechatSubscribeToUser(userId, 'SONG_SELECTED', { songTitle: songInfo.title, message })
/*
* 微信模板字段比站内通知挑数据:thing/date/time/character_string 各有格式要求,
* 空值或格式不对会让**整条**订阅消息被拒(47003),所以这里把每个字段都算好再传。
*/
const playTime = isPlayTimeEnabled && schedule?.playTime ? schedule.playTime : null
await sendWechatSubscribeToUser(userId, 'SONG_SELECTED', {
songTitle: songInfo.title,
// date 型:'YYYY-MM-DD'
playDate: formatDate(songInfo.playDate),
// time 型:'YYYY-MM-DD HH:mm',有排期时段就取它的开始时间('12:30-13:00' 也能解析)
playTime: buildWechatTimeValue(songInfo.playDate, playTime?.startTime || playTime?.endTime),
// phrase 型:5 个以内纯汉字;“已排期”只有 3 个字,clampField 会补全角空格
status: '已排期',
// character_string 型:只允许数字/字母,没有序号时不传(避免空值 47003)
sequence: songInfo.sequence == null ? undefined : String(songInfo.sequence),
message
})
} catch (error) {
console.error('发送微信订阅消息失败:', error)
}