1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 19:17:38 +08:00

message: remove GroupImage Width & Height

sometimes these fields may be zero causing send failures
This commit is contained in:
wdvxdr 2021-12-28 21:44:10 +08:00 committed by fumiama
parent 2c56abf4d8
commit e22965eb0c
3 changed files with 7 additions and 20 deletions

View File

@ -3,7 +3,6 @@ package client
import ( import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"image"
"io" "io"
"math/rand" "math/rand"
"os" "os"
@ -81,8 +80,6 @@ func (c *QQClient) UploadGroupImage(groupCode int64, img io.ReadSeeker) (*messag
} }
return nil, errors.Wrap(err, "upload failed") return nil, errors.Wrap(err, "upload failed")
ok: ok:
_, _ = img.Seek(0, io.SeekStart)
i, _, _ := image.DecodeConfig(img)
var imageType int32 = 1000 var imageType int32 = 1000
_, _ = img.Seek(0, io.SeekStart) _, _ = img.Seek(0, io.SeekStart)
tmp := make([]byte, 4) tmp := make([]byte, 4)
@ -90,7 +87,7 @@ ok:
if bytes.Equal(tmp, []byte{0x47, 0x49, 0x46, 0x38}) { if bytes.Equal(tmp, []byte{0x47, 0x49, 0x46, 0x38}) {
imageType = 2000 imageType = 2000
} }
return message.NewGroupImage(binary.CalculateImageResourceId(fh), fh, rsp.FileId, int32(length), int32(i.Width), int32(i.Height), imageType), nil return message.NewGroupImage(binary.CalculateImageResourceId(fh), fh, rsp.FileId, int32(length), imageType), nil
} }
func (c *QQClient) UploadGroupImageByFile(groupCode int64, path string) (*message.GroupImageElement, error) { func (c *QQClient) UploadGroupImageByFile(groupCode int64, path string) (*message.GroupImageElement, error) {
@ -134,8 +131,6 @@ func (c *QQClient) UploadGroupImageByFile(groupCode int64, path string) (*messag
} }
return nil, errors.Wrap(err, "upload failed") return nil, errors.Wrap(err, "upload failed")
ok: ok:
_, _ = img.Seek(0, io.SeekStart)
i, _, _ := image.DecodeConfig(img)
var imageType int32 = 1000 var imageType int32 = 1000
_, _ = img.Seek(0, io.SeekStart) _, _ = img.Seek(0, io.SeekStart)
tmp := make([]byte, 4) tmp := make([]byte, 4)
@ -143,7 +138,7 @@ ok:
if bytes.Equal(tmp, []byte{0x47, 0x49, 0x46, 0x38}) { if bytes.Equal(tmp, []byte{0x47, 0x49, 0x46, 0x38}) {
imageType = 2000 imageType = 2000
} }
return message.NewGroupImage(binary.CalculateImageResourceId(fh), fh, rsp.FileId, int32(length), int32(i.Width), int32(i.Height), imageType), nil return message.NewGroupImage(binary.CalculateImageResourceId(fh), fh, rsp.FileId, int32(length), imageType), nil
} }
func (c *QQClient) UploadPrivateImage(target int64, img io.ReadSeeker) (*message.FriendImageElement, error) { func (c *QQClient) UploadPrivateImage(target int64, img io.ReadSeeker) (*message.FriendImageElement, error) {
@ -191,7 +186,7 @@ func (c *QQClient) ImageOcr(img interface{}) (*OcrResponse, error) {
} }
_ = b.Close() _ = b.Close()
} }
rsp, err := c.sendAndWait(c.buildImageOcrRequestPacket(url, strings.ToUpper(hex.EncodeToString(e.Md5)), e.Size, e.Width, e.Height)) rsp, err := c.sendAndWait(c.buildImageOcrRequestPacket(url, strings.ToUpper(hex.EncodeToString(e.Md5)), e.Size, 480, 720))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -210,7 +205,7 @@ func (c *QQClient) QueryGroupImage(groupCode int64, hash []byte, size int32) (*m
return nil, errors.New(rsp.Message) return nil, errors.New(rsp.Message)
} }
if rsp.IsExists { if rsp.IsExists {
return message.NewGroupImage(binary.CalculateImageResourceId(hash), hash, rsp.FileId, size, rsp.Width, rsp.Height, 1000), nil return message.NewGroupImage(binary.CalculateImageResourceId(hash), hash, rsp.FileId, size, 1000), nil
} }
return nil, errors.New("image does not exist") return nil, errors.New("image does not exist")
} }

View File

@ -16,8 +16,6 @@ type GroupImageElement struct {
ImageType int32 ImageType int32
ImageBizType ImageBizType ImageBizType ImageBizType
Size int32 Size int32
Width int32
Height int32
Md5 []byte Md5 []byte
Url string Url string
@ -64,15 +62,13 @@ const (
/* ------ Implementations ------ */ /* ------ Implementations ------ */
func NewGroupImage(id string, md5 []byte, fid int64, size, width, height, imageType int32) *GroupImageElement { func NewGroupImage(id string, md5 []byte, fid int64, size, imageType int32) *GroupImageElement {
return &GroupImageElement{ return &GroupImageElement{
ImageId: id, ImageId: id,
FileId: fid, FileId: fid,
Md5: md5, Md5: md5,
Size: size, Size: size,
ImageType: imageType, ImageType: imageType,
Width: width,
Height: height,
Url: "https://gchat.qpic.cn/gchatpic_new/1/0-0-" + strings.ReplaceAll(binary.CalculateImageResourceId(md5)[1:37], "-", "") + "/0?term=2", Url: "https://gchat.qpic.cn/gchatpic_new/1/0-0-" + strings.ReplaceAll(binary.CalculateImageResourceId(md5)[1:37], "-", "") + "/0?term=2",
} }
} }
@ -95,8 +91,8 @@ func (e *GroupImageElement) Pack() (r []*msg.Elem) {
Useful: proto.Int32(1), Useful: proto.Int32(1),
// Origin: 1, // Origin: 1,
BizType: proto.Int32(5), BizType: proto.Int32(5),
Width: &e.Width, Width: proto.Int32(720),
Height: &e.Height, Height: proto.Int32(480),
FileId: proto.Int32(int32(e.FileId)), FileId: proto.Int32(int32(e.FileId)),
FilePath: &e.ImageId, FilePath: &e.ImageId,
ImageType: &e.ImageType, ImageType: &e.ImageType,

View File

@ -462,8 +462,6 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement {
FileId: int64(elem.CustomFace.GetFileId()), FileId: int64(elem.CustomFace.GetFileId()),
ImageId: elem.CustomFace.GetFilePath(), ImageId: elem.CustomFace.GetFilePath(),
Size: elem.CustomFace.GetSize(), Size: elem.CustomFace.GetSize(),
Width: elem.CustomFace.GetWidth(),
Height: elem.CustomFace.GetHeight(),
Url: url, Url: url,
ImageBizType: func() ImageBizType { ImageBizType: func() ImageBizType {
if len(elem.CustomFace.PbReserve) == 0 { if len(elem.CustomFace.PbReserve) == 0 {
@ -561,8 +559,6 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement {
FileId: int64(flash.FlashTroopPic.GetFileId()), FileId: int64(flash.FlashTroopPic.GetFileId()),
ImageId: flash.FlashTroopPic.GetFilePath(), ImageId: flash.FlashTroopPic.GetFilePath(),
Size: flash.FlashTroopPic.GetSize(), Size: flash.FlashTroopPic.GetSize(),
Width: flash.FlashTroopPic.GetWidth(),
Height: flash.FlashTroopPic.GetHeight(),
Md5: flash.FlashTroopPic.Md5, Md5: flash.FlashTroopPic.Md5,
Flash: true, Flash: true,
}) })