docs: add platform credentials table to README + skills/ directory

This commit is contained in:
yumoqing 2026-08-04 08:27:45 +08:00
parent 004fd713b8
commit 69b92ae44f
2 changed files with 119 additions and 22 deletions

View File

@ -4,17 +4,51 @@ Sage 框架模块 — 多平台内容一键发布。支持文章/视频/音频/
## 支持平台
| 平台代码 | 平台名称 | 支持内容类型 |
|---------|---------|------------|
| `weibo` | 微博 | article, video, image |
| `douyin` | 抖音 | video, image |
| `bilibili` | B站 | video, article, image |
| `kuaishou` | 快手 | video, image |
| `wechat` | 微信公众号 | article |
| `xiaohongshu` | 小红书 | article, image, video |
| `toutiao` | 头条号 | article, video |
| `youtube` | YouTube | video |
| `twitter` | Twitter/X | article, image, video |
| 平台代码 | 平台名称 | 支持内容类型 | 标题上限 | 正文上限 | 媒体上限 |
|---------|---------|------------|:---:|:---:|:---:|
| `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"}
```
## 目录
@ -26,7 +60,8 @@ publisher/
│ ├── platforms.py # 10 平台 API 适配器
│ ├── engine.py # 发布引擎 + 定时调度
│ └── db.py # 数据库操作
├── json/ # 表定义 (4 张表)
├── models/ # 表定义 (4 张表)
├── skills/ # Hermes 技能文件
├── wwwroot/publisher/ # UI + DSPY 端点
├── ddl/mysql.sql
├── scripts/load_path.py
@ -39,24 +74,17 @@ publisher/
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/json/publisher_*.json $SAGE_ROOT/json/
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 # 从 publisher/scripts/
cd $SAGE_ROOT && python scripts/load_path.py
```
sage.py 中添加: `from publisher.init import load_publisher` + `load_publisher()`
## 使用
1. 配置平台 → 填 App Key/Secret/Access Token
2. 创建内容 → 选类型(article/video/audio/image) + 媒体URL
3. 创建任务 → 选内容 + 平台 + 定时发布时间
4. 点击「执行待发布任务」
## 新增平台
编辑 `publisher/platforms.py`,添加:
编辑 `publisher/platforms.py`:
```python
from publisher.platforms import register

View File

@ -0,0 +1,69 @@
---
name: publisher-module
description: Multi-platform content publishing module for Sage — articles, videos, audio to 10 social platforms
category: devops
---
# Publisher Module
Multi-platform content publishing for Sage. Covers 10 platforms: weibo, douyin, bilibili, kuaishou, wechat (公众号), channels (视频号), xiaohongshu, toutiao, youtube, twitter.
## Architecture
- **Repo**: `git@git.opencomputing.cn:yumoqing/publisher.git`
- **Tables** (4): `publisher_platform`, `publisher_content`, `publisher_task`, `publisher_log`
- **Content types**: article, video, audio, image
- **DSPY pattern**: `import json` + `get_sor_context(env, 'sage')` + `env.run_scheduled(sor)`
## Adding a Platform
Edit `publisher/platforms.py`:
```python
from publisher.platforms import register
def publish_newplat(platform, content):
headers = {'Authorization': 'Bearer ' + platform['access_token']}
body = {'text': content.get('title', '')}
return ('POST', 'https://api.newplat.com/publish', headers, body, content['content_type'])
register('newplat', '新平台', publish_newplat, ['article', 'image', 'video'])
```
Each platform needs in `publisher_platform`:
- `app_key` + `app_secret` (all)
- `access_token` (all)
- `refresh_token` (YouTube)
- `extra_config` JSON with platform-specific fields (uid/open_id/channel_id/etc.)
## Platform Credentials Quick Reference
| platform_code | extra_config fields | Notes |
|---|---|---|
| weibo | uid | Weibo user UID required |
| douyin | open_id | OAuth authorized user |
| bilibili | cookie | Some endpoints need Cookie |
| kuaishou | open_id | User identifier |
| wechat | — | Token expires every 2h |
| channels | open_id | Separate auth from 公众号 |
| xiaohongshu | user_id | Creator ID |
| toutiao | user_id | Author ID |
| youtube | channel_id | Needs refresh_token |
| twitter | oauth_token_secret | OAuth 1.0a |
## Deployment Checklist
1. `cp -r publisher $SAGE_ROOT/`
2. `cp models/publisher_*.json $SAGE_ROOT/models/`
3. `cp -r wwwroot/publisher $SAGE_ROOT/wwwroot/`
4. Execute `ddl/mysql.sql`
5. Run `scripts/load_path.py`
6. `from publisher.init import load_publisher` + `load_publisher()` in sage.py
7. Restart Sage
## Pitfalls
- Platform APIs require real credentials — access_token expires, need refresh flow
- Content format differs per platform (Weibo 2000, WeChat title 64, Twitter 280)
- Network errors auto-retry 3 times before marking failed
- `sor` parameter allows DSPY context reuse