From af9ed48cb7ca0d738b9c481b214a4cced4451e3b Mon Sep 17 00:00:00 2001 From: Mrs4s Date: Tue, 9 Nov 2021 03:16:26 +0800 Subject: [PATCH] feat: query guild service image --- binary/protobuf.go | 4 ++++ client/guild_msg.go | 53 +++++++++++++++++++++++++++++++++++++++++++++ message/image.go | 32 +++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) diff --git a/binary/protobuf.go b/binary/protobuf.go index e468c7dc..30573eac 100644 --- a/binary/protobuf.go +++ b/binary/protobuf.go @@ -55,6 +55,10 @@ func (msg DynamicProtoMessage) Encode() []byte { en.uvarint(key | 0) en.uvarint(v[i]) } + case []byte: + en.uvarint(key | 2) + en.uvarint(uint64(len(v))) + _, _ = en.Write(v) case DynamicProtoMessage: en.uvarint(key | 2) b := v.Encode() diff --git a/client/guild_msg.go b/client/guild_msg.go index 15ed268b..1b99a636 100644 --- a/client/guild_msg.go +++ b/client/guild_msg.go @@ -1,6 +1,9 @@ package client import ( + "encoding/hex" + "github.com/Mrs4s/MiraiGo/client/pb/cmd0x388" + "github.com/Mrs4s/MiraiGo/internal/packets" "strconv" "github.com/pkg/errors" @@ -37,6 +40,56 @@ func (c *QQClient) parseGuildChannelMessage(msg *channel.ChannelMsgContent) *mes } } +func (s *GuildService) QueryImage(guildId, channelId uint64, hash []byte, size uint64) (*message.GuildImageElement, error) { + seq := s.c.nextSeq() + payload, _ := proto.Marshal(&cmd0x388.D388ReqBody{ + NetType: proto.Uint32(3), + Subcmd: proto.Uint32(1), + TryupImgReq: []*cmd0x388.TryUpImgReq{ + { + GroupCode: &channelId, + SrcUin: proto.Uint64(uint64(s.c.Uin)), + FileId: proto.Uint64(0), + FileMd5: hash, + FileSize: &size, + FileName: []byte(hex.EncodeToString(hash) + ".jpg"), + SrcTerm: proto.Uint32(5), + PlatformType: proto.Uint32(9), + BuType: proto.Uint32(211), + PicType: proto.Uint32(1000), + BuildVer: []byte("8.8.38.2266"), + AppPicType: proto.Uint32(1052), + SrvUpload: proto.Uint32(0), + QqmeetGuildId: &guildId, + QqmeetChannelId: &channelId, + }, + }, + CommandId: proto.Uint32(83), + }) + packet := packets.BuildUniPacket(s.c.Uin, seq, "ImgStore.QQMeetPicUp", 1, s.c.OutGoingPacketSessionId, []byte{}, s.c.sigInfo.d2Key, payload) + rsp, err := s.c.sendAndWaitDynamic(seq, packet) + if err != nil { + return nil, errors.Wrap(err, "send packet error") + } + body := new(cmd0x388.D388RspBody) + if err = proto.Unmarshal(rsp, body); err != nil { + return nil, errors.Wrap(err, "failed to unmarshal protobuf message") + } + if len(body.TryupImgRsp) == 0 { + return nil, errors.New("response is empty") + } + if body.TryupImgRsp[0].GetFileExit() { + return &message.GuildImageElement{ + FileId: body.TryupImgRsp[0].GetFileid(), + FilePath: hex.EncodeToString(hash) + ".jpg", + Size: int32(size), + DownloadIndex: string(body.TryupImgRsp[0].GetDownloadIndex()), + Md5: hash, + }, nil + } + return nil, errors.New("image is not exists") +} + func decodeGuildMessagePushPacket(c *QQClient, _ *incomingPacketInfo, payload []byte) (interface{}, error) { push := new(channel.MsgOnlinePush) if err := proto.Unmarshal(payload, push); err != nil { diff --git a/message/image.go b/message/image.go index 147c537a..3a71db24 100644 --- a/message/image.go +++ b/message/image.go @@ -36,6 +36,17 @@ type FriendImageElement struct { Flash bool } +type GuildImageElement struct { + FileId uint64 + FilePath string + ImageType int32 + Size int32 + Width int32 + Height int32 + DownloadIndex string + Md5 []byte +} + type ImageBizType uint32 const ( @@ -155,3 +166,24 @@ func (e *FriendImageElement) Pack() (r []*msg.Elem) { elem := &msg.Elem{NotOnlineImage: image} return []*msg.Elem{elem} } + +func (e *GuildImageElement) Pack() (r []*msg.Elem) { + cface := &msg.CustomFace{ + FileType: proto.Int32(66), + Useful: proto.Int32(1), + BizType: proto.Int32(0), + Width: &e.Width, + Height: &e.Height, + FileId: proto.Int32(int32(e.FileId)), + FilePath: &e.FilePath, + ImageType: &e.ImageType, + Size: &e.Size, + Md5: e.Md5, + PbReserve: binary.DynamicProtoMessage{ + 1: uint32(0), 2: uint32(0), 6: "", 10: uint32(0), 15: uint32(8), + 20: e.DownloadIndex, + }.Encode(), + } + elem := &msg.Elem{CustomFace: cface} + return []*msg.Elem{elem} +}