本服通过 NapCat 将 QQ 号桥接为标准 OneBot v11 实现:事件经正向 WebSocket / HTTP 上报,出站动作经 HTTP API 调用。主服务 onebot_server.py 负责连接与全部事件处理。以下字段以实际实现为准。
| 项 | 默认值 | 说明 |
|---|---|---|
| 正向 WebSocket | ws://127.0.0.1:3001 | NapCat 提供服务端,onebot_server.py 主动连接并接收事件上报。 |
| HTTP API | http://127.0.0.1:3000 | 出站动作调用基址。 |
| Access Token | 随机串 | Bearer 鉴权,配置于 NapCat 与 onebot_server.py 两侧。 |
| Self ID | 机器人 QQ 号 | 用于过滤自身消息与识别 @提及。 |
每条事件为 JSON 对象,核心字段 post_type 区分四大类:
| post_type | 说明 | 关键附加字段 |
|---|---|---|
message | 收到消息 | message_type、user_id、group_id、guild_id、message、raw_message、sender、message_id |
notice | 群/好友通知 | notice_type、operator_id、target_id(入群、退群、戳一戳等) |
request | 加好友/加群请求 | request_type、user_id、comment |
meta_event | 生命周期与心跳 | meta_event_type:lifecycle / heartbeat |
| message_type | 目标解析 | 说明 |
|---|---|---|
private | user_id | 私聊消息。 |
group | group_id + user_id | 群聊消息。 |
guild | guild_id + channel_id + user_id | QQ 频道消息。 |
{
"post_type": "message",
"message_type": "group",
"self_id": 2738624541,
"user_id": 3533943365,
"group_id": 987654321,
"message_id": 123456789,
"raw_message": "你好",
"message": [{"type": "text", "data": {"text": "你好"}}],
"sender": {"nickname": "路易十六", "user_id": 3533943365},
"time": 1720000000
}
消息由消息段数组组成,也可用 CQ 码字符串表示([CQ:type,key=value])。onebot_server.py 收到后统一解析为 segments 与纯文本,并提取媒体文件与 @提及。
| 段类型 | CQ 码 | 关键参数 | 说明 |
|---|---|---|---|
| 文本 | — | text | 普通文本。 |
| @某人 | [CQ:at,qq=123] | qq | 解析后进入 mentioned 列表;qq=all 表示 @全体。 |
| 回复 | [CQ:reply,id=123] | id | 引用回复,出站回复时自动附带。 |
| 图片 | [CQ:image,file=...] | file / url | 支持 file://、base64://、http(s) 三种来源。 |
| 语音 | [CQ:record,file=...] | file | 语音消息,同样支持文件与 base64。 |
| 视频 | [CQ:video,file=...] | file | 视频消息。 |
| 表情 | [CQ:face,id=123] | id | QQ 内置表情。 |
调用方式:POST {httpApiUrl}/{action},请求头携带 Authorization: Bearer {accessToken},Content-Type 为 JSON。常用动作:
| Action | 参数(节选) | 说明 |
|---|---|---|
send_private_msg | user_id、message | 发送私聊消息。 |
send_group_msg | group_id、message | 发送群聊消息。 |
send_msg | message_type、user_id/group_id、message | 按类型自动路由发送。 |
delete_msg | message_id | 撤回消息。 |
set_group_ban | group_id、user_id、duration | 群内禁言(秒,0 为解除)。 |
set_group_whole_ban | group_id、enable | 全员禁言。 |
get_group_member_info | group_id、user_id | 获取群成员信息。 |
get_friend_list / get_group_list | — | 获取好友/群列表。 |
upload_group_file | group_id、file、name | 上传群文件。 |
upload_private_file | user_id、file、name | 上传私聊文件。 |
set_group_card | group_id、user_id、card | 设置群名片。 |
get_msg | message_id | 获取消息详情。 |
file:// 本地路径;需要携带多媒体时按媒体 URL 或 base64 传入,onebot_server.py 会自动落盘为可访问资源。事件上报支持 HMAC-SHA1 签名校验(X-Signature 头);出站调用使用 Bearer Token。控制台入口为随机子域 + 随机路径的一次性入口,未开通或过期即 302 跳回官网。