go-cqhttp icon indicating copy to clipboard operation
go-cqhttp copied to clipboard

[Bug]: 无法发送Json消息

Open vaecou opened this issue 2 years ago • 1 comments

请确保您已阅读以上注意事项,并勾选下方的确认框。

  • [X] 我已经仔细阅读上述教程和 "提问前需知"
  • [X] 我已经使用 dev分支版本 测试过,问题依旧存在。
  • [X] 我已经在 Issue Tracker 中找过我要提出的问题,没有找到相同问题的ISSUE。
  • [X] 我已知晓并同意,此处仅用于汇报程序中存在的问题。若这个 Issue 是关于其他非程序本身问题,则我的 Issue 可能会被无条件自动关闭或/并锁定。(这些问题应当在 Discussion 板块提出。)

go-cqhttp 版本

v1.0.0-rc3

运行环境

Linux

运行架构

x86

连接方式

HTTP

使用协议

1 | Android Phone

重现步骤

我无法使用CQ码发送json消息,以严格按照文档对部分字符进行转义,但依然提示非法Json

即使是官方文档提供的示例Json也无法被发送,也还是会提示非法Json

https://github.com/Mrs4s/go-cqhttp/blob/master/docs/cqhttp.md#json-%E6%B6%88%E6%81%AF

期望的结果是什么?

Json发送成功

实际的结果是什么?

Json无法被发送出去

简单的复现代码/链接(可选)

No response

日志记录(可选)

No response

补充说明(可选)

No response

vaecou avatar Jul 29 '22 08:07 vaecou

我也注意到了相同的问题,我使用的提交方式是HTTP POST JSON ,使用的协议是1 | Android Phone,go-cqhttp版本是v1.0.0-rc3,我使用的系统架构是Linux amd64 我尝试使用Onebot 11标准定义的json发送方式发送json:

{
    "type": "json",
    "data": {
        "data": "{\"app\": ..."
    }
}

用作示例的json:

{ "app": "com.tencent.structmsg", "config": { "ctime": 1660368475, "forward": true, "token": "18a5e5ddd5d17272db5fa7ed85ab15c4", "type": "normal" }, "desc": "音乐", "meta": { "music": { "action": "", "android_pkg_name": "", "app_type": 1, "appid": 100495085, "ctime": 1660368475, "desc": "痛仰乐队", "jumpUrl": "https:\/\/y.music.163.com\/m\/song\/28949129", "musicUrl": "http:\/\/music.163.com\/song\/media\/outer\/url?id=28949129", "preview": "http:\/\/p1.music.126.net\/kAqWKIT-hYwO-jTS5BCAmQ==\/8888451999121623.jpg", "sourceMsgId": "0", "source_icon": "https:\/\/i.gtimg.cn\/open\/app_icon\/00\/49\/50\/85\/100495085_100_m.png", "source_url": "", "tag": "网易云音乐", "title": "两个人的假期", "uin": 755074393 } }, "prompt": "[分享]两个人的假期", "ver": "0.0.0.1", "view": "music" }

能正确发送的完整的post json内容:

{
	"group_id": xxxxx,
	"message": {
		"type": "json",
		"data": {
			"data": "{ \"app\": \"com.tencent.structmsg\", \"config\": { \"ctime\": 1660368475, \"forward\": true, \"token\": \"18a5e5ddd5d17272db5fa7ed85ab15c4\", \"type\": \"normal\" }, \"desc\": \"\u97f3\u4e50\", \"meta\": { \"music\": { \"action\": \"\", \"android_pkg_name\": \"\", \"app_type\": 1, \"appid\": 100495085, \"ctime\": 1660368475, \"desc\": \"\u75db\u4ef0\u4e50\u961f\", \"jumpUrl\": \"https:\/\/y.music.163.com\/m\/song\/28949129\", \"musicUrl\": \"http:\/\/music.163.com\/song\/media\/outer\/url?id=28949129\", \"preview\": \"http:\/\/p1.music.126.net\/kAqWKIT-hYwO-jTS5BCAmQ==\/8888451999121623.jpg\", \"sourceMsgId\": \"0\", \"source_icon\": \"https:\/\/i.gtimg.cn\/open\/app_icon\/00\/49\/50\/85\/100495085_100_m.png\", \"source_url\": \"\", \"tag\": \"\u7f51\u6613\u4e91\u97f3\u4e50\", \"title\": \"\u4e24\u4e2a\u4eba\u7684\u5047\u671f\", \"uin\": 755074393 } }, \"prompt\": \"[\u5206\u4eab]\u4e24\u4e2a\u4eba\u7684\u5047\u671f\", \"ver\": \"0.0.0.1\", \"view\": \"music\" }"
		}
	},
	"auto_escape": false
}

这没有问题,但我使用CQ码发送json时导致了与您同样的错误,我已确认我正确的转义了这些特殊字符串:

"," => ,
"&" => &
"[" => [
"]" => ]

我开启debug尝试捕获日志,但在日志中我认为没有可以有效解决这个问题的信息

xiwangly2 avatar Aug 13 '22 06:08 xiwangly2

同关注这个问题 另外想请问一下,data里必须要包含这么多字段吗,尤其token之类的

hfuulzy avatar Oct 09 '22 02:10 hfuulzy

s少一点都发不出来

vaecou avatar Oct 15 '22 15:10 vaecou

token目前获取方式未知

James4Ever0 avatar Oct 31 '22 07:10 James4Ever0