1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-06 20:13:50 +08:00

Merge pull request #6 from Mrs4s/master

1
This commit is contained in:
wdvxdr1123 2020-09-03 22:57:01 +08:00 committed by GitHub
commit 8c1770318c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 24 deletions

View File

@ -458,13 +458,17 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
mid := info.Get("track_info.mid").Str mid := info.Get("track_info.mid").Str
albumMid := info.Get("track_info.album.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") 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 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 { if len(aid) < 2 {
return nil, errors.New("song error") 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 return message.NewLightApp(json), nil
} }
if d["type"] == "163" { if d["type"] == "163" {
@ -503,7 +507,19 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
template := CQCodeEscapeValue(d["data"]) template := CQCodeEscapeValue(d["data"])
//println(template) //println(template)
i, _ := strconv.ParseInt(resId, 10, 64) 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 return msg, nil
default: default:
return nil, errors.New("unsupported cq code: " + t) return nil, errors.New("unsupported cq code: " + t)

View File

@ -135,8 +135,11 @@ Type: `xml`
示例: `[CQ:xml,data=xxxx]` 示例: `[CQ:xml,data=xxxx]`
####一些xml样例 ####一些xml样例
####ps:重要xml中的value部分记得html实体化处理后再打加入到cq码中 ####ps:重要xml中的value部分记得html实体化处理后再打加入到cq码中
#### qq音乐 #### qq音乐
```xml ```xml
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="2" templateID="1" action="web" brief="&#91;分享&#93; 十年" sourceMsgId="0" url="https://i.y.qq.com/v8/playsong.html?_wv=1&amp;songid=4830342&amp;souce=qqshare&amp;source=qqshare&amp;ADTAG=qqshare" flag="0" adverSign="0" multiMsgFlag="0" ><item layout="2"><audio cover="http://imgcache.qq.com/music/photo/album_500/26/500_albumpic_89526_0.jpg" src="http://ws.stream.qqmusic.qq.com/C400003mAan70zUy5O.m4a?guid=1535153710&amp;vkey=D5315B8C0603653592AD4879A8A3742177F59D582A7A86546E24DD7F282C3ACF81526C76E293E57EA1E42CF19881C561275D919233333ADE&amp;uin=&amp;fromtag=3" /><title>十年</title><summary>陈奕迅</summary></item><source name="QQ音乐" icon="https://i.gtimg.cn/open/app_icon/01/07/98/56/1101079856_100_m.png" url="http://web.p.qq.com/qqmpmobile/aio/app.html?id=1101079856" action="app" a_actionData="com.tencent.qqmusic" i_actionData="tencent1101079856://" appid="1101079856" /></msg> <?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="2" templateID="1" action="web" brief="&#91;分享&#93; 十年" sourceMsgId="0" url="https://i.y.qq.com/v8/playsong.html?_wv=1&amp;songid=4830342&amp;souce=qqshare&amp;source=qqshare&amp;ADTAG=qqshare" flag="0" adverSign="0" multiMsgFlag="0" ><item layout="2"><audio cover="http://imgcache.qq.com/music/photo/album_500/26/500_albumpic_89526_0.jpg" src="http://ws.stream.qqmusic.qq.com/C400003mAan70zUy5O.m4a?guid=1535153710&amp;vkey=D5315B8C0603653592AD4879A8A3742177F59D582A7A86546E24DD7F282C3ACF81526C76E293E57EA1E42CF19881C561275D919233333ADE&amp;uin=&amp;fromtag=3" /><title>十年</title><summary>陈奕迅</summary></item><source name="QQ音乐" icon="https://i.gtimg.cn/open/app_icon/01/07/98/56/1101079856_100_m.png" url="http://web.p.qq.com/qqmpmobile/aio/app.html?id=1101079856" action="app" a_actionData="com.tencent.qqmusic" i_actionData="tencent1101079856://" appid="1101079856" /></msg>
``` ```
@ -165,6 +168,35 @@ Type: `xml`
</msg> </msg>
``` ```
###json消息支持
Type: `json`
范围: **发送**
参数:
| 参数名 | 类型 | 说明 |
| ------ | ------ | ------------------------------------------------------------ |
| data | string | json内容json的所有字符串记得实体化处理|
| resid | int32 | 默认不填为0走小程序通道填了走富文本通道发送|
json中的字符串需要进行转义
>","=>`&#44;`
>"&"=> `&amp;`
>"["=>`&#91;`
>"]"=>`&#93;`
否则无法正确得到解析
示例json 的cq码
```test
[CQ:json,data={"app":"com.tencent.miniapp"&#44;"desc":""&#44;"view":"notification"&#44;"ver":"0.0.0.1"&#44;"prompt":"&#91;应用&#93;"&#44;"appID":""&#44;"sourceName":""&#44;"actionData":""&#44;"actionData_A":""&#44;"sourceUrl":""&#44;"meta":{"notification":{"appInfo":{"appName":"全国疫情数据统计"&#44;"appType":4&#44;"appid":1109659848&#44;"iconUrl":"http:\/\/gchat.qpic.cn\/gchatpic_new\/719328335\/-2010394141-6383A777BEB79B70B31CE250142D740F\/0"}&#44;"data":&#91;{"title":"确诊"&#44;"value":"80932"}&#44;{"title":"今日确诊"&#44;"value":"28"}&#44;{"title":"疑似"&#44;"value":"72"}&#44;{"title":"今日疑似"&#44;"value":"5"}&#44;{"title":"治愈"&#44;"value":"60197"}&#44;{"title":"今日治愈"&#44;"value":"1513"}&#44;{"title":"死亡"&#44;"value":"3140"}&#44;{"title":"今**亡"&#44;"value":"17"}&#93;&#44;"title":"中国加油,武汉加油"&#44;"button":&#91;{"name":"病毒SARS-CoV-2其导致疾病命名 COVID-19"&#44;"action":""}&#44;{"name":"传染源:新冠肺炎的患者。无症状感染者也可能成为传染源。"&#44;"action":""}&#93;&#44;"emphasis_keyword":""}}&#44;"text":""&#44;"sourceAd":""}]
```
## API ## API

View File

@ -4,13 +4,10 @@ import (
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"fmt" "fmt"
"github.com/tidwall/gjson"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strconv"
"strings" "strings"
"github.com/Mrs4s/MiraiGo/message"
"github.com/tidwall/gjson"
) )
func GetBytes(url string) ([]byte, error) { 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 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",
}
}

View File

@ -400,7 +400,6 @@ func getParamOrDefault(c *gin.Context, k, def string) string {
return def return def
} }
func getParam(c *gin.Context, k string) string { func getParam(c *gin.Context, k string) string {
p, _ := getParamWithType(c, k) p, _ := getParamWithType(c, k)
return p return p