2025-04-02 14:29:57 +08:00

188 lines
7.8 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<div class="bg-white shadow rounded-lg p-6">
<h1 class="text-2xl font-bold text-gray-800 mb-6">API 文档</h1>
<div class="mb-10">
<p class="text-gray-600 mb-4">
微信机器人管理系统提供了一系列API接口方便您进行系统集成或自动化操作。
所有API都需要认证请在请求头中添加<code class="bg-gray-100 px-2 py-1 rounded">Authorization</code>头部。
</p>
<div class="bg-gray-100 p-4 rounded-md">
<h3 class="text-lg font-medium text-gray-800 mb-2">认证方式</h3>
<p class="mb-2">在HTTP请求头中添加</p>
<pre class="bg-gray-800 text-white p-3 rounded-md overflow-x-auto">
Authorization: Bearer YOUR_API_TOKEN</pre>
<p class="mt-2 text-sm text-gray-600">API Token可在系统设置中生成和管理。</p>
</div>
</div>
<h2 class="text-xl font-bold text-gray-800 mb-4 mt-10">可用API端点</h2>
<div class="space-y-8">
<!-- 机器人相关API -->
<div class="border-b pb-6">
<h3 class="text-lg font-medium text-gray-800 mb-4 flex items-center">
<i class="fas fa-robot mr-2 text-indigo-500"></i>机器人管理
</h3>
<!-- GET /api/robots -->
<div class="api-endpoint mb-6">
<div class="flex items-center mb-2">
<span class="inline-block px-2 py-1 text-xs font-medium bg-green-100 text-green-800 rounded-md mr-3">GET</span>
<span class="font-mono text-sm">/api/v1/robots</span>
</div>
<p class="text-gray-600 mb-2">获取所有机器人列表</p>
<div class="mt-2">
<button class="text-xs text-indigo-600 hover:text-indigo-800" onclick="toggleExample('get-robots-example')">
查看示例 <i class="fas fa-chevron-down ml-1"></i>
</button>
<div id="get-robots-example" class="hidden mt-2">
<pre class="bg-gray-800 text-white text-xs p-3 rounded-md overflow-x-auto">
{
"success": true,
"data": [
{
"id": 1,
"nickname": "客服机器人",
"container_id": "abcdef123456",
"status": "online",
"wechat_id": "wxid_12345",
"created_at": "2025-01-01T12:00:00Z",
"last_login_at": "2025-01-02T12:00:00Z"
},
{
"id": 2,
"nickname": "营销机器人",
"container_id": "ghijkl789012",
"status": "offline",
"wechat_id": null,
"created_at": "2025-01-01T14:00:00Z",
"last_login_at": null
}
]
}</pre>
</div>
</div>
</div>
<!-- GET /api/robots/:id -->
<div class="api-endpoint mb-6">
<div class="flex items-center mb-2">
<span class="inline-block px-2 py-1 text-xs font-medium bg-green-100 text-green-800 rounded-md mr-3">GET</span>
<span class="font-mono text-sm">/api/v1/robots/:id</span>
</div>
<p class="text-gray-600 mb-2">获取指定机器人的详细信息</p>
<div class="mt-2">
<button class="text-xs text-indigo-600 hover:text-indigo-800" onclick="toggleExample('get-robot-example')">
查看示例 <i class="fas fa-chevron-down ml-1"></i>
</button>
<div id="get-robot-example" class="hidden mt-2">
<pre class="bg-gray-800 text-white text-xs p-3 rounded-md overflow-x-auto">
{
"success": true,
"data": {
"id": 1,
"nickname": "客服机器人",
"container_id": "abcdef123456",
"container_host": "localhost:9001",
"status": "online",
"wechat_id": "wxid_12345",
"avatar": "base64-encoded-avatar",
"created_at": "2025-01-01T12:00:00Z",
"last_login_at": "2025-01-02T12:00:00Z"
}
}</pre>
</div>
</div>
</div>
<!-- POST /api/robots -->
<div class="api-endpoint">
<div class="flex items-center mb-2">
<span class="inline-block px-2 py-1 text-xs font-medium bg-blue-100 text-blue-800 rounded-md mr-3">POST</span>
<span class="font-mono text-sm">/api/v1/robots</span>
</div>
<p class="text-gray-600 mb-2">创建新机器人</p>
<div class="mt-2">
<button class="text-xs text-indigo-600 hover:text-indigo-800" onclick="toggleExample('post-robot-example')">
查看示例 <i class="fas fa-chevron-down ml-1"></i>
</button>
<div id="post-robot-example" class="hidden mt-2">
<p class="text-sm font-medium mb-1">请求体:</p>
<pre class="bg-gray-800 text-white text-xs p-3 rounded-md overflow-x-auto">
{
"name": "新机器人",
"port": 9002 // 可选,容器端口映射
}</pre>
<p class="text-sm font-medium mt-3 mb-1">响应:</p>
<pre class="bg-gray-800 text-white text-xs p-3 rounded-md overflow-x-auto">
{
"success": true,
"data": {
"id": 3,
"nickname": "新机器人",
"container_id": "mnopqr345678",
"container_host": "localhost:9002",
"status": "offline",
"created_at": "2025-01-03T10:00:00Z"
}
}</pre>
</div>
</div>
</div>
</div>
<!-- 联系人相关API -->
<div class="border-b pb-6">
<h3 class="text-lg font-medium text-gray-800 mb-4 flex items-center">
<i class="fas fa-address-book mr-2 text-indigo-500"></i>联系人管理
</h3>
<!-- GET /api/robots/:id/contacts -->
<div class="api-endpoint mb-6">
<div class="flex items-center mb-2">
<span class="inline-block px-2 py-1 text-xs font-medium bg-green-100 text-green-800 rounded-md mr-3">GET</span>
<span class="font-mono text-sm">/api/v1/robots/:id/contacts</span>
</div>
<p class="text-gray-600">获取机器人的联系人列表</p>
</div>
<!-- GET /api/contacts/:id/messages -->
<div class="api-endpoint">
<div class="flex items-center mb-2">
<span class="inline-block px-2 py-1 text-xs font-medium bg-green-100 text-green-800 rounded-md mr-3">GET</span>
<span class="font-mono text-sm">/api/v1/contacts/:id/messages</span>
</div>
<p class="text-gray-600">获取与联系人的聊天记录</p>
</div>
</div>
<!-- 消息相关API -->
<div class="border-b pb-6">
<h3 class="text-lg font-medium text-gray-800 mb-4 flex items-center">
<i class="fas fa-comment mr-2 text-indigo-500"></i>消息管理
</h3>
<!-- POST /api/contacts/:id/messages -->
<div class="api-endpoint">
<div class="flex items-center mb-2">
<span class="inline-block px-2 py-1 text-xs font-medium bg-blue-100 text-blue-800 rounded-md mr-3">POST</span>
<span class="font-mono text-sm">/api/v1/contacts/:id/messages</span>
</div>
<p class="text-gray-600">发送消息给联系人</p>
</div>
</div>
</div>
</div>
<script>
function toggleExample(elementId) {
const element = document.getElementById(elementId);
if (element.classList.contains('hidden')) {
element.classList.remove('hidden');
} else {
element.classList.add('hidden');
}
}
</script>