Add WeChat draft publishing

This commit is contained in:
王鹏
2026-09-18 09:30:59 +08:00
parent c9237cd480
commit 4ed8743934
30 changed files with 2536 additions and 2 deletions

88
sql/wechat_draft.sql Normal file
View File

@@ -0,0 +1,88 @@
-- 微信公众号草稿箱集成。
-- 部署前请为后端设置 WECHAT_MP_SECRET_KEY(至少16位),并将服务器出口 IP 加入公众号白名单。
CREATE TABLE IF NOT EXISTS `tt_wechat_account` (
`account_id` bigint NOT NULL AUTO_INCREMENT COMMENT '账号ID',
`account_name` varchar(100) NOT NULL COMMENT '公众号名称',
`app_id` varchar(64) NOT NULL COMMENT '公众号AppID',
`app_secret` varchar(512) NOT NULL COMMENT 'AES-GCM加密的AppSecret',
`default_author` varchar(32) DEFAULT NULL COMMENT '默认作者',
`default_source_url` varchar(1000) DEFAULT NULL COMMENT '默认阅读原文地址',
`need_open_comment` tinyint NOT NULL DEFAULT 0 COMMENT '是否开启评论',
`only_fans_can_comment` tinyint NOT NULL DEFAULT 0 COMMENT '是否仅粉丝评论',
`status` char(1) NOT NULL DEFAULT '0' COMMENT '状态(0正常 1停用)',
`create_by` varchar(64) DEFAULT '',
`create_time` datetime DEFAULT NULL,
`update_by` varchar(64) DEFAULT '',
`update_time` datetime DEFAULT NULL,
`remark` varchar(500) DEFAULT NULL,
PRIMARY KEY (`account_id`),
UNIQUE KEY `uk_wechat_account_app_id` (`app_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='微信公众号配置';
CREATE TABLE IF NOT EXISTS `tt_wechat_article` (
`article_id` bigint NOT NULL AUTO_INCREMENT COMMENT '推送记录ID',
`account_id` bigint NOT NULL COMMENT '公众号账号ID',
`code_id` bigint NOT NULL COMMENT '源码项目ID',
`template_id` bigint NOT NULL COMMENT '文案模板ID',
`request_no` varchar(64) NOT NULL COMMENT '幂等请求号',
`title` varchar(128) NOT NULL COMMENT '文章标题',
`author` varchar(64) DEFAULT NULL COMMENT '作者',
`digest` varchar(512) DEFAULT NULL COMMENT '摘要',
`content_markdown` longtext COMMENT '推送时Markdown',
`rendered_html` longtext COMMENT '图片转存前HTML',
`content_html` longtext COMMENT '最终提交微信HTML',
`content_source_url` varchar(1000) DEFAULT NULL COMMENT '阅读原文地址',
`thumb_media_id` varchar(255) DEFAULT NULL COMMENT '封面素材ID',
`show_cover_pic` tinyint NOT NULL DEFAULT 0,
`need_open_comment` tinyint NOT NULL DEFAULT 0,
`only_fans_can_comment` tinyint NOT NULL DEFAULT 0,
`wechat_media_id` varchar(255) DEFAULT NULL COMMENT '微信草稿MediaID',
`push_status` char(1) NOT NULL DEFAULT '2' COMMENT '0成功 1失败 2处理中',
`error_code` int DEFAULT NULL,
`error_message` varchar(1000) DEFAULT NULL,
`retry_count` int NOT NULL DEFAULT 0,
`push_time` datetime DEFAULT NULL,
`create_by` varchar(64) DEFAULT '',
`create_time` datetime DEFAULT NULL,
`update_by` varchar(64) DEFAULT '',
`update_time` datetime DEFAULT NULL,
PRIMARY KEY (`article_id`),
UNIQUE KEY `uk_wechat_article_request_no` (`request_no`),
KEY `idx_wechat_article_account` (`account_id`, `article_id`),
KEY `idx_wechat_article_code` (`code_id`, `article_id`),
KEY `idx_wechat_article_status` (`push_status`, `article_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='公众号草稿推送记录';
-- 菜单放在源码管理同级。
SET @wechat_parent_id := COALESCE((SELECT parent_id FROM sys_menu WHERE perms = 'office:code:list' LIMIT 1), 0);
SET @wechat_order_num := COALESCE((SELECT MAX(order_num) + 1 FROM sys_menu WHERE parent_id = @wechat_parent_id), 1);
INSERT INTO sys_menu
(menu_name, parent_id, order_num, path, component, query, is_frame, is_cache,
menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
SELECT '公众号草稿', @wechat_parent_id, @wechat_order_num,
'wechatDraft', 'office/wechat/index', '', 1, 0,
'C', '0', '0', 'office:wechat:draft:list', 'wechat', 'admin', NOW(), '', NULL,
'公众号账号和草稿推送记录'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'office:wechat:draft:list');
SET @wechat_menu_id := (SELECT menu_id FROM sys_menu WHERE perms = 'office:wechat:draft:list' LIMIT 1);
INSERT INTO sys_menu
(menu_name, parent_id, order_num, path, component, query, is_frame, is_cache,
menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
SELECT p.menu_name, @wechat_menu_id, p.order_num, '', '', '', 1, 0,
'F', '0', '0', p.perms, '#', 'admin', NOW(), '', NULL, ''
FROM (
SELECT '账号查询' menu_name, 1 order_num, 'office:wechat:account:list' perms UNION ALL
SELECT '账号详情', 2, 'office:wechat:account:query' UNION ALL
SELECT '新增账号', 3, 'office:wechat:account:add' UNION ALL
SELECT '修改账号', 4, 'office:wechat:account:edit' UNION ALL
SELECT '删除账号', 5, 'office:wechat:account:remove' UNION ALL
SELECT '测试账号', 6, 'office:wechat:account:test' UNION ALL
SELECT '推送草稿', 7, 'office:wechat:draft:push' UNION ALL
SELECT '重试草稿', 8, 'office:wechat:draft:retry'
) p
WHERE @wechat_menu_id IS NOT NULL
AND NOT EXISTS (SELECT 1 FROM sys_menu m WHERE m.perms = p.perms);