diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 2c6f244..0183c30 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -507,7 +507,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 := global.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"]) + 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 a0f5c42..f491cb5 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,35 @@ Type: `xml` ``` +###json消息支持 + +Type: `json` + +范围: **发送** + +参数: + +| 参数名 | 类型 | 说明 | +| ------ | ------ | ------------------------------------------------------------ | +| data | string | json内容,json的所有字符串记得实体化处理| +| resid | int32 | 默认不填为0,走小程序通道,填了走富文本通道发送| + +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 diff --git a/global/net.go b/global/net.go index e394efd..55f27de 100644 --- a/global/net.go +++ b/global/net.go @@ -4,13 +4,10 @@ import ( "bytes" "compress/gzip" "fmt" + "github.com/tidwall/gjson" "io/ioutil" "net/http" - "strconv" "strings" - - "github.com/Mrs4s/MiraiGo/message" - "github.com/tidwall/gjson" ) func GetBytes(url string) ([]byte, error) { @@ -54,18 +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", - } -} 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