diff --git a/client/internal/highway/bdh.go b/client/internal/highway/bdh.go index 7491e588..5fab686a 100644 --- a/client/internal/highway/bdh.go +++ b/client/internal/highway/bdh.go @@ -64,7 +64,7 @@ func (s *Session) UploadBDH(input BdhInput) ([]byte, error) { sum, length := utils.ComputeMd5AndLength(input.Body) _, _ = input.Body.Seek(0, io.SeekStart) if err := input.encrypt(s.SessionKey); err != nil { - return nil, errors.Wrap(err, "encrypt error") + return nil, err } conn, err := net.DialTimeout("tcp", addr, time.Second*20) if err != nil { @@ -94,16 +94,7 @@ func (s *Session) UploadBDH(input BdhInput) ([]byte, error) { } ch := md5.Sum(chunk) head, _ := proto.Marshal(&pb.ReqDataHighwayHead{ - MsgBasehead: &pb.DataHighwayHead{ - Version: 1, - Uin: s.Uin, - Command: "PicUp.DataUp", - Seq: s.nextSeq(), - Appid: s.AppID, - Dataflag: 4096, - CommandId: input.CommandID, - LocaleId: 2052, - }, + MsgBasehead: s.dataHighwayHead(4096, input.CommandID, 2052), MsgSeghead: &pb.SegHead{ Filesize: length, Dataoffset: int64(offset), @@ -157,7 +148,7 @@ func (s *Session) UploadBDHMultiThread(input BdhMultiThreadInput, threadCount in addr := s.SsoAddr[0].String() if err := input.encrypt(s.SessionKey); err != nil { - return nil, errors.Wrap(err, "encrypt error") + return nil, err } type BlockMetaData struct { @@ -236,16 +227,7 @@ func (s *Session) UploadBDHMultiThread(input BdhMultiThreadInput, threadCount in } ch := md5.Sum(buffer) head, _ := proto.Marshal(&pb.ReqDataHighwayHead{ - MsgBasehead: &pb.DataHighwayHead{ - Version: 1, - Uin: s.Uin, - Command: "PicUp.DataUp", - Seq: s.nextSeq(), - Appid: s.AppID, - Dataflag: 4096, - CommandId: input.CommandID, - LocaleId: 2052, - }, + MsgBasehead: s.dataHighwayHead(4096, input.CommandID, 2052), MsgSeghead: &pb.SegHead{ Filesize: input.Size, Dataoffset: block.Offset, diff --git a/client/internal/highway/highway.go b/client/internal/highway/highway.go index 7d7c1ab0..7e74021d 100644 --- a/client/internal/highway/highway.go +++ b/client/internal/highway/highway.go @@ -74,16 +74,7 @@ func (s *Session) Upload(addr Addr, input Input) error { } ch := md5.Sum(chunk) head, _ := proto.Marshal(&pb.ReqDataHighwayHead{ - MsgBasehead: &pb.DataHighwayHead{ - Version: 1, - Uin: s.Uin, - Command: "PicUp.DataUp", - Seq: s.nextSeq(), - Appid: s.AppID, - Dataflag: 4096, - CommandId: input.CommandID, - LocaleId: 2052, - }, + MsgBasehead: s.dataHighwayHead(4096, input.CommandID, 2052), MsgSeghead: &pb.SegHead{ Filesize: length, Dataoffset: int64(offset), @@ -144,16 +135,7 @@ func (s *Session) UploadExciting(input ExcitingInput) ([]byte, error) { } ch := md5.Sum(chunk) head, _ := proto.Marshal(&pb.ReqDataHighwayHead{ - MsgBasehead: &pb.DataHighwayHead{ - Version: 1, - Uin: s.Uin, - Command: "PicUp.DataUp", - Seq: s.nextSeq(), - Appid: s.AppID, - Dataflag: 0, - CommandId: input.CommandID, - LocaleId: 0, - }, + MsgBasehead: s.dataHighwayHead(0, input.CommandID, 0), MsgSeghead: &pb.SegHead{ Filesize: fileLength, Dataoffset: offset, @@ -202,6 +184,19 @@ func (s *Session) nextSeq() int32 { return atomic.AddInt32(&s.seq, 2) } +func (s *Session) dataHighwayHead(flag, cmd, locale int32) *pb.DataHighwayHead { + return &pb.DataHighwayHead{ + Version: 1, + Uin: s.Uin, + Command: "PicUp.DataUp", + Seq: s.nextSeq(), + Appid: s.AppID, + Dataflag: flag, + CommandId: cmd, + LocaleId: locale, + } +} + func (s *Session) sendHeartbreak(conn net.Conn) error { head, _ := proto.Marshal(&pb.ReqDataHighwayHead{ MsgBasehead: &pb.DataHighwayHead{ diff --git a/client/private_msg.go b/client/private_msg.go index ac118d66..be1d1b66 100644 --- a/client/private_msg.go +++ b/client/private_msg.go @@ -162,20 +162,9 @@ func (c *QQClient) buildFriendSendingPacket(target int64, msgSeq, r, pkgNum, pkg Ptt: ptt, }, }, - MsgSeq: &msgSeq, - MsgRand: &r, - SyncCookie: func() []byte { - cookie := &msg.SyncCookie{ - Time: &time, - Ran1: proto.Int64(rand.Int63()), - Ran2: proto.Int64(rand.Int63()), - Const1: &syncConst1, - Const2: &syncConst2, - Const3: proto.Int64(0x1d), - } - b, _ := proto.Marshal(cookie) - return b - }(), + MsgSeq: &msgSeq, + MsgRand: &r, + SyncCookie: syncCookie(time), } payload, _ := proto.Marshal(req) return c.uniPacket("MessageSvc.PbSendMsg", payload) @@ -194,26 +183,16 @@ func (c *QQClient) buildGroupTempSendingPacket(groupUin, target int64, msgSeq, r Elems: message.ToProtoElems(m.Elements, false), }, }, - MsgSeq: &msgSeq, - MsgRand: &r, - SyncCookie: func() []byte { - cookie := &msg.SyncCookie{ - Time: &time, - Ran1: proto.Int64(rand.Int63()), - Ran2: proto.Int64(rand.Int63()), - Const1: &syncConst1, - Const2: &syncConst2, - Const3: proto.Int64(0x1d), - } - b, _ := proto.Marshal(cookie) - return b - }(), + MsgSeq: &msgSeq, + MsgRand: &r, + SyncCookie: syncCookie(time), } payload, _ := proto.Marshal(req) return c.uniPacket("MessageSvc.PbSendMsg", payload) } func (c *QQClient) buildWPATempSendingPacket(uin int64, sig []byte, msgSeq, r int32, time int64, m *message.SendingMessage) (uint16, []byte) { + req := &msg.SendMessageRequest{ RoutingHead: &msg.RoutingHead{WpaTmp: &msg.WPATmp{ ToUin: proto.Uint64(uint64(uin)), @@ -225,21 +204,22 @@ func (c *QQClient) buildWPATempSendingPacket(uin int64, sig []byte, msgSeq, r in Elems: message.ToProtoElems(m.Elements, false), }, }, - MsgSeq: &msgSeq, - MsgRand: &r, - SyncCookie: func() []byte { - cookie := &msg.SyncCookie{ - Time: &time, - Ran1: proto.Int64(rand.Int63()), - Ran2: proto.Int64(rand.Int63()), - Const1: &syncConst1, - Const2: &syncConst2, - Const3: proto.Int64(0x1d), - } - b, _ := proto.Marshal(cookie) - return b - }(), + MsgSeq: &msgSeq, + MsgRand: &r, + SyncCookie: syncCookie(time), } payload, _ := proto.Marshal(req) return c.uniPacket("MessageSvc.PbSendMsg", payload) } + +func syncCookie(time int64) []byte { + cookie, _ := proto.Marshal(&msg.SyncCookie{ + Time: &time, + Ran1: proto.Int64(rand.Int63()), + Ran2: proto.Int64(rand.Int63()), + Const1: &syncConst1, + Const2: &syncConst2, + Const3: proto.Int64(0x1d), + }) + return cookie +}