github.com/LagrangeDev/LagrangeGo@v0.0.0-20240512064304-ad4a85e10cb4/client/packets/oidb/GroupImageUpload.go (about) 1 package oidb 2 3 import ( 4 "encoding/hex" 5 "errors" 6 "fmt" 7 "math/rand" 8 9 "github.com/LagrangeDev/LagrangeGo/client/packets/pb/service/oidb" 10 "github.com/LagrangeDev/LagrangeGo/utils" 11 "github.com/LagrangeDev/LagrangeGo/utils/crypto" 12 ) 13 14 func BuildGroupImageUploadReq(groupUin uint32, data []byte) (*OidbPacket, error) { 15 // OidbSvcTrpcTcp.0x11c4_100 16 md5Hash := crypto.MD5Digest(data) 17 sha1Hash := crypto.SHA1Digest(data) 18 format, size, err := utils.ImageResolve(data) 19 if err != nil { 20 return nil, err 21 } 22 imageExt := format.String() 23 24 hexString := "0800180020004a00500062009201009a0100aa010c080012001800200028003a00" 25 bytesPbReserveTroop, err := hex.DecodeString(hexString) 26 if err != nil { 27 return nil, err 28 } 29 30 body := &oidb.NTV2RichMediaReq{ 31 ReqHead: &oidb.MultiMediaReqHead{ 32 Common: &oidb.CommonHead{ 33 RequestId: 1, 34 Command: 100, 35 }, 36 Scene: &oidb.SceneInfo{ 37 RequestType: 2, 38 BusinessType: 1, 39 SceneType: 2, 40 Group: &oidb.NTGroupInfo{ 41 GroupUin: groupUin, 42 }, 43 }, 44 Client: &oidb.ClientMeta{ 45 AgentType: 2, 46 }, 47 }, 48 Upload: &oidb.UploadReq{ 49 UploadInfo: []*oidb.UploadInfo{ 50 { 51 FileInfo: &oidb.FileInfo{ 52 FileSize: uint32(len(data)), 53 FileHash: fmt.Sprintf("%x", md5Hash), 54 FileSha1: fmt.Sprintf("%x", sha1Hash), 55 FileName: fmt.Sprintf("%x.%s", md5Hash, imageExt), 56 Type: &oidb.FileType{ 57 Type: 1, 58 PicFormat: uint32(format), 59 VideoFormat: 0, 60 VoiceFormat: 0, 61 }, 62 Width: uint32(size.Width), 63 Height: uint32(size.Height), 64 Time: 0, 65 Original: 1, 66 }, 67 SubFileType: 0, 68 }, 69 }, 70 TryFastUploadCompleted: true, 71 SrvSendMsg: false, 72 ClientRandomId: uint64(rand.Int63()), 73 CompatQMsgSceneType: 2, 74 ExtBizInfo: &oidb.ExtBizInfo{ 75 Pic: &oidb.PicExtBizInfo{ 76 BytesPbReserveTroop: bytesPbReserveTroop, 77 }, 78 Video: &oidb.VideoExtBizInfo{ 79 BytesPbReserve: []byte{}, 80 }, 81 Ptt: &oidb.PttExtBizInfo{ 82 BytesReserve: []byte{}, 83 BytesPbReserve: []byte{}, 84 BytesGeneralFlags: []byte{}, 85 }, 86 }, 87 ClientSeq: 0, 88 NoNeedCompatMsg: false, 89 }, 90 } 91 return BuildOidbPacket(0x11c4, 100, body, false, true) 92 } 93 94 func ParseGroupImageUploadResp(data []byte) (*oidb.NTV2RichMediaResp, error) { // TODO: return proper response 95 var resp oidb.NTV2RichMediaResp 96 baseResp, err := ParseOidbPacket(data, &resp) 97 if err != nil { 98 return nil, err 99 } 100 if baseResp.ErrorCode != 0 { 101 return nil, errors.New(baseResp.ErrorMsg) 102 } 103 104 return &resp, nil 105 }