From 57ad498e69aabd08ecf22d801521cfd3815efe0f Mon Sep 17 00:00:00 2001 From: eatmoreapple <15055461510@163.com> Date: Mon, 16 Aug 2021 21:38:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BE=A4=E6=88=90=E5=91=98?= =?UTF-8?q?=E5=A4=B4=E5=83=8F=E6=97=A0=E6=B3=95=E4=B8=8B=E8=BD=BD=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20=20https://github.com/eatmoreapple/openwec?= =?UTF-8?q?hat/issues/69?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 15 ++++++++++-- relations.go | 1 + source/bot.md | 6 +---- source/message.md | 20 ++++++++++++++++ url.go | 61 ++++++++++++++++++++++++----------------------- user.go | 10 +++----- 6 files changed, 69 insertions(+), 44 deletions(-) diff --git a/client.go b/client.go index 74c7ff7..b49db35 100644 --- a/client.go +++ b/client.go @@ -293,8 +293,19 @@ func (c *Client) WebWxSendMsg(msg *SendMessage, info *LoginInfo, request *BaseRe } // WebWxGetHeadImg 获取用户的头像 -func (c *Client) WebWxGetHeadImg(headImageUrl string) (*http.Response, error) { - path := c.Domain.BaseHost() + headImageUrl +func (c *Client) WebWxGetHeadImg(user *User) (*http.Response, error) { + var path string + if user.HeadImgUrl != "" { + path = c.Domain.BaseHost() + user.HeadImgUrl + } else { + params := url.Values{} + params.Add("username", user.UserName) + params.Add("skey", user.Self.Bot.Storage.Request.Skey) + params.Add("type", "big") + URL, _ := url.Parse(c.Domain.BaseHost() + webwxgeticon) + URL.RawQuery = params.Encode() + path = URL.String() + } req, _ := http.NewRequest(http.MethodGet, path, nil) return c.Do(req) } diff --git a/relations.go b/relations.go index 4cf6df4..e8c1ec5 100644 --- a/relations.go +++ b/relations.go @@ -227,6 +227,7 @@ func (g *Group) Members() (Members, error) { if err != nil { return nil, err } + group.MemberList.init(g.Self) return group.MemberList, nil } diff --git a/source/bot.md b/source/bot.md index ba2dd89..d02d223 100644 --- a/source/bot.md +++ b/source/bot.md @@ -90,11 +90,7 @@ bot.HotLogin(reloadStorage) ```go // 热登陆存储接口 -type HotReloadStorage interface { - GetHotReloadStorageItem() HotReloadStorageItem // 获取HotReloadStorageItem - Dump(item HotReloadStorageItem) error // 实现该方法, 将必要信息进行序列化 - Load() error // 实现该方法, 将存储媒介的内容反序列化 -} +type HotReloadStorage io.ReadWriteCloser ``` `NewJsonFileHotReloadStorage`简单实现了该接口,它采用`JSON`的方式存储会话信息。 diff --git a/source/message.md b/source/message.md index 3d7f9fa..c50e37b 100644 --- a/source/message.md +++ b/source/message.md @@ -274,6 +274,18 @@ msg.Agree() +#### 设置为已读 + +```go +msg.AsRead() +``` + +该当前消息设置为已读 + + + + + #### 设置消息的上下文 用于多个消息处理函数之间的通信,并且是协程安全的。 @@ -320,6 +332,14 @@ sentMsg.Revoke() +#### 判断是否可以撤回 + +```go +sentMsg.CanRevoke() +``` + + + #### 转发给好友 ```go diff --git a/url.go b/url.go index d329e9a..af6da1d 100644 --- a/url.go +++ b/url.go @@ -5,49 +5,50 @@ type mode string // 向外暴露2种模式 const ( - Normal mode = "normal" - Desktop mode = "desktop" // 突破网页版登录限制 + Normal mode = "normal" + Desktop mode = "desktop" // 突破网页版登录限制 ) const ( - webwxinit = "/cgi-bin/mmwebwx-bin/webwxinit" - webwxstatusnotify = "/cgi-bin/mmwebwx-bin/webwxstatusnotify" - webwxsync = "/cgi-bin/mmwebwx-bin/webwxsync" - webwxsendmsg = "/cgi-bin/mmwebwx-bin/webwxsendmsg" - webwxgetcontact = "/cgi-bin/mmwebwx-bin/webwxgetcontact" - webwxsendmsgimg = "/cgi-bin/mmwebwx-bin/webwxsendmsgimg" - webwxsendappmsg = "/cgi-bin/mmwebwx-bin/webwxsendappmsg" - webwxbatchgetcontact = "/cgi-bin/mmwebwx-bin/webwxbatchgetcontact" - webwxoplog = "/cgi-bin/mmwebwx-bin/webwxoplog" - webwxverifyuser = "/cgi-bin/mmwebwx-bin/webwxverifyuser" - synccheck = "/cgi-bin/mmwebwx-bin/synccheck" - webwxuploadmedia = "/cgi-bin/mmwebwx-bin/webwxuploadmedia" - webwxgetmsgimg = "/cgi-bin/mmwebwx-bin/webwxgetmsgimg" - webwxgetvoice = "/cgi-bin/mmwebwx-bin/webwxgetvoice" - webwxgetvideo = "/cgi-bin/mmwebwx-bin/webwxgetvideo" - webwxlogout = "/cgi-bin/mmwebwx-bin/webwxlogout" - webwxgetmedia = "/cgi-bin/mmwebwx-bin/webwxgetmedia" - webwxupdatechatroom = "/cgi-bin/mmwebwx-bin/webwxupdatechatroom" - webwxrevokemsg = "/cgi-bin/mmwebwx-bin/webwxrevokemsg" - webwxcheckupload = "/cgi-bin/mmwebwx-bin/webwxcheckupload" - webwxpushloginurl = "/cgi-bin/mmwebwx-bin/webwxpushloginurl" + webwxinit = "/cgi-bin/mmwebwx-bin/webwxinit" + webwxstatusnotify = "/cgi-bin/mmwebwx-bin/webwxstatusnotify" + webwxsync = "/cgi-bin/mmwebwx-bin/webwxsync" + webwxsendmsg = "/cgi-bin/mmwebwx-bin/webwxsendmsg" + webwxgetcontact = "/cgi-bin/mmwebwx-bin/webwxgetcontact" + webwxsendmsgimg = "/cgi-bin/mmwebwx-bin/webwxsendmsgimg" + webwxsendappmsg = "/cgi-bin/mmwebwx-bin/webwxsendappmsg" + webwxbatchgetcontact = "/cgi-bin/mmwebwx-bin/webwxbatchgetcontact" + webwxoplog = "/cgi-bin/mmwebwx-bin/webwxoplog" + webwxverifyuser = "/cgi-bin/mmwebwx-bin/webwxverifyuser" + synccheck = "/cgi-bin/mmwebwx-bin/synccheck" + webwxuploadmedia = "/cgi-bin/mmwebwx-bin/webwxuploadmedia" + webwxgetmsgimg = "/cgi-bin/mmwebwx-bin/webwxgetmsgimg" + webwxgetvoice = "/cgi-bin/mmwebwx-bin/webwxgetvoice" + webwxgetvideo = "/cgi-bin/mmwebwx-bin/webwxgetvideo" + webwxlogout = "/cgi-bin/mmwebwx-bin/webwxlogout" + webwxgetmedia = "/cgi-bin/mmwebwx-bin/webwxgetmedia" + webwxupdatechatroom = "/cgi-bin/mmwebwx-bin/webwxupdatechatroom" + webwxrevokemsg = "/cgi-bin/mmwebwx-bin/webwxrevokemsg" + webwxcheckupload = "/cgi-bin/mmwebwx-bin/webwxcheckupload" + webwxpushloginurl = "/cgi-bin/mmwebwx-bin/webwxpushloginurl" + webwxgeticon = "/cgi-bin/mmwebwx-bin/webwxgeticon" - webwxnewloginpage = "https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage" - jslogin = "https://login.wx.qq.com/jslogin" - login = "https://login.wx.qq.com/cgi-bin/mmwebwx-bin/login" - qrcode = "https://login.weixin.qq.com/qrcode/" + webwxnewloginpage = "https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage" + jslogin = "https://login.wx.qq.com/jslogin" + login = "https://login.wx.qq.com/cgi-bin/mmwebwx-bin/login" + qrcode = "https://login.weixin.qq.com/qrcode/" ) type WechatDomain string func (w WechatDomain) BaseHost() string { - return "https://" + string(w) + return "https://" + string(w) } func (w WechatDomain) FileHost() string { - return "https://file." + string(w) + return "https://file." + string(w) } func (w WechatDomain) SyncHost() string { - return "https://webpush." + string(w) + return "https://webpush." + string(w) } diff --git a/user.go b/user.go index ae49c14..28d3f94 100644 --- a/user.go +++ b/user.go @@ -1,9 +1,9 @@ package openwechat import ( - "bytes" "errors" "fmt" + "io" "net/http" "os" "strings" @@ -56,7 +56,7 @@ func (u *User) String() string { // GetAvatarResponse 获取用户头像 func (u *User) GetAvatarResponse() (*http.Response, error) { - return u.Self.Bot.Caller.Client.WebWxGetHeadImg(u.HeadImgUrl) + return u.Self.Bot.Caller.Client.WebWxGetHeadImg(u) } // SaveAvatar 下载用户头像 @@ -66,16 +66,12 @@ func (u *User) SaveAvatar(filename string) error { return err } defer resp.Body.Close() - buffer := bytes.Buffer{} - if _, err := buffer.ReadFrom(resp.Body); err != nil { - return err - } file, err := os.Create(filename) if err != nil { return err } defer file.Close() - _, err = file.Write(buffer.Bytes()) + _, err = io.Copy(file, resp.Body) return err }