@Dituon 刚刚在频道里测试成功了,QQ群应该是不好使
H
Posts made by han1549302096
-
RE: 腾讯官方Bot接口扫盲
@Dituon json是正常的,我看文档只有旧版api文档里出现过formdata方法传送图片,我不知道是我方法不对还是现在不接受formdata格式了。
-
RE: 腾讯官方Bot接口扫盲
@Dituon 大概是这样的,只是发送了一个字符串
const url = `https://api.sgroup.qq.com/v2/groups/${groupOpenid}/messages`; // const body = { // content: replyContent, // msg_type: 0, // msg_id: msgid, // }; // 创建一个 FormData 对象并添加字段 const formData = new FormData(); formData.append('content', 'hello'); formData.append('msg_type', '0'); formData.append('msg_id', msgid); try { const response = await fetch(url, { method: 'POST', headers: { // 'Content-Type': 'application/json', 'Authorization': `QQBot ${this.accessToken}`, 'X-Union-Appid': `${this.appId}`, }, body: formData, // body: JSON.stringify(body), });
-
RE: 腾讯官方Bot接口扫盲
@Dituon 我后来删除了content-type,但仍然报错
Error: Error: 304061 - invalid content
at QQBot.replyToGroupMessage (c:\koshi_dev\koishi-app\external\handstwiki3\src\test111.ts:142:27)
at processTicksAndRejections (node:internal/process/task_queues:95:5) -
RE: 腾讯官方Bot接口扫盲
@Dituon 是不是不支持formdata,我是这样写的,但是报错了
const url = `https://api.sgroup.qq.com/v2/groups/${groupOpenid}/messages`; // const body = { // content: replyContent, // msg_type: 0, // msg_id: msgid, // }; // 创建一个 FormData 对象并添加字段 const formData = new FormData(); formData.append('content', replyContent); formData.append('msg_type', '0'); formData.append('msg_id', msgid); try { const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `QQBot ${this.accessToken}`, 'X-Union-Appid': `${this.appId}`, }, body: formData, // body: JSON.stringify(body), });
报错
Error: Error: 40011000 - 请求数据异常 at QQBot.replyToGroupMessage (c:\test111.ts:145:27) at processTicksAndRejections (node:internal/process/task_queues:95:5)