forked from Mrs4s/MiraiGo
/
richmsg.go
132 lines (123 loc) · 3.52 KB
/
richmsg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package client
import (
"math/rand"
"time"
"github.com/pkg/errors"
"github.com/eya46/MiraiGo/client/pb/oidb"
"github.com/eya46/MiraiGo/internal/proto"
"github.com/eya46/MiraiGo/message"
"github.com/eya46/MiraiGo/utils"
)
type musicTypeInfo struct {
appID uint64
appType uint32
platform uint32
sdkVersion string
packageName string
signature string
}
var musicType = [...]musicTypeInfo{
{ // QQMusic
appID: 100497308,
appType: 1,
platform: 1,
sdkVersion: "0.0.0",
packageName: "com.tencent.qqmusic",
signature: "cbd27cd7c861227d013a25b2d10f0799",
},
{ // NeteaseMusic
appID: 100495085,
appType: 1,
platform: 1,
sdkVersion: "0.0.0",
packageName: "com.netease.cloudmusic",
signature: "da6b069da1e2982db3e386233f68d76d",
},
{ // MiguMusic
appID: 1101053067,
appType: 1,
platform: 1,
sdkVersion: "0.0.0",
packageName: "cmccwm.mobilemusic",
signature: "6cdc72a439cef99a3418d2a78aa28c73",
},
{ // KugouMusic
appID: 205141,
appType: 1,
platform: 1,
sdkVersion: "0.0.0",
packageName: "com.kugou.android",
signature: "fe4a24d80fcf253a00676a808f62c2c6",
},
{ // KuwoMusic
appID: 100243533,
appType: 1,
platform: 1,
sdkVersion: "0.0.0",
packageName: "cn.kuwo.player",
signature: "bf9ff4ffb4c558a34ee3fd52c223ebf5",
},
}
// SendGroupMusicShare 发送群聊音乐卡片
func (c *QQClient) SendGroupMusicShare(target int64, msg *message.MusicShareElement) (*message.GroupMessage, error) {
ch := make(chan *message.GroupMessage, 2)
eid := utils.RandomString(6)
c.onGroupMessageReceipt(eid, func(c *QQClient, e *groupMessageReceiptEvent) {
for _, elem := range e.Msg.Elements {
if elem.Type() == message.LightApp || elem.Type() == message.Service {
ch <- e.Msg
}
}
})
defer c.onGroupMessageReceipt(eid)
_, _ = c.sendAndWait(c.buildRichMsgSendingPacket(0, target, msg, 1)) // rsp is empty chunk
select {
case ret := <-ch:
return ret, nil
case <-time.After(time.Second * 5):
return nil, errors.New("timeout")
}
}
// SendFriendMusicShare 发送好友音乐卡片
func (c *QQClient) SendFriendMusicShare(target int64, msg *message.MusicShareElement) {
_, _ = c.sendAndWait(c.buildRichMsgSendingPacket(0, target, msg, 0))
}
// SendGuildMusicShare 发送频道音乐卡片
func (c *QQClient) SendGuildMusicShare(guildID, channelID uint64, msg *message.MusicShareElement) {
// todo(wdvxdr): message receipt?
_, _ = c.sendAndWait(c.buildRichMsgSendingPacket(guildID, int64(channelID), msg, 3))
}
// OidbSvc.0xb77_9
func (c *QQClient) buildRichMsgSendingPacket(guild uint64, target int64, msg *message.MusicShareElement, sendType uint32) (uint16, []byte) {
tp := musicType[msg.MusicType] // MusicType
msgStyle := uint32(0)
if msg.MusicUrl != "" {
msgStyle = 4
}
body := &oidb.DB77ReqBody{
AppId: tp.appID,
AppType: tp.appType,
MsgStyle: msgStyle,
ClientInfo: &oidb.DB77ClientInfo{
Platform: tp.platform,
SdkVersion: tp.sdkVersion,
AndroidPackageName: tp.packageName,
AndroidSignature: tp.signature,
},
ExtInfo: &oidb.DB77ExtInfo{MsgSeq: rand.Uint64()},
SendType: sendType,
RecvUin: uint64(target),
RichMsgBody: &oidb.DB77RichMsgBody{
Title: msg.Title,
Summary: msg.Summary,
Brief: msg.Brief,
Url: msg.Url,
PictureUrl: msg.PictureUrl,
MusicUrl: msg.MusicUrl,
},
RecvGuildId: guild,
}
b, _ := proto.Marshal(body)
payload := c.packOIDBPackage(2935, 9, b)
return c.uniPacket("OidbSvc.0xb77_9", payload)
}