From fc18b84d4b15c6dd5e658cd0233af8afdab14495 Mon Sep 17 00:00:00 2001 From: scjtqs Date: Sun, 30 Aug 2020 02:28:01 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20[CQ:json,data=3D{json?= =?UTF-8?q?=E4=BB=A3=E7=A0=81}]=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coolq/cqcode.go | 3 +++ docs/cqhttp.md | 6 ++++++ global/net.go | 9 +++++++++ 3 files changed, 18 insertions(+) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 4c5e8b4..cc569ea 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -470,6 +470,9 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message. i, _ := strconv.ParseInt(resId, 10, 64) msg := global.NewXmlMsg(template, i) return msg, nil + case "json": + msg := global.NewJsonMsg(d["data"]) + return msg, nil default: return nil, errors.New("unsupported cq code: " + t) } diff --git a/docs/cqhttp.md b/docs/cqhttp.md index a0f5c42..457cd4a 100644 --- a/docs/cqhttp.md +++ b/docs/cqhttp.md @@ -135,8 +135,11 @@ Type: `xml` 示例: `[CQ:xml,data=xxxx]` ####一些xml样例 + ####ps:重要:xml中的value部分,记得html实体化处理后,再打加入到cq码中 + #### qq音乐 + ```xml ``` @@ -165,6 +168,9 @@ Type: `xml` ``` +###json消息支持 + +json中的","逗号,需要转义成`,`,否则无法正确得到解析 ## API diff --git a/global/net.go b/global/net.go index d3cf1a7..b0bf936 100644 --- a/global/net.go +++ b/global/net.go @@ -59,3 +59,12 @@ func NewXmlMsg(template string,ResId int64) *message.ServiceElement{ SubType: "xml", } } + +func NewJsonMsg(template string) *message.ServiceElement{ + return &message.ServiceElement{ + Id: 1, + Content: template, + ResId: "1", + SubType: "json", + } +} From bcdbefb355b11b783a017114a9e84ebd368b4bb1 Mon Sep 17 00:00:00 2001 From: scjtqs Date: Sun, 30 Aug 2020 02:29:29 +0800 Subject: [PATCH 2/9] go fmt --- global/net.go | 12 ++++++------ server/http.go | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/global/net.go b/global/net.go index b0bf936..9abcbe5 100644 --- a/global/net.go +++ b/global/net.go @@ -44,12 +44,12 @@ func QQMusicSongInfo(id string) (gjson.Result, error) { return gjson.ParseBytes(d).Get("songinfo.data"), nil } -func NewXmlMsg(template string,ResId int64) *message.ServiceElement{ +func NewXmlMsg(template string, ResId int64) *message.ServiceElement { var serviceid string - if ResId == 0{ - serviceid ="2" //默认值2 - }else{ - serviceid = strconv.FormatInt(ResId,10) + if ResId == 0 { + serviceid = "2" //默认值2 + } else { + serviceid = strconv.FormatInt(ResId, 10) } //println(serviceid) return &message.ServiceElement{ @@ -60,7 +60,7 @@ func NewXmlMsg(template string,ResId int64) *message.ServiceElement{ } } -func NewJsonMsg(template string) *message.ServiceElement{ +func NewJsonMsg(template string) *message.ServiceElement { return &message.ServiceElement{ Id: 1, Content: template, diff --git a/server/http.go b/server/http.go index ad864f5..168856b 100644 --- a/server/http.go +++ b/server/http.go @@ -400,7 +400,6 @@ func getParamOrDefault(c *gin.Context, k, def string) string { return def } - func getParam(c *gin.Context, k string) string { p, _ := getParamWithType(c, k) return p From d25674a9ef8931c5b4fa9478b7b9f2115f75da4c Mon Sep 17 00:00:00 2001 From: scjtqs Date: Sun, 30 Aug 2020 03:00:18 +0800 Subject: [PATCH 3/9] =?UTF-8?q?json=20=E5=88=9D=E6=AD=A5=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/cqhttp.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/cqhttp.md b/docs/cqhttp.md index 457cd4a..0c6f17f 100644 --- a/docs/cqhttp.md +++ b/docs/cqhttp.md @@ -170,7 +170,17 @@ Type: `xml` ###json消息支持 -json中的","逗号,需要转义成`,`,否则无法正确得到解析 +json中的字符串需要进行转义: + +>","=>`,`、 + +>"&"=> `&`、 + +>"["=>`[`、 + +>"]"=>`]`、 + +否则无法正确得到解析 ## API From 710a8588b7911f9793baf2bb410341a18bf98c9d Mon Sep 17 00:00:00 2001 From: scjtqs Date: Mon, 31 Aug 2020 00:34:38 +0800 Subject: [PATCH 4/9] =?UTF-8?q?cq:json=20=E6=B6=88=E6=81=AF=E7=9A=84?= =?UTF-8?q?=E5=88=9D=E6=AD=A5=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coolq/cqcode.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 591dd47..0da592b 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -502,10 +502,11 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message. template := CQCodeEscapeValue(d["data"]) //println(template) i, _ := strconv.ParseInt(resId, 10, 64) - msg := global.NewXmlMsg(template, i) + msg := message.NewXmlMsg(template, i) return msg, nil case "json": - msg := global.NewJsonMsg(d["data"]) + log.Warnf("json msg=%s", d["data"]) + msg := message.NewJsonMsg(CQCodeUnescapeValue(d["data"])) return msg, nil default: return nil, errors.New("unsupported cq code: " + t) From a455aeea392d1e98cb81f40cf9e5e875aa6b2af9 Mon Sep 17 00:00:00 2001 From: scjtqs Date: Mon, 31 Aug 2020 00:36:42 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E4=B8=8D=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- global/net.go | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/global/net.go b/global/net.go index c7341b7..55f27de 100644 --- a/global/net.go +++ b/global/net.go @@ -4,11 +4,9 @@ import ( "bytes" "compress/gzip" "fmt" - "github.com/Mrs4s/MiraiGo/message" "github.com/tidwall/gjson" "io/ioutil" "net/http" - "strconv" "strings" ) @@ -53,27 +51,3 @@ func NeteaseMusicSongInfo(id string) (gjson.Result, error) { return gjson.ParseBytes(d).Get("songs.0"), nil } -func NewXmlMsg(template string, ResId int64) *message.ServiceElement { - var serviceid string - if ResId == 0 { - serviceid = "2" //默认值2 - } else { - serviceid = strconv.FormatInt(ResId, 10) - } - //println(serviceid) - return &message.ServiceElement{ - Id: int32(ResId), - Content: template, - ResId: serviceid, - SubType: "xml", - } -} - -func NewJsonMsg(template string) *message.ServiceElement { - return &message.ServiceElement{ - Id: 1, - Content: template, - ResId: "1", - SubType: "json", - } -} From a0483530670a570ac4372ad252eb371ee18087c9 Mon Sep 17 00:00:00 2001 From: scjtqs Date: Mon, 31 Aug 2020 00:45:36 +0800 Subject: [PATCH 6/9] =?UTF-8?q?json=20cq=20=E7=A0=81=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/cqhttp.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/cqhttp.md b/docs/cqhttp.md index 0c6f17f..f664276 100644 --- a/docs/cqhttp.md +++ b/docs/cqhttp.md @@ -170,6 +170,16 @@ Type: `xml` ###json消息支持 +Type: `json` + +范围: **发送** + +参数: + +| 参数名 | 类型 | 说明 | +| ------ | ------ | ------------------------------------------------------------ | +| data | string | json内容,json的所有字符串记得实体化处理| + json中的字符串需要进行转义: >","=>`,`、 @@ -182,6 +192,11 @@ json中的字符串需要进行转义: 否则无法正确得到解析 +示例json 的cq码: +```test +[CQ:json,data={"app":"com.tencent.miniapp","desc":"","view":"notification","ver":"0.0.0.1","prompt":"[应用]","appID":"","sourceName":"","actionData":"","actionData_A":"","sourceUrl":"","meta":{"notification":{"appInfo":{"appName":"全国疫情数据统计","appType":4,"appid":1109659848,"iconUrl":"http:\/\/gchat.qpic.cn\/gchatpic_new\/719328335\/-2010394141-6383A777BEB79B70B31CE250142D740F\/0"},"data":[{"title":"确诊","value":"80932"},{"title":"今日确诊","value":"28"},{"title":"疑似","value":"72"},{"title":"今日疑似","value":"5"},{"title":"治愈","value":"60197"},{"title":"今日治愈","value":"1513"},{"title":"死亡","value":"3140"},{"title":"今**亡","value":"17"}],"title":"中国加油,武汉加油","button":[{"name":"病毒:SARS-CoV-2,其导致疾病命名 COVID-19","action":""},{"name":"传染源:新冠肺炎的患者。无症状感染者也可能成为传染源。","action":""}],"emphasis_keyword":""}},"text":"","sourceAd":""}] +``` + ## API ### 设置群名 From 05d8e773f2312a56c2447bbff1b77eda943f21a5 Mon Sep 17 00:00:00 2001 From: scjtqs Date: Thu, 3 Sep 2020 00:34:20 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E9=85=8D=E5=90=88=20=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=9A=84MiraiGo=E8=B0=83=E6=95=B4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coolq/cqcode.go | 12 ++++++++++-- docs/cqhttp.md | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 090e06a..396a1c8 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -503,11 +503,19 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message. template := CQCodeEscapeValue(d["data"]) //println(template) i, _ := strconv.ParseInt(resId, 10, 64) - msg := message.NewXmlMsg(template, i) + msg := message.NewRichXml(template, i) return msg, nil case "json": + resId := d["resid"] + i, _ := strconv.ParseInt(resId, 10, 64) log.Warnf("json msg=%s", d["data"]) - msg := message.NewJsonMsg(CQCodeUnescapeValue(d["data"])) + if i == 0 { + //默认情况下走小程序通道 + msg := message.NewLightApp(CQCodeUnescapeValue(d["data"])) + return msg, nil + } + //resid不为0的情况下走富文本通道,后续补全透传service Id,此处暂时不处理 TODO + msg := message.NewRichJson(CQCodeUnescapeValue(d["data"])) return msg, nil default: return nil, errors.New("unsupported cq code: " + t) diff --git a/docs/cqhttp.md b/docs/cqhttp.md index f664276..f491cb5 100644 --- a/docs/cqhttp.md +++ b/docs/cqhttp.md @@ -179,6 +179,7 @@ Type: `json` | 参数名 | 类型 | 说明 | | ------ | ------ | ------------------------------------------------------------ | | data | string | json内容,json的所有字符串记得实体化处理| +| resid | int32 | 默认不填为0,走小程序通道,填了走富文本通道发送| json中的字符串需要进行转义: From 3bd557d7a0d32ee317f52a59b70aec1f8fa2528d Mon Sep 17 00:00:00 2001 From: scjtqs Date: Thu, 3 Sep 2020 00:37:57 +0800 Subject: [PATCH 8/9] fmt --- coolq/cqcode.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 396a1c8..7f194f5 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -458,13 +458,13 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message. mid := info.Get("track_info.mid").Str albumMid := info.Get("track_info.album.mid").Str pinfo, _ := global.GetBytes("http://u.y.qq.com/cgi-bin/musicu.fcg?g_tk=2034008533&uin=0&format=json&data={\"comm\":{\"ct\":23,\"cv\":0},\"url_mid\":{\"module\":\"vkey.GetVkeyServer\",\"method\":\"CgiGetVkey\",\"param\":{\"guid\":\"4311206557\",\"songmid\":[\"" + mid + "\"],\"songtype\":[0],\"uin\":\"0\",\"loginflag\":1,\"platform\":\"23\"}}}&_=1599039471576") - jumpUrl := "https://i.y.qq.com/v8/playsong.html?platform=11&appshare=android_qq&appversion=10030010&hosteuin=oKnlNenz7i-s7c**&songmid="+ mid +"&type=0&appsongtype=1&_wv=1&source=qq&ADTAG=qfshare" + jumpUrl := "https://i.y.qq.com/v8/playsong.html?platform=11&appshare=android_qq&appversion=10030010&hosteuin=oKnlNenz7i-s7c**&songmid=" + mid + "&type=0&appsongtype=1&_wv=1&source=qq&ADTAG=qfshare" purl := gjson.ParseBytes(pinfo).Get("url_mid.data.midurlinfo.0.purl").Str - preview := "http://y.gtimg.cn/music/photo_new/T002R180x180M000"+ albumMid +".jpg" + preview := "http://y.gtimg.cn/music/photo_new/T002R180x180M000" + albumMid + ".jpg" if len(aid) < 2 { return nil, errors.New("song error") } - json := fmt.Sprintf("{\"app\": \"com.tencent.structmsg\",\"desc\": \"音乐\",\"meta\": {\"music\": {\"desc\": \"来自MiraiGo\",\"jumpUrl\": \"%s\",\"musicUrl\": \"%s\",\"preview\": \"%s\",\"tag\": \"QQ音乐\",\"title\": \"%s\"}},\"prompt\": \"[分享]%s\",\"ver\": \"0.0.0.1\",\"view\": \"music\"}", jumpUrl, purl, preview, name, name) + json := fmt.Sprintf("{\"app\": \"com.tencent.structmsg\",\"desc\": \"音乐\",\"meta\": {\"music\": {\"desc\": \"来自MiraiGo\",\"jumpUrl\": \"%s\",\"musicUrl\": \"%s\",\"preview\": \"%s\",\"tag\": \"QQ音乐\",\"title\": \"%s\"}},\"prompt\": \"[分享]%s\",\"ver\": \"0.0.0.1\",\"view\": \"music\"}", jumpUrl, purl, preview, name, name) return message.NewLightApp(json), nil } if d["type"] == "163" { From 0100b85fb161aa2e2b6bdae0012967e4ae2df602 Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Thu, 3 Sep 2020 18:05:31 +0800 Subject: [PATCH 9/9] update qq music content. --- coolq/cqcode.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 8e807d4..2c6f244 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -458,13 +458,17 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message. mid := info.Get("track_info.mid").Str albumMid := info.Get("track_info.album.mid").Str pinfo, _ := global.GetBytes("http://u.y.qq.com/cgi-bin/musicu.fcg?g_tk=2034008533&uin=0&format=json&data={\"comm\":{\"ct\":23,\"cv\":0},\"url_mid\":{\"module\":\"vkey.GetVkeyServer\",\"method\":\"CgiGetVkey\",\"param\":{\"guid\":\"4311206557\",\"songmid\":[\"" + mid + "\"],\"songtype\":[0],\"uin\":\"0\",\"loginflag\":1,\"platform\":\"23\"}}}&_=1599039471576") - jumpUrl := "https://i.y.qq.com/v8/playsong.html?platform=11&appshare=android_qq&appversion=10030010&hosteuin=oKnlNenz7i-s7c**&songmid="+ mid +"&type=0&appsongtype=1&_wv=1&source=qq&ADTAG=qfshare" + jumpUrl := "https://i.y.qq.com/v8/playsong.html?platform=11&appshare=android_qq&appversion=10030010&hosteuin=oKnlNenz7i-s7c**&songmid=" + mid + "&type=0&appsongtype=1&_wv=1&source=qq&ADTAG=qfshare" purl := gjson.ParseBytes(pinfo).Get("url_mid.data.midurlinfo.0.purl").Str - preview := "http://y.gtimg.cn/music/photo_new/T002R180x180M000"+ albumMid +".jpg" + preview := "http://y.gtimg.cn/music/photo_new/T002R180x180M000" + albumMid + ".jpg" if len(aid) < 2 { return nil, errors.New("song error") } - json := fmt.Sprintf("{\"app\": \"com.tencent.structmsg\",\"desc\": \"音乐\",\"meta\": {\"music\": {\"desc\": \"来自MiraiGo\",\"jumpUrl\": \"%s\",\"musicUrl\": \"%s\",\"preview\": \"%s\",\"tag\": \"QQ音乐\",\"title\": \"%s\"}},\"prompt\": \"[分享]%s\",\"ver\": \"0.0.0.1\",\"view\": \"music\"}", jumpUrl, purl, preview, name, name) + content := "来自go-cqhttp" + if d["content"] != "" { + content = d["content"] + } + json := fmt.Sprintf("{\"app\": \"com.tencent.structmsg\",\"desc\": \"音乐\",\"meta\": {\"music\": {\"desc\": \"%s\",\"jumpUrl\": \"%s\",\"musicUrl\": \"%s\",\"preview\": \"%s\",\"tag\": \"QQ音乐\",\"title\": \"%s\"}},\"prompt\": \"[分享]%s\",\"ver\": \"0.0.0.1\",\"view\": \"music\"}", content, jumpUrl, purl, preview, name, name) return message.NewLightApp(json), nil } if d["type"] == "163" {