API 认证
Token 使用指南
通过 API Token 调用文流转换服务,实现 Markdown 到富文本的自动化转换。
调用流程
理解 API 认证与数据流向
1创建 Token
- 1登录文流账户
- 2点击右上角头像,选择「设置」
- 3切换到「Token 管理」标签页
- 4输入 Token 名称,点击「创建」
重要:Token 仅在创建时显示一次,请务必立即复制保存。之后将无法再次查看完整 Token。
2调用 API (cURL)
请求示例
curl -X POST https://wenflow.coze.site/api/convert/rich-text \
-H "Content-Type: application/json" \
-H "Authorization: Bearer wmd_your_token_here" \
-d '{
"markdown": "# 标题\n\n这是一段内容。",
"theme": {
"id": "tech-blue"
}
}'响应示例
{
"html": "<h1 style=\"...\">标题</h1><p style=\"...\">这是一段内容。</p>",
"remaining": 2
}3Node.js 调用示例
使用 node-fetch
Node.js (node-fetch)
const fetch = require('node-fetch');
async function convertMarkdown() {
const response = await fetch('https://wenflow.coze.site/api/convert/rich-text', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer wmd_your_token_here'
},
body: JSON.stringify({
markdown: '# 标题\n\n这是一段 **加粗** 的内容。',
theme: {
id: 'tech-blue'
}
})
});
const data = await response.json();
if (response.ok) {
console.log('HTML:', data.html);
console.log('剩余调用次数:', data.remaining);
return data.html;
} else {
console.error('错误:', data.error);
throw new Error(data.error);
}
}
convertMarkdown().catch(console.error);使用 axios
Node.js (axios)
const axios = require('axios');
async function convertMarkdown() {
try {
const response = await axios.post(
'https://wenflow.coze.site/api/convert/rich-text',
{
markdown: '# 标题\n\n这是一段 **加粗** 的内容。',
theme: { id: 'tech-blue' }
},
{
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer wmd_your_token_here'
}
}
);
console.log('HTML:', response.data.html);
console.log('剩余调用次数:', response.data.remaining);
return response.data.html;
} catch (error) {
console.error('错误:', error.response?.data || error.message);
throw error;
}
}
convertMarkdown();4Python 调用示例
使用 requests (同步)
Python (requests)
import requests
import json
def convert_markdown(markdown_content, theme_id='default'):
"""
将 Markdown 转换为微信公众号富文本格式
Args:
markdown_content: Markdown 文本内容
theme_id: 主题 ID,可选值见文档
Returns:
dict: 包含 html 和 remaining 的字典
"""
url = 'https://wenflow.coze.site/api/convert/rich-text'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer wmd_your_token_here'
}
payload = {
'markdown': markdown_content,
'theme': {'id': theme_id}
}
response = requests.post(url, headers=headers, json=payload)
if response.ok:
data = response.json()
print(f"HTML: {data['html'][:100]}...")
print(f"剩余调用次数: {data['remaining']}")
return data
else:
error = response.json()
print(f"错误: {error.get('error', 'Unknown error')}")
raise Exception(error.get('error', 'API request failed'))
# 使用示例
if __name__ == '__main__':
markdown_text = '''
# 标题
这是一段 **加粗** 的内容。
## 二级标题
- 列表项 1
- 列表项 2
'''
result = convert_markdown(markdown_text, theme_id='tech-blue')
print(result['html'])使用 aiohttp (异步)
Python (aiohttp)
import aiohttp
import asyncio
async def convert_markdown_async(markdown_content, theme_id='default'):
"""异步版本的 Markdown 转换"""
url = 'https://wenflow.coze.site/api/convert/rich-text'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer wmd_your_token_here'
}
payload = {
'markdown': markdown_content,
'theme': {'id': theme_id}
}
async with aiohttp.ClientSession() as session:
async with session.post(url, headers=headers, json=payload) as response:
if response.status == 200:
data = await response.json()
return data
else:
error = await response.json()
raise Exception(error.get('error', 'API request failed'))
# 使用示例
async def main():
markdown_text = '# 标题\n\n这是异步请求的结果。'
result = await convert_markdown_async(markdown_text, 'forest-green')
print(result['html'])
asyncio.run(main())5接口详情
请求参数
markdownstring,必需theme.idstring,可选theme.cssstring,可选限流规则
每个 Token每分钟 3 次
响应头
X-RateLimit-Remaining超限响应
429 Too Many Requests6可用主题
通过 theme.id 参数指定主题,支持以下主题:
default默认简约
tech-blue科技蓝
warm-orange暖橙活力
purple-gradient紫韵渐变
forest-green森林绿意
ocean-blue深海蔚蓝
rose-pink玫瑰浪漫
dark-mode暗夜模式
vintage-paper复古纸张PRO
minimalist-white极简留白PRO
neon-cyber赛博霓虹PRO
newspaper新闻报刊PRO
gradient-rainbow彩虹渐变PRO
typewriter打字机PRO
glassmorphism毛玻璃PRO
code-docs代码文档PRO
hand-drawn手绘风格PRO
notepad记事本PRO
apple-notes苹果备忘录PRO
smartisan-notes锤子笔记PRO
错误码说明
MISSING_TOKEN请求缺少认证 TokenINVALID_TOKENToken 无效或不存在TOKEN_DISABLEDToken 已被禁用TOKEN_EXPIREDToken 已过期RATE_LIMITED请求过于频繁MISSING_MARKDOWN请求缺少 Markdown 内容安全建议
妥善保管
不要将 Token 提交到公开仓库
定期更换
怀疑泄露时立即删除重建
使用环境变量
避免硬编码 Token 值
最小权限
为不同应用创建不同 Token
