chrononeko / bugtracker

Chrononeko Bugtracker
0 stars 0 forks source link

发送消息的具体例子 #18

Closed f44r closed 1 year ago

f44r commented 1 year ago

使用 message::send 发送消息后,better-qqnt 就会崩溃,可能是发送的 json 字段有错误?但是没有崩溃日志,无从下手

std-microblock commented 1 year ago

在最新版协议 1.1.0 中,你可以通过发送以下包来发送一条纯文本消息

{
    "type": "message::send",
    "payload": {
        "peer": {
            "chatType": 1, // 1: 私聊 2: 群聊
            "peerUin": "2953529126" // QQ 号
        },
        "elements": [
            {
                "elementType": 1,
                "textElement": {
                    "content": "1"
                }
            }
        ]
    }
}

请注意:此包省略了诸多字段,省略字段的功能是在 1.1.0 才加入的,如果不能使用,请先确认协议版本是否高于 1.1.0

协议版本号可以从回发的 meta::connect 包中获知。

std-microblock commented 1 year ago

注:1.1.0 版本协议在目前(2023/07/23 02:53 UTC+8)尚未发版,发版后我将会在此 issue 下回复。

std-microblock commented 1 year ago

此处给出更多示例:

发送文本消息到群组

{
    "type": "message::send",
    "payload": {
        "peer": {
            "chatType": 2, // 1: 私聊 2: 群聊
            "peerUin": "479613101"
        },
        "elements": [
            {
                "elementType": 1,
                "textElement": {
                    "content": "1"
                }
            }
        ]
    }
}

在私聊内回复某条消息

{
    "type": "message::send",
    "payload": {
        "peer": {
            "chatType": 1,
            "peerUin": "2953529126"
        },
        "elements": [
            {
                "elementType": 7,
                "replyElement": {
                    "replayMsgSeq": "2269", // 可在 message::recv 中取得的字段
                    "sourceMsgIdInRecords": "7259090206895299479", // 可在 message::recv 中取得的字段
                    "senderUid": "1715311957"
                }
            },
            {
                "elementType": 1,
                "textElement": {
                    "content": "1"
                }
            }
        ]
    }
}

在群聊中 At 某人

{
    "type": "message::send",
    "payload": {
        "peer": {
            "chatType": 2,
            "peerUin": "892539614"
        },
        "elements": [
            {
                "elementType": 1,
                "textElement": {
                    "content": "@时空猫猫",
                    "atType": 2,
                    "atNtUin": "3073329916"
                }
            }
        ]
    }
}

在群聊中发送表情 “快哭了”

{
    "type": "message::send",
    "payload": {
        "peer": {
            "chatType": 2,
            "peerUin": "892539614"
        },
        "elements": [
            {
                "elementType": 6,
                "faceElement": {
                    "faceIndex": 107,
                    "faceType": 1
                }
            }
        ]
    }
}

(你可以在 /data/face.json 中找到所有 QQ 自带表情)

std-microblock commented 1 year ago

chronocat launcher 0.0.29 已更新到协议 1.1.0

std-microblock commented 1 year ago

发送图片较为麻烦一点,首先你需要上传图片

POST http://localhost:16530/api/upload
form-data: 
  file: [文件]

你会得到一个 JSON 回复,例如:

{
    "md5": "7af5bac705699974bf36faa2ad973c4a",
    "imageInfo": {
        "width": 661,
        "height": 665,
        "type": "png",
        "mime": "image/png",
        "wUnits": "px",
        "hUnits": "px"
    },
    "fileSize": 513526,
    "filePath": "C:\\Users\\xxxx\\AppData\\Roaming\\BetterUniverse\\QQNT\\redprotocol-upload\\64a02e9ff8616c7730570cf414f705a6-2.png",
    "ntFilePath": "J:\\QQ\\Data\\xxxx\\nt_qq\\nt_data\\Pic\\2023-07\\Ori\\7af5bac705699974bf36faa2ad973c4a.png"
}

你需要将这个 JSON 内的字段填入包中并发送,如下

{
    "type": "message::send",
    "payload": {
        "peer": {
            "chatType": 1,
            "peerUin": "2953529126"
        },
        "elements": [
            {
                "elementType": 2,
                "picElement": {
                    "md5HexStr": "7af5bac705699974bf36faa2ad973c4a",
                    "fileSize": 513526,
                    "picHeight": 665, // 非必须
                    "picWidth": 661, // 非必须
                    "fileName": "7af5bac705699974bf36faa2ad973c4a.png",
                    "sourcePath": "J:\\QQ\\Data\\xxxx\\nt_qq\\nt_data\\Pic\\2023-07\\Ori\\7af5bac705699974bf36faa2ad973c4a.png"
                }
            }
        ]
    }
}
f44r commented 1 year ago

chronocat launcher 0.0.29 已更新到协议 1.1.0

能问一下 chronocat launcher 和 BetterQQNT 之间的关联吗?RedProtocol 以后只会在超时空猫猫那里更新吗?

std-microblock commented 1 year ago

ChronoCat 是 BetterQQNT 的特殊阉割版,和 BetterQQNT 共用大部分代码(包括RedProtocol部分)

Cola-Ace commented 1 year ago

现在at某人时貌似只有在指定atNtUid时才能生效?我指定atNtUin并传入qq号后不起作用