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

Merge pull request #66 from wdvxdr1123/master

fix gif
This commit is contained in:
Mrs4s 2020-11-15 00:02:42 +08:00 committed by GitHub
commit 6b9dd7feaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 23 deletions

View File

@ -7,6 +7,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"image"
"io" "io"
"math" "math"
"math/rand" "math/rand"
@ -645,7 +646,12 @@ func (c *QQClient) UploadGroupImage(groupCode int64, img []byte) (*message.Group
} }
return nil, errors.New("upload failed") return nil, errors.New("upload failed")
ok: ok:
return message.NewGroupImage(binary.CalculateImageResourceId(h[:]), h[:], rsp.FileId, int32(len(img)), rsp.Width, rsp.Height), nil i, _, _ := image.DecodeConfig(bytes.NewReader(img))
var imageType int32 = 1000
if bytes.HasPrefix(img, []byte{0x47, 0x49, 0x46, 0x38}) {
imageType = 2000
}
return message.NewGroupImage(binary.CalculateImageResourceId(h[:]), h[:], rsp.FileId, int32(len(img)), int32(i.Width), int32(i.Height), imageType), nil
} }
func (c *QQClient) UploadPrivateImage(target int64, img []byte) (*message.FriendImageElement, error) { func (c *QQClient) UploadPrivateImage(target int64, img []byte) (*message.FriendImageElement, error) {
@ -700,7 +706,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), nil return message.NewGroupImage(binary.CalculateImageResourceId(hash), hash, rsp.FileId, size, rsp.Width, rsp.Height, 1000), nil
} }
return nil, errors.New("image not exists") return nil, errors.New("image not exists")
} }

View File

@ -23,13 +23,14 @@ type ImageElement struct {
} }
type GroupImageElement struct { type GroupImageElement struct {
ImageId string ImageId string
FileId int64 FileId int64
Size int32 ImageType int32
Width int32 Size int32
Height int32 Width int32
Md5 []byte Height int32
Url string Md5 []byte
Url string
} }
type VoiceElement struct { type VoiceElement struct {
@ -143,15 +144,16 @@ func NewImage(data []byte) *ImageElement {
} }
} }
func NewGroupImage(id string, md5 []byte, fid int64, size, width, height int32) *GroupImageElement { func NewGroupImage(id string, md5 []byte, fid int64, size, width, height, imageType int32) *GroupImageElement {
return &GroupImageElement{ return &GroupImageElement{
ImageId: id, ImageId: id,
FileId: fid, FileId: fid,
Md5: md5, Md5: md5,
Size: size, Size: size,
Width: width, ImageType: imageType,
Height: height, Width: width,
Url: "http://gchat.qpic.cn/gchatpic_new/1/0-0-" + strings.ReplaceAll(binary.CalculateImageResourceId(md5)[1:37], "-", "") + "/0?term=2", Height: height,
Url: "http://gchat.qpic.cn/gchatpic_new/1/0-0-" + strings.ReplaceAll(binary.CalculateImageResourceId(md5)[1:37], "-", "") + "/0?term=2",
} }
} }

View File

@ -75,12 +75,16 @@ func (e *GroupImageElement) Pack() (r []*msg.Elem) {
CustomFace: &msg.CustomFace{ CustomFace: &msg.CustomFace{
FileType: 66, FileType: 66,
Useful: 1, Useful: 1,
Origin: 1, //Origin: 1,
FileId: int32(e.FileId), BizType: 5,
FilePath: e.ImageId, Width: e.Width,
Size: e.Size, Height: e.Height,
Md5: e.Md5[:], FileId: int32(e.FileId),
Flag: make([]byte, 4), FilePath: e.ImageId,
ImageType: e.ImageType,
Size: e.Size,
Md5: e.Md5[:],
Flag: make([]byte, 4),
//OldData: imgOld, //OldData: imgOld,
}, },
}) })