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