From 9ef6c3cf3a0368bd9e10a8da2b69d2a9e8e3c28a Mon Sep 17 00:00:00 2001 From: lz1998 <875543533@qq.com> Date: Mon, 21 Feb 2022 00:22:45 +0800 Subject: [PATCH] feat: set profile detail (#254) * feat: profile detail * struct: ProfileDetailUpdate * ProfileDetailUpdate * update profile --- client/builders.go | 45 ++++++++++++++++++++++++++++++++++++++++----- client/client.go | 6 +++--- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/client/builders.go b/client/builders.go index 8b041dd0..0154ae6a 100644 --- a/client/builders.go +++ b/client/builders.go @@ -1150,15 +1150,50 @@ func (c *QQClient) buildWordSegmentationPacket(data []byte) (uint16, []byte) { return c.uniPacket("OidbSvc.0xd79", payload) } -// OidbSvc.0x4ff_9 -func (c *QQClient) buildUpdateQQNicknamePacket(name string) (uint16, []byte) { +type ProfileDetailUpdate map[uint16][]byte + +func NewProfileDetailUpdate() ProfileDetailUpdate { + return map[uint16][]byte{} +} + +func (p ProfileDetailUpdate) Nick(value string) ProfileDetailUpdate { + p[20002] = []byte(value) + return p +} + +func (p ProfileDetailUpdate) Email(value string) ProfileDetailUpdate { + p[20011] = []byte(value) + return p +} + +func (p ProfileDetailUpdate) PersonalNote(value string) ProfileDetailUpdate { + p[20019] = []byte(value) + return p +} + +func (p ProfileDetailUpdate) Company(value string) ProfileDetailUpdate { + p[24008] = []byte(value) + return p +} + +func (p ProfileDetailUpdate) College(value string) ProfileDetailUpdate { + p[20021] = []byte(value) + return p +} + +// OidbSvc.0x4ff_9_IMCore +func (c *QQClient) buildUpdateProfileDetailPacket(profileRecord map[uint16][]byte) (uint16, []byte) { b, cl := binary.OpenWriterF(func(w *binary.Writer) { w.WriteUInt32(uint32(c.Uin)) w.WriteByte(0) - w.WriteUInt32(uint32(85538)) - w.WriteStringShort(name) + w.WriteUInt16(uint16(len(profileRecord))) + for tag, value := range profileRecord { + w.WriteUInt16(tag) + w.WriteUInt16(uint16(len(value))) + w.Write(value) + } }) payload := c.packOIDBPackage(1279, 9, b) cl() - return c.uniPacket("OidbSvc.0x4ff_9", payload) + return c.uniPacket("OidbSvc.0x4ff_9_IMCore", payload) } diff --git a/client/client.go b/client/client.go index b92c8cf7..12a8ce33 100644 --- a/client/client.go +++ b/client/client.go @@ -750,9 +750,9 @@ func (g *GroupInfo) removeMember(uin int64) { }) } -// SetNickname 设置 QQ 昵称 -func (c *QQClient) SetNickname(name string) { - _, _ = c.sendAndWait(c.buildUpdateQQNicknamePacket(name)) +// UpdateProfile 修改个人资料 +func (c *QQClient) UpdateProfile(profile ProfileDetailUpdate) { + _, _ = c.sendAndWait(c.buildUpdateProfileDetailPacket(profile)) } func (c *QQClient) SetCustomServer(servers []*net.TCPAddr) {