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

client: use %x placeholder

This commit is contained in:
wdvxdr 2022-03-20 13:48:02 +08:00
parent 436482c7db
commit 714961d68f
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6
7 changed files with 15 additions and 16 deletions

View File

@ -2,7 +2,7 @@ package client
import ( import (
"crypto/md5" "crypto/md5"
"encoding/hex" "fmt"
"math/rand" "math/rand"
"time" "time"
@ -903,7 +903,7 @@ func (c *QQClient) buildOffPicUpPacket(target int64, md5 []byte, size int32) (ui
DstUin: proto.Uint64(uint64(target)), DstUin: proto.Uint64(uint64(target)),
FileMd5: md5, FileMd5: md5,
FileSize: proto.Uint64(uint64(size)), FileSize: proto.Uint64(uint64(size)),
FileName: []byte(hex.EncodeToString(md5) + ".jpg"), FileName: []byte(fmt.Sprintf("%x.jpg", md5)),
SrcTerm: proto.Uint32(5), SrcTerm: proto.Uint32(5),
PlatformType: proto.Uint32(9), PlatformType: proto.Uint32(9),
BuType: proto.Uint32(1), BuType: proto.Uint32(1),

View File

@ -2,7 +2,6 @@ package client
import ( import (
"crypto/md5" "crypto/md5"
"encoding/hex"
"net" "net"
"strconv" "strconv"
"strings" "strings"
@ -173,7 +172,7 @@ func decodeLoginResponse(c *QQClient, _ *network.IncomingPacketInfo, payload []b
} }
c.debug("unknown login response: %v", t) c.debug("unknown login response: %v", t)
for k, v := range m { for k, v := range m {
c.debug("Type: %v Value: %v", strconv.FormatInt(int64(k), 16), hex.EncodeToString(v)) c.debug("Type: %d Value: %x", k, v)
} }
return nil, errors.Errorf("unknown login response: %v", t) // ? return nil, errors.Errorf("unknown login response: %v", t) // ?
} }

View File

@ -104,7 +104,7 @@ func (c *QQClient) GetGroupFileUrl(groupCode int64, fileId string, busId int32)
return "" return ""
} }
url := i.(string) url := i.(string)
url += "?fname=" + hex.EncodeToString([]byte(fileId)) url += fmt.Sprintf("?fname=%x", fileId)
return url return url
} }

View File

@ -1,7 +1,7 @@
package client package client
import ( import (
"encoding/hex" "fmt"
"io" "io"
"math/rand" "math/rand"
"strconv" "strconv"
@ -88,7 +88,7 @@ func (s *GuildService) QueryImage(guildId, channelId uint64, hash []byte, size u
if body.IsExists { if body.IsExists {
return &message.GuildImageElement{ return &message.GuildImageElement{
FileId: body.FileId, FileId: body.FileId,
FilePath: hex.EncodeToString(hash) + ".jpg", FilePath: fmt.Sprintf("%x.jpg", hash),
Size: int32(size), Size: int32(size),
DownloadIndex: body.DownloadIndex, DownloadIndex: body.DownloadIndex,
Width: body.Width, Width: body.Width,
@ -177,7 +177,7 @@ func (c *QQClient) buildGuildImageStorePacket(guildId, channelId uint64, hash []
FileId: proto.Uint64(0), FileId: proto.Uint64(0),
FileMd5: hash, FileMd5: hash,
FileSize: &size, FileSize: &size,
FileName: []byte(hex.EncodeToString(hash) + ".jpg"), FileName: []byte(fmt.Sprintf("%x.jpg", hash)),
SrcTerm: proto.Uint32(5), SrcTerm: proto.Uint32(5),
PlatformType: proto.Uint32(9), PlatformType: proto.Uint32(9),
BuType: proto.Uint32(211), BuType: proto.Uint32(211),

View File

@ -1,7 +1,7 @@
package client package client
import ( import (
"encoding/hex" "fmt"
"io" "io"
"math/rand" "math/rand"
"strings" "strings"
@ -154,7 +154,7 @@ ok:
} }
return &message.GuildImageElement{ return &message.GuildImageElement{
FileId: rsp.FileId, FileId: rsp.FileId,
FilePath: hex.EncodeToString(fh) + ".jpg", FilePath: fmt.Sprintf("%x.jpg", fh),
Size: int32(length), Size: int32(length),
DownloadIndex: rsp.DownloadIndex, DownloadIndex: rsp.DownloadIndex,
Width: width, Width: width,
@ -214,7 +214,7 @@ func (c *QQClient) ImageOcr(img any) (*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, fmt.Sprintf("%X", e.Md5), e.Size, e.Width, e.Height))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -399,7 +399,7 @@ func decodeGroupImageDownloadResponse(_ *QQClient, _ *network.IncomingPacketInfo
if len(pkt.GetimgUrlRsp[0].FailMsg) != 0 { if len(pkt.GetimgUrlRsp[0].FailMsg) != 0 {
return nil, errors.New(utils.B2S(pkt.GetimgUrlRsp[0].FailMsg)) return nil, errors.New(utils.B2S(pkt.GetimgUrlRsp[0].FailMsg))
} }
return "https://" + utils.B2S(pkt.GetimgUrlRsp[0].DownDomain) + utils.B2S(pkt.GetimgUrlRsp[0].BigDownPara), nil return fmt.Sprintf("https://%s%s", pkt.GetimgUrlRsp[0].DownDomain, pkt.GetimgUrlRsp[0].BigDownPara), nil
} }
// OidbSvc.0xe07_0 // OidbSvc.0xe07_0

View File

@ -3,6 +3,7 @@ package client
import ( import (
"crypto/md5" "crypto/md5"
"encoding/hex" "encoding/hex"
"fmt"
"io" "io"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -90,7 +91,7 @@ func (c *QQClient) UploadVoice(target message.Source, voice io.ReadSeeker) (*mes
FileType: proto.Int32(4), FileType: proto.Int32(4),
SrcUin: &c.Uin, SrcUin: &c.Uin,
FileMd5: fh, FileMd5: fh,
FileName: proto.String(hex.EncodeToString(fh) + ".amr"), FileName: proto.String(fmt.Sprintf("%x.amr", fh)),
FileSize: proto.Int32(int32(length)), FileSize: proto.Int32(int32(length)),
BoolValid: proto.Bool(true), BoolValid: proto.Bool(true),
} }
@ -259,7 +260,7 @@ func (c *QQClient) buildPttShortVideoProto(target message.Source, videoHash, thu
ChatType: chatType, ChatType: chatType,
ClientType: 2, ClientType: 2,
Info: &pttcenter.ShortVideoFileInfo{ Info: &pttcenter.ShortVideoFileInfo{
FileName: hex.EncodeToString(videoHash) + ".mp4", FileName: fmt.Sprintf("%x.mp4", videoHash),
FileMd5: videoHash, FileMd5: videoHash,
ThumbFileMd5: thumbHash, ThumbFileMd5: thumbHash,
FileSize: videoSize, FileSize: videoSize,

View File

@ -1,7 +1,6 @@
package message package message
import ( import (
"encoding/hex"
"fmt" "fmt"
"github.com/Mrs4s/MiraiGo/binary" "github.com/Mrs4s/MiraiGo/binary"
@ -126,7 +125,7 @@ func (e *ShortVideoElement) Pack() (r []*msg.Elem) {
video := &msg.VideoFile{ video := &msg.VideoFile{
FileUuid: e.Uuid, FileUuid: e.Uuid,
FileMd5: e.Md5, FileMd5: e.Md5,
FileName: []byte(hex.EncodeToString(e.Md5) + ".mp4"), FileName: []byte(fmt.Sprintf("%x.mp4", e.Md5)),
FileFormat: proto.Int32(3), FileFormat: proto.Int32(3),
FileTime: proto.Int32(10), FileTime: proto.Int32(10),
FileSize: proto.Int32(e.Size), FileSize: proto.Int32(e.Size),