From 775580616f6c9cf247e7f3cb433a531bc4a910e0 Mon Sep 17 00:00:00 2001 From: eatmoreapple <15055461510@163.com> Date: Sun, 1 Aug 2021 01:24:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=81=94=E7=B3=BB=E4=BA=BA?= =?UTF-8?q?=E7=BD=AE=E9=A1=B6=E5=92=8C=E5=8F=96=E6=B6=88=E7=BD=AE=E9=A1=B6?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_test.go | 25 +++++++++++++++++++++++++ caller.go | 9 +++++++++ client.go | 16 ++++++++++++++++ user.go | 12 ++++++++++++ 4 files changed, 62 insertions(+) diff --git a/bot_test.go b/bot_test.go index 8a69621..8ad73be 100644 --- a/bot_test.go +++ b/bot_test.go @@ -2,6 +2,7 @@ package openwechat import ( "testing" + "time" ) func TestLogin(t *testing.T) { @@ -85,3 +86,27 @@ func TestGroups(t *testing.T) { } t.Log(groups) } + +func TestPinUser(t *testing.T) { + bot := DefaultBot(Desktop) + if err := bot.Login(); err != nil { + t.Error(err) + return + } + user, err := bot.GetCurrentUser() + if err != nil { + t.Error(err) + return + } + friends, err := user.Friends() + if err != nil { + t.Error(err) + return + } + if friends.Count() > 0 { + f := friends.First() + f.Pin() + time.Sleep(time.Second * 5) + f.UnPin() + } +} diff --git a/caller.go b/caller.go index f78549b..798dd17 100644 --- a/caller.go +++ b/caller.go @@ -336,6 +336,15 @@ func (c *Caller) WebWxStatusAsRead(request *BaseRequest, info *LoginInfo, msg *M return parseBaseResponseError(resp) } +// WebWxRelationPin 将联系人是否置顶 +func (c *Caller) WebWxRelationPin(request *BaseRequest, user *User, op uint8) error { + resp, err := c.Client.WebWxRelationPin(request, op, user) + if err != nil { + return err + } + return parseBaseResponseError(resp) +} + // 处理响应返回的结果是否正常 func parseBaseResponseError(resp *http.Response) error { defer resp.Body.Close() diff --git a/client.go b/client.go index 8260eee..2203496 100644 --- a/client.go +++ b/client.go @@ -674,3 +674,19 @@ func (c *Client) WebWxStatusAsRead(request *BaseRequest, info *LoginInfo, msg *M req.Header.Add("Content-Type", jsonContentType) return c.Do(req) } + +// WebWxRelationPin 联系人置顶接口 +func (c *Client) WebWxRelationPin(request *BaseRequest, op uint8, user *User) (*http.Response, error) { + path, _ := url.Parse(c.domain.BaseHost() + webwxoplog) + content := map[string]interface{}{ + "BaseRequest": request, + "CmdId": 3, + "OP": op, + "RemarkName": user.RemarkName, + "UserName": user.UserName, + } + body, _ := ToBuffer(content) + req, _ := http.NewRequest(http.MethodPost, path.String(), body) + req.Header.Add("Content-Type", jsonContentType) + return c.Do(req) +} diff --git a/user.go b/user.go index d63d3c2..4a07011 100644 --- a/user.go +++ b/user.go @@ -110,6 +110,18 @@ func (u *User) IsMP() bool { return u.VerifyFlag == 8 || u.VerifyFlag == 24 || u.VerifyFlag == 136 } +// Pin 将联系人置顶 +func (u *User) Pin() error { + req := u.Self.Bot.storage.Request + return u.Self.Bot.Caller.WebWxRelationPin(req, u, 1) +} + +// UnPin 将联系人取消置顶 +func (u *User) UnPin() error { + req := u.Self.Bot.storage.Request + return u.Self.Bot.Caller.WebWxRelationPin(req, u, 0) +} + // Self 自己,当前登录用户对象 type Self struct { *User