diff --git a/docs/news-morning-templates.md b/docs/news-morning-templates.md
index 7e839e1..ef66a38 100644
--- a/docs/news-morning-templates.md
+++ b/docs/news-morning-templates.md
@@ -6,7 +6,8 @@
| 模板 | 版本 | 状态 | 说明 |
|------|------|------|------|
| `news001` | `2026-09-18-refined` | frozen | 2026-09-18 定稿版式,已上生产。**只读,不允许就地修改**;要改版式请新开 `news003`。 |
-| `news002` | `2026-09-21-subscriber` | active | 订阅向改版:事件唯一化、每条配图、报头版式、深色模式。 |
+| `news002` | `2026-09-21-subscriber` | active | 订阅向改版:事件唯一化、每条配图、报头版式、深色模式。生产默认仍是这一版。 |
+| `news003` | `2026-11-21-wechat-forward` | trial | 页面仍是 news002。公众号标题用第一条的具体判断,摘要用新闻标题,其余列表保持紧凑。未切生产。 |
## 切换模板
@@ -146,6 +147,9 @@ news002 的卡片图会先上传到微信正文素材接口,再由 inline 渲
# 渲染一张 news002 静态预览页(样例数据,占位图)
node scripts/preview-news002-template.mjs /tmp/news002-preview.html
+# 渲染 news003 公众号对照(分享卡 + 正文,不切换生产模板)
+node scripts/preview-news003-template.mjs .tmp/news003-preview.html
+
# 用当天真实新闻 + 对应文章来源图片生成视觉样图(不推微信、不写生产目录)
node scripts/build-news002-real-design-sample.mjs
diff --git a/news-morning-templates.mjs b/news-morning-templates.mjs
index 34916a5..a825656 100644
--- a/news-morning-templates.mjs
+++ b/news-morning-templates.mjs
@@ -550,6 +550,31 @@ export const NEWS002_FRESH_CONTENT_SPEC = [
'10. 禁止八卦绯闻、未经证实的传闻、标题党;每条都要能说清「为什么重要」,说不清就不要写。',
].join('\n');
+/* ------------------------------------------------------------------ *
+ * news003 · 页面沿用 news002,公众号正文更紧凑
+ * ------------------------------------------------------------------ */
+
+export const NEWS003_VERSION = '2026-11-21-wechat-forward';
+export const NEWS003_MAX_STORY_CARDS = NEWS002_MAX_STORY_CARDS;
+export const NEWS003_SECTIONS = NEWS002_SECTIONS;
+
+export const NEWS003_STYLE_BLOCK = NEWS002_STYLE_BLOCK;
+
+export const NEWS003_SEO_SPEC = NEWS002_SEO_SPEC;
+
+export const NEWS003_TEMPLATE_SPEC = [
+ '生成「每日新闻早报」静态 HTML 页面(daily-news-MMDD.html)。',
+ '页面继续用 news002,不要改栏目、卡片、配图和色值。news003 只改公众号:分享标题用第一条的判断,其余列表保持紧凑。',
+ '在 `` 上增加 `data-news-template="news003"`,其余 DOM 与 news002 相同。',
+ '第一条 `` 的 `.why` 就是公众号标题,不超过 22 字。写出具体变化和读者要付出或得到的东西,有数字或时间就写上。',
+ '标题禁止「转给」「速看」「先看这条」「你一定要知道」「建议转发」「震惊」。不要写「为什么重要」套话,不要用栏目名。',
+ '同一条的 h3 仍是新闻标题,公众号摘要用它。其余卡片的 `.why` 仍按 news002。',
+ '',
+ NEWS002_TEMPLATE_SPEC,
+].join('\n');
+
+export const NEWS003_FRESH_CONTENT_SPEC = NEWS002_FRESH_CONTENT_SPEC;
+
/* ------------------------------------------------------------------ *
* 注册表
* ------------------------------------------------------------------ */
@@ -579,6 +604,18 @@ export const NEWS_MORNING_TEMPLATES = {
seoSpec: NEWS002_SEO_SPEC,
templateSpec: NEWS002_TEMPLATE_SPEC,
},
+ news003: {
+ id: 'news003',
+ version: NEWS003_VERSION,
+ label: '每日新闻早报 · 公众号转发版(news003)',
+ status: 'trial',
+ referenceUrl: null,
+ supportsCardImages: true,
+ maxStoryCards: NEWS003_MAX_STORY_CARDS,
+ freshContentSpec: NEWS003_FRESH_CONTENT_SPEC,
+ seoSpec: NEWS003_SEO_SPEC,
+ templateSpec: NEWS003_TEMPLATE_SPEC,
+ },
};
export const NEWS_MORNING_TEMPLATE_IDS = Object.keys(NEWS_MORNING_TEMPLATES);
@@ -607,9 +644,9 @@ function envFlag(value, fallback = true) {
export function buildNewsMorningTemplateSpec(templateId, env = process.env) {
const template = getNewsMorningTemplate(templateId, env);
- const requireFill = template.id === 'news002'
+ const requireFill = (template.id === 'news002' || template.id === 'news003')
&& envFlag(env.MEMIND_NEWS_MORNING_NEWS002_REQUIRE_FILL, true);
- const subscribeHistorySpec = template.id === 'news002'
+ const subscribeHistorySpec = template.id === 'news002' || template.id === 'news003'
? [
buildNewsMorningSubscribeBlockSpec(env),
buildNewsMorningHistorySectionSpec(),
diff --git a/news-morning-templates.test.mjs b/news-morning-templates.test.mjs
index 2b8ce59..1a9daf3 100644
--- a/news-morning-templates.test.mjs
+++ b/news-morning-templates.test.mjs
@@ -18,14 +18,21 @@ import {
countNews002SectionItems,
getNewsMorningTemplate,
NEWS002_FILL_REQUIREMENT_SPEC,
+ NEWS003_MAX_STORY_CARDS,
+ NEWS003_SECTIONS,
+ NEWS003_STYLE_BLOCK,
+ NEWS003_TEMPLATE_SPEC,
+ NEWS003_VERSION,
resolveNewsMorningTemplateId,
} from './news-morning-templates.mjs';
-test('registry exposes news001 and news002', () => {
- assert.deepEqual(NEWS_MORNING_TEMPLATE_IDS, ['news001', 'news002']);
+test('registry exposes news001, news002 and news003', () => {
+ assert.deepEqual(NEWS_MORNING_TEMPLATE_IDS, ['news001', 'news002', 'news003']);
assert.equal(NEWS_MORNING_TEMPLATES.news001.status, 'frozen');
assert.equal(NEWS_MORNING_TEMPLATES.news001.version, NEWS001_VERSION);
assert.equal(NEWS_MORNING_TEMPLATES.news002.version, NEWS002_VERSION);
+ assert.equal(NEWS_MORNING_TEMPLATES.news003.version, NEWS003_VERSION);
+ assert.equal(NEWS_MORNING_TEMPLATES.news003.status, 'trial');
});
test('news001 stays byte-identical to the frozen 0918 spec', () => {
@@ -104,6 +111,21 @@ test('buildNewsMorningTemplateSpec assembles content + seo + layout', () => {
assert.ok(!spec002.includes('版式参照(只读结构)'), 'news002 自带样式,不依赖外部参照页');
});
+test('news003 keeps the news002 page and only marks the denser WeChat variant', () => {
+ assert.equal(NEWS003_STYLE_BLOCK, NEWS002_STYLE_BLOCK);
+ assert.equal(NEWS003_MAX_STORY_CARDS, NEWS002_MAX_STORY_CARDS);
+ assert.match(NEWS003_TEMPLATE_SPEC, /data-news-template="news003"/);
+ assert.match(NEWS003_TEMPLATE_SPEC, /页面继续用 news002/);
+ assert.match(NEWS003_TEMPLATE_SPEC, /不超过 22 字/);
+ assert.match(NEWS003_TEMPLATE_SPEC, /禁止「转给」/);
+ assert.match(NEWS003_TEMPLATE_SPEC, /#FAF7F2/);
+ const spec = buildNewsMorningTemplateSpec('news003', {});
+ assert.match(spec, /版式模板:news003/);
+ assert.ok(spec.includes(NEWS002_FILL_REQUIREMENT_SPEC));
+ assert.equal(DEFAULT_NEWS_MORNING_TEMPLATE_ID, 'news002');
+ assert.equal(resolveNewsMorningTemplateId('news003', {}), 'news003');
+});
+
test('auditNews002SectionFill requires core max counts and flex coverage', () => {
const sparse = `
`;
diff --git a/scripts/preview-news003-template.mjs b/scripts/preview-news003-template.mjs
new file mode 100644
index 0000000..2d0c689
--- /dev/null
+++ b/scripts/preview-news003-template.mjs
@@ -0,0 +1,76 @@
+/**
+ * 对照渲染 news002 / news003 的公众号分享卡和正文。页面结构相同。
+ *
+ * node scripts/preview-news003-template.mjs [输出路径]
+ */
+import fs from 'node:fs';
+import path from 'node:path';
+import { convertDailyNewsHtmlToWechatInlineArticle } from '../wechat-daily-news-inline.mjs';
+
+const LEAD = ['国际油价一夜上涨', '布伦特原油隔夜上涨约 4%。国内成品油调价窗口就在这两天。', '明天加油,每升多花近两毛'];
+const ITEMS = [
+ ['东博会在南宁开幕', '本届参展企业超过三千家。主办方预计到场采购商多于去年。'],
+ ['央行维持政策利率', '公开市场继续净投放,资金面保持平稳。银行间利率围绕政策利率波动。'],
+ ['高铁新线开始试运行', '沿线车站完成联调。正式通车日期还要等监管部门公布。'],
+ ['沪指窄幅整理', '成交额较前一日略有萎缩。权重股分化,题材股成交靠前。'],
+ ['芯片厂上调资本开支', '先进制程订单排到明年二季度。设备交货周期仍在拉长。'],
+ ['冷空气开始南下', '明起华北有明显降温。部分地区风力加大,出行要注意。'],
+];
+
+const leadThumb = `data:image/svg+xml,${encodeURIComponent('')}`;
+const thumb = `data:image/svg+xml,${encodeURIComponent('')}`;
+
+function page(templateId) {
+ const [title, body, why] = LEAD;
+ const lead = `能源${title}
${body}
为什么重要:${why}
`;
+ const cards = ITEMS.map(([itemTitle, itemBody], index) =>
+ `
要闻${itemTitle}
${itemBody}
为什么重要:这句只留在页面上。
`,
+ ).join('\n');
+ return `
+ 每日新闻早报 · 2026年11月21日
+
+
+
+ 中美外长再次通话 · 东博会南宁开幕 · 央行维持政策利率
+
+ `;
+}
+
+function column(label, html, cover) {
+ const article = convertDailyNewsHtmlToWechatInlineArticle(html, {
+ includeFixedLayout: false,
+ imageUrlMap: new Map([[leadThumb, leadThumb], [thumb, thumb]]),
+ });
+ return `${label}
+ 
${article.title}
${article.digest}
+ ${article.content}
`;
+}
+
+const brandCover = `data:image/svg+xml,${encodeURIComponent('')}`;
+const out = process.argv[2] || path.join(process.cwd(), '.tmp', 'news003-preview.html');
+const html = `
+
+公众号对照 · news002 / news003
+
+公众号对照
+两边是同一份 news002 页面。上面是分享卡,下面是打开后的正文。左边标题是栏目名,右边标题是这条新闻里跟读者有关的具体变化。其余列表保持紧凑。
+
+ ${column('现在 · news002', page('news002'), brandCover)}
+ ${column('转发 · news003', page('news003'), brandCover)}
+
+`;
+fs.mkdirSync(path.dirname(out), { recursive: true });
+fs.writeFileSync(out, html);
+console.log(`news003 wechat preview written to ${out}`);
diff --git a/server/one-shop-checkout.mjs b/server/one-shop-checkout.mjs
index 7105597..a81d5f5 100644
--- a/server/one-shop-checkout.mjs
+++ b/server/one-shop-checkout.mjs
@@ -3,6 +3,22 @@ import { createHmac, timingSafeEqual } from 'node:crypto';
const lifetimeMs = 5 * 60_000;
const signature = (body, secret) => createHmac('sha256', secret)
.update('one-shop-checkout-v1:' + body).digest('base64url');
+const returnPathPattern = /^(\/[a-z0-9-]{1,80})?\/(my\/orders\/[1-9]\d*\/pay|recharge)$/;
+
+export function resolveReturnUrl(shopOrigin, { orderId, returnPath } = {}) {
+ let path = returnPath;
+ if (path == null || path === '') {
+ if (!Number.isSafeInteger(orderId) || orderId <= 0) return null;
+ path = `/my/orders/${orderId}/pay`;
+ }
+ const pattern = Number.isSafeInteger(orderId) && orderId > 0
+ ? new RegExp(`^(?:/[a-z0-9-]{1,80})?/my/orders/${orderId}/pay$`)
+ : /^(?:\/[a-z0-9-]{1,80})?\/recharge$/;
+ if (typeof path !== 'string' || path.length > 120 || !pattern.test(path)) return null;
+ const target = new URL(path, shopOrigin);
+ if (target.origin !== shopOrigin || target.pathname !== path || target.search || target.hash) return null;
+ return target.href;
+}
export function createCheckoutToken(payload, secret, now = Date.now()) {
const body = Buffer.from(JSON.stringify({ ...payload, expires: now + lifetimeMs })).toString('base64url');
@@ -19,7 +35,7 @@ export function readCheckoutToken(token, secret, shopOrigin, now = Date.now()) {
const payload = JSON.parse(Buffer.from(body, 'base64url').toString());
const target = new URL(payload.return_url);
if (!Number.isSafeInteger(payload.expires) || payload.expires <= now || payload.expires > now + lifetimeMs ||
- target.origin !== shopOrigin || !/^\/my\/orders\/[1-9]\d*\/pay$/.test(target.pathname) || target.search || target.hash ||
+ target.origin !== shopOrigin || !returnPathPattern.test(target.pathname) || target.search || target.hash ||
!Number.isSafeInteger(payload.amount_cents) || payload.amount_cents <= 0 || !payload.jsapi_params?.package) {
throw new Error('Invalid checkout');
}
diff --git a/server/portal-one-shop-routes.mjs b/server/portal-one-shop-routes.mjs
index 0a5a21a..9a13776 100644
--- a/server/portal-one-shop-routes.mjs
+++ b/server/portal-one-shop-routes.mjs
@@ -1,6 +1,6 @@
import { existsSync } from 'node:fs';
import { randomBytes, timingSafeEqual } from 'node:crypto';
-import { checkoutHtml, createCheckoutToken, readCheckoutToken } from './one-shop-checkout.mjs';
+import { checkoutHtml, createCheckoutToken, readCheckoutToken, resolveReturnUrl } from './one-shop-checkout.mjs';
import {
createWechatPayClient,
loadWechatPayConfig,
@@ -123,15 +123,19 @@ export function attachPortalOneShopRoutes({
out_trade_no: outTradeNo, amount_cents: amountCents,
memind_user_id: userId, order_id: orderId,
openid: directOpenid, openid_app_id: openidAppId,
+ return_path: returnPath,
} = req.body || {};
if (typeof outTradeNo !== 'string' || !orderPattern.test(outTradeNo) ||
!Number.isSafeInteger(amountCents) || amountCents <= 0 || amountCents > 100_000_000 ||
(userId != null && (typeof userId !== 'string' || !userId || userId.length > 128)) ||
(directOpenid != null && (typeof directOpenid !== 'string' || !/^[A-Za-z0-9_-]{1,128}$/.test(directOpenid) ||
typeof openidAppId !== 'string' || openidAppId.length > 64)) ||
- (orderId != null && (!Number.isSafeInteger(orderId) || orderId <= 0 || !outTradeNo.startsWith('OC')))) {
+ (orderId != null && (!Number.isSafeInteger(orderId) || orderId <= 0 || !outTradeNo.startsWith('OC'))) ||
+ (returnPath != null && (typeof returnPath !== 'string' || returnPath.length > 120))) {
return res.sendStatus(400);
}
+ const returnUrl = resolveReturnUrl(shopOrigin, { orderId, returnPath: returnPath || null });
+ if (returnPath && !returnUrl) return res.sendStatus(400);
try {
const pay = getPayClient();
if (!pay?.enabled) return res.sendStatus(503);
@@ -140,22 +144,26 @@ export function attachPortalOneShopRoutes({
if (userId) {
await userAuthReady;
openid = await getUserAuth()?.getWechatOpenidForUser(userId, pay.appId);
- if (!openid) return res.sendStatus(409);
- } else if (directOpenid) {
+ }
+ if (!openid && directOpenid) {
if (openidAppId !== pay.appId) return res.sendStatus(409);
openid = directOpenid;
+ } else if (userId && !openid) {
+ return res.sendStatus(409);
}
if (openid) {
const { jsapiParams } = await pay.createJsapiOrder({ ...order, openid });
- if (orderId) {
+ if (returnUrl) {
const token = createCheckoutToken({
- jsapi_params: jsapiParams, amount_cents: amountCents,
- return_url: new URL(`/my/orders/${orderId}/pay`, shopOrigin).href,
+ jsapi_params: jsapiParams, amount_cents: amountCents, return_url: returnUrl,
}, sharedSecret);
// Use the configured public payment origin, never an untrusted Host header.
const publicOrigin = new URL(paymentPublicUrl).origin;
if (!['https:', 'http:'].includes(new URL(paymentPublicUrl).protocol)) throw new Error('Invalid payment origin');
- return res.json({ checkout_url: publicOrigin + '/one-shop-pay#checkout=' + token });
+ return res.json({
+ checkout_url: publicOrigin + '/one-shop-pay#checkout=' + token,
+ jsapi_params: jsapiParams,
+ });
}
return res.json({ jsapi_params: jsapiParams });
}
diff --git a/wechat-daily-news-inline.mjs b/wechat-daily-news-inline.mjs
index 3bb9d25..c7b2c1b 100644
--- a/wechat-daily-news-inline.mjs
+++ b/wechat-daily-news-inline.mjs
@@ -304,25 +304,34 @@ function renderNews002CompactCard({
index = 0,
imageUrl = '',
isLead = false,
+ dense = false,
}) {
+ const thumbWidth = dense ? 56 : 72;
+ const thumbHeight = dense ? 42 : 54;
const thumbBlock = imageUrl
? [
- ``,
- `
`,
+ ``,
+ `
`,
'',
].join('')
: '';
- const titleStyle = isLead ? WX.compactLeadTitle : WX.listTitle;
- const titleHtml = isLead
+ const titleStyle = dense
+ ? `margin:0;font-size:14px;font-weight:700;color:${BRAND.ink};line-height:1.35`
+ : (isLead ? WX.compactLeadTitle : WX.listTitle);
+ const titleHtml = isLead || dense
? `${title}
`
: `${formatCardIndex(index)} ${title}
`;
+ const bodyStyle = dense
+ ? `margin:2px 0 0;font-size:12px;color:${BRAND.body};line-height:1.4`
+ : WX.listBody;
+ const bodyGap = dense ? 64 : 82;
return [
- ``,
+ ``,
thumbBlock,
- ``,
- tag ? `${tag}
` : '',
+ ``,
+ !dense && tag ? `${tag}
` : '',
titleHtml,
- body ? `${body}
` : '',
+ body ? `${body}
` : '',
'',
'',
].filter(Boolean).join('');
@@ -333,6 +342,7 @@ function renderCard(cardHtml, {
index = 0,
imageUrlMap = new Map(),
news002Mode = false,
+ dense = false,
} = {}) {
const title = extractInnerHtml(cardHtml, /]*>([\s\S]*?)<\/h3>/i);
if (!title) return '';
@@ -349,9 +359,10 @@ function renderCard(cardHtml, {
].join('');
}
- const body = maxBodyChars
- ? truncatePlainText(rawBody.replace(/<[^>]+>/g, ''), maxBodyChars)
- : rawBody;
+ const plainBody = rawBody.replace(/<[^>]+>/g, '');
+ const body = dense
+ ? truncatePlainText(plainBody.split(/[。!?!?]/u)[0].trim(), Math.min(Number(maxBodyChars) || 36, 36))
+ : (maxBodyChars ? truncatePlainText(plainBody, maxBodyChars) : rawBody);
const imageUrl = extractMappedCardImage(cardHtml, imageUrlMap);
if (news002Mode) {
@@ -362,6 +373,7 @@ function renderCard(cardHtml, {
index,
imageUrl,
isLead: /\blead-card\b/u.test(cardHtml),
+ dense,
});
}
@@ -381,14 +393,17 @@ function renderCard(cardHtml, {
});
}
-function renderSectionTitle(titleHtml, sectionId = '') {
+function renderSectionTitle(titleHtml, sectionId = '', { dense = false } = {}) {
const text = stripInlineText(titleHtml);
if (!text) return '';
- const label = SECTION_LABELS[sectionId] ?? '';
+ const label = dense ? '' : (SECTION_LABELS[sectionId] ?? '');
const suffix = label
? ` ${label}`
: '';
- return `
▎${text}${suffix}
`;
+ const style = dense
+ ? `margin:12px 0 4px;padding-bottom:2px;border-bottom:1px solid ${BRAND.line};font-size:15px;font-weight:700;color:${BRAND.ink}`
+ : WX.section;
+ return `▎${text}${suffix}
`;
}
function resolveMappedImageUrl(src, imageUrlMap = new Map()) {
@@ -410,6 +425,7 @@ function extractHeroSubtitle(html) {
const source = String(html);
return stripInlineText(
source.match(/