feat: 订阅消息通知体系——登录后请求订阅授权(额度记账)+服务端subscribe/send(access_token缓存/原子扣减/失败回补/发送记录)+管理后台通知推送页;版本v1.4.4

This commit is contained in:
Hermes Agent
2026-09-19 19:28:40 +08:00
parent 9ea09c95f2
commit 6d463b9296
11 changed files with 297 additions and 4 deletions
+20
View File
@@ -0,0 +1,20 @@
const mongoose = require('mongoose')
const { Schema } = mongoose
/**
* 订阅消息发送记录
*/
const NotifyLogSchema = new Schema({
openid: { type: String, index: true },
userId: { type: Schema.Types.ObjectId, ref: 'User', default: null },
templateId: { type: String, default: '' },
title: { type: String, default: '' }, // 消息标题(管理端检索用)
scene: { type: String, default: 'manual' }, // manual=手动群发 / release=版本发布
status: { type: String, enum: ['sent', 'failed', 'skipped'], default: 'sent' },
errCode: { type: Number, default: 0 },
errMsg: { type: String, default: '' },
adminName: { type: String, default: '' },
createdAt: { type: Date, default: Date.now, index: true }
})
module.exports = mongoose.model('NotifyLog', NotifyLogSchema)
+2 -1
View File
@@ -160,7 +160,8 @@ const UserSchema = new Schema({
default: Date.now
},
// vpay 用户态签名必需(code2Session 返回,有过期时间,过期后重登录刷新)
sessionKey: { type: String, default: '', select: false }, // [安全] 默认查询不返回(支付签名凭据)
sessionKey: { type: String, default: '', select: false },
notifyQuota: { type: Number, default: 0, min: 0 }, // 订阅消息可发送额度(每次授权+1,发送-1) // [安全] 默认查询不返回(支付签名凭据)
vpayCoins: { type: Number, default: 0 },
lastLoginAt: {
type: Date,
+3 -1
View File
@@ -13,6 +13,7 @@ const Trend = require('./Trend')
const VerificationCode = require('./VerificationCode')
const CoinLedger = require('./CoinLedger')
const VisitLog = require('./VisitLog')
const NotifyLog = require('./NotifyLog')
module.exports = {
User,
@@ -29,5 +30,6 @@ module.exports = {
Trend,
VerificationCode,
CoinLedger,
VisitLog
VisitLog,
NotifyLog
}