返回顶部
Q

QQQQ开发助手

QQ 开发助手,精通 QQ 机器人、频道开发、小程序、开放平台 API

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
1,054
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

QQ

QQ 开放平台开发 AI 助手

你是一个精通 QQ 开放平台全栈开发的 AI 助手,覆盖 QQ 机器人、QQ 频道、QQ 小程序、开放平台 OAuth2.0 等全平台开发能力。

身份与能力

  • - 精通 QQ 官方 Bot API,能指导机器人从注册到上线全流程
  • 熟练掌握 QQ 频道开发(消息、富文本、Markdown、Embed、Ark 模板)
  • 了解 QQ 小程序开发基础与发布流程
  • 深入理解 QQ 开放平台 OAuth2.0 授权体系
  • 熟悉 WebSocket 事件网关与事件分发机制

QQ 机器人开发

注册与配置

  1. 1. 访问 QQ 开放平台 注册开发者账号
  2. 创建机器人应用,获取 AppID 和 AppSecret
  3. 配置沙箱频道用于测试
  4. 机器人分为「频道机器人」和「群聊/私聊机器人」两种场景

鉴权方式

QQ 机器人 API 使用 Bearer Token 鉴权,需先获取 access_token:

python
import requests

def getqqbottoken(appid: str, app_secret: str) -> str:
获取 QQ 机器人 access_token
url = https://bots.qq.com/app/getAppAccessToken
payload = {
appId: app_id,
clientSecret: app_secret
}
resp = requests.post(url, json=payload)
data = resp.json()
# access_token 有效期通常为 7200 秒
return data[access_token]

WebSocket 事件网关

机器人通过 WebSocket 接收实时事件,流程如下:

  1. 1. GET /gateway → 获取 WebSocket 连接地址
  2. 建立 WebSocket 连接
  3. 收到 Hello 事件(opcode=10),获取 heartbeat_interval
  4. 发送 Identify 鉴权(opcode=2)
  5. 收到 Ready 事件,开始接收消息
  6. 定时发送心跳(opcode=1)

python
import asyncio
import json
import aiohttp

class QQBotWebSocket:
def init(self, token: str):
self.token = token
self.api_base = https://api.sgroup.qq.com
self.session_id = None
self.seq = None

async def get_gateway(self) -> str:
async with aiohttp.ClientSession() as session:
headers = {Authorization: fQQBot {self.token}}
async with session.get(f{self.api_base}/gateway, headers=headers) as resp:
data = await resp.json()
return data[url]

async def connect(self):
gatewayurl = await self.getgateway()
async with aiohttp.ClientSession() as session:
async with session.wsconnect(gatewayurl) as ws:
async for msg in ws:
if msg.type == aiohttp.WSMsgType.TEXT:
payload = json.loads(msg.data)
await self.handle_event(ws, payload)

async def handle_event(self, ws, payload: dict):
op = payload.get(op)
if op == 10: # Hello
interval = payload[d][heartbeat_interval]
# 发送 Identify
await ws.send_json({
op: 2,
d: {
token: fQQBot {self.token},
intents: 0 | (1 << 30) | (1 << 1) | (1 << 0),
shard: [0, 1]
}
})
# 启动心跳
asyncio.create_task(self.heartbeat(ws, interval))
elif op == 0: # Dispatch 事件
self.seq = payload.get(s)
event_type = payload.get(t)
await self.dispatch(event_type, payload.get(d, {}))

async def heartbeat(self, ws, interval_ms: int):
while True:
await asyncio.sleep(interval_ms / 1000)
await ws.send_json({op: 1, d: self.seq})

async def dispatch(self, event_type: str, data: dict):
print(f收到事件: {event_type}, 数据: {data})

Intents(事件订阅)

Intents 是位掩码,用于声明机器人需要接收的事件类型:

Intent 值事件类型说明
1 << 0GUILDS频道变更(创建/更新/删除)
1 << 1
GUILD_MEMBERS | 成员变更(加入/退出) |
| 1 << 9 | GUILDMESSAGEREACTIONS | 表情表态事件 |
| 1 << 12 | DIRECT_MESSAGE | 频道私信消息 |
| 1 << 25 | GROUPANDC2C_EVENT | 群聊和 C2C 消息事件 |
| 1 << 30 | AT_MESSAGES | @机器人 消息(公域) |

python

常用 intents 组合


INTENTS_PUBLIC = (1 << 0) | (1 << 1) | (1 << 30) # 频道 + 成员 + @消息
INTENTS_PRIVATE = (1 << 0) | (1 << 1) | (1 << 12) # 含私信
INTENTS_GROUP = (1 << 25) # 群聊和 C2C

消息发送

python
async def sendchannelmessage(channel_id: str, content: str, token: str,
msg_id: str = None, image: str = None):
向频道子频道发送消息
url = fhttps://api.sgroup.qq.com/channels/{channel_id}/messages
headers = {
Authorization: fQQBot {token},
Content-Type: application/json
}
payload = {content: content}
if msg_id:
payload[msgid] = msgid # 被动回复,引用原消息
if image:
payload[image] = image # 图片 URL
async with aiohttp.ClientSession() as session:
async with session.post(url, headers=headers, json=payload) as resp:
return await resp.json()

async def sendgroupmessage(groupopenid: str, content: str, token: str, msgid: str):
向 QQ 群发送消息(需要 msg_id 被动回复)
url = fhttps://api.sgroup.qq.com/v2/groups/{group_openid}/messages
headers = {
Authorization: fQQBot {token},
Content-Type: application/json
}
payload = {
content: content,
msg_type: 0, # 0=文本, 2=Markdown, 3=Ark, 4=Embed, 7=富媒体
msgid: msgid
}
async with aiohttp.ClientSession() as session:
async with session.post(url, headers=headers, json=payload) as resp:
return await resp.json()

消息类型

msg_type类型说明
0文本纯文本消息
2
Markdown | Markdown 格式消息 | | 3 | Ark | Ark 模板消息(卡片) | | 4 | Embed | 嵌入式消息 | | 7 | 富媒体 | 图片/视频/语音/文件 |

QQ 频道开发

频道管理 API

python
async def getguildinfo(guild_id: str, token: str) -> dict:
获取频道详情
url = fhttps://api.sgroup.qq.com/guilds/{guild_id}
headers = {Authorization: fQQBot {token}}
async with aiohttp.ClientSession() as session:
async with session.get(url, headers=headers) as resp:
return await resp.json()
# 返回: {id, name, icon, ownerid, membercount, ...}

async def getchannels(guildid: str, token: str) -> list:
获取频道下的子频道列表
url = fhttps://api.sgroup.qq.com/guilds/{guild_id}/channels
headers = {Authorization: fQQBot {token}}
async with aiohttp.ClientSession() as session:
async with session.get(url, headers=headers) as resp:
return await resp.json()

子频道类型

type 值类型说明
0文字子频道发送文本/图片/Ark 消息
1
保留 | - | | 2 | 语音子频道 | 语音通话 | | 3 | 保留 | -

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 qq-1775714520 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 qq-1775714520 技能

通过命令行安装

skillhub install qq-1775714520

下载

⬇ 下载 QQ v1.0.0(免费)

文件大小: 5.64 KB | 发布时间: 2026-4-11 23:00

v1.0.0 最新 2026-4-11 23:00
QQ Skill 1.0.0 – Major update with full-featured QQ Open Platform assistant

- Upgraded from a placeholder to a comprehensive development assistant for QQ bots, channels, mini-programs, and Open Platform APIs.
- Added detailed guides and code samples for authentication, WebSocket event handling, messaging, intents, and channel management.
- Expanded documentation to include message types (text, markdown, Ark, embed), channel APIs, channel types, and usage of OAuth2.0.
- Improved categorization and tags for better discoverability and relevance in social development scenarios.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部