# 内容发布模块 (Publisher) Sage 框架模块 — 多平台内容一键发布。支持文章/视频/音频/图片,覆盖 10 个主流平台。 ## 支持平台 | 平台代码 | 平台名称 | 支持内容类型 | 标题上限 | 正文上限 | 媒体上限 | |---------|---------|------------|:---:|:---:|:---:| | `weibo` | 微博 | article, video, image | — | 2000字 | 图片1张 | | `douyin` | 抖音 | video, image | 100字 | 500字 | 图片9张 | | `bilibili` | B站 | video, article, image | 80字 | 2000字 | — | | `kuaishou` | 快手 | video, image | — | 500字 | — | | `wechat` | 微信公众号 | article | 64字 | 50000字 | 封面图 | | `channels` | 微信视频号 | video, image | 50字 | 500字 | 图片9张 | | `xiaohongshu` | 小红书 | article, image, video | 20字 | 1000字 | 图片9张 | | `toutiao` | 头条号 | article, video | 30字 | 20000字 | — | | `youtube` | YouTube | video | 100字 | 5000字 | — | | `twitter` | Twitter/X | article, image, video | — | 280字 | 图片4张 | ## 平台认证凭据 每个平台需要配置 `publisher_platform` 记录,通用字段: | 字段 | 说明 | 必填 | |------|------|:---:| | `platform_code` | 平台代码(上表第一列) | ✓ | | `app_key` | App Key / Client ID / AppID | ✓ | | `app_secret` | App Secret(加密存储) | ✓ | | `access_token` | OAuth 2.0 访问令牌 | ✓ | | `refresh_token` | 刷新令牌(YouTube 必填) | 部分 | | `extra_config` | 平台特有参数 JSON | 部分 | 各平台 `extra_config` 需要的额外字段: | 平台 | 额外字段 | 说明 | |------|---------|------| | 微博 | `uid` | 微博用户 UID | | 抖音 | `open_id` | 授权用户的 open_id | | B站 | `cookie` | 部分接口需 Cookie | | 快手 | `open_id` | 用户唯一标识 | | 公众号 | — | AppID+Secret 即可,token 2h过期需定时刷新 | | 视频号 | `open_id` | 同公众号体系独立授权 | | 小红书 | `user_id` | 创作者身份 ID | | 头条号 | `user_id` | 头条作者 ID | | YouTube | `channel_id` | 目标频道 ID | | Twitter | `oauth_token_secret` | OAuth 1.0a Token Secret | 配置示例: ```json {"uid": "1234567890", "open_id": "abc123", "channel_id": "UCxxx"} ``` ## 目录 ``` publisher/ ├── publisher/ # Python 包 │ ├── __init__.py │ ├── init.py # load_publisher() → ServerEnv │ ├── platforms.py # 10 平台 API 适配器 │ ├── engine.py # 发布引擎 + 定时调度 │ └── db.py # 数据库操作 ├── models/ # 表定义 (4 张表) ├── skills/ # Hermes 技能文件 ├── wwwroot/publisher/ # UI + DSPY 端点 ├── ddl/mysql.sql ├── scripts/load_path.py └── install/ ``` ## 安装 ```bash git clone git@git.opencomputing.cn:yumoqing/publisher.git /tmp/publisher SAGE_ROOT=/path/to/sage cp -r /tmp/publisher/publisher $SAGE_ROOT/ cp /tmp/publisher/models/publisher_*.json $SAGE_ROOT/models/ cp -r /tmp/publisher/wwwroot/publisher $SAGE_ROOT/wwwroot/ mysql -u user -p sage < /tmp/publisher/ddl/mysql.sql cd $SAGE_ROOT && python scripts/load_path.py ``` sage.py 中添加: `from publisher.init import load_publisher` + `load_publisher()` ## 新增平台 编辑 `publisher/platforms.py`: ```python from publisher.platforms import register def publish_xxx(platform, content): return ('POST', 'https://api.xxx.com/publish', headers, body, content['content_type']) register('xxx_code', '平台名', publish_xxx, ['article', 'video']) ```