This commit is contained in:
eatmoreapple 2021-08-16 21:38:51 +08:00
parent ef31047cc5
commit 57ad498e69
6 changed files with 69 additions and 44 deletions

View File

@ -293,8 +293,19 @@ func (c *Client) WebWxSendMsg(msg *SendMessage, info *LoginInfo, request *BaseRe
} }
// WebWxGetHeadImg 获取用户的头像 // WebWxGetHeadImg 获取用户的头像
func (c *Client) WebWxGetHeadImg(headImageUrl string) (*http.Response, error) { func (c *Client) WebWxGetHeadImg(user *User) (*http.Response, error) {
path := c.Domain.BaseHost() + headImageUrl 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) req, _ := http.NewRequest(http.MethodGet, path, nil)
return c.Do(req) return c.Do(req)
} }

View File

@ -227,6 +227,7 @@ func (g *Group) Members() (Members, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
group.MemberList.init(g.Self)
return group.MemberList, nil return group.MemberList, nil
} }

View File

@ -90,11 +90,7 @@ bot.HotLogin(reloadStorage)
```go ```go
// 热登陆存储接口 // 热登陆存储接口
type HotReloadStorage interface { type HotReloadStorage io.ReadWriteCloser
GetHotReloadStorageItem() HotReloadStorageItem // 获取HotReloadStorageItem
Dump(item HotReloadStorageItem) error // 实现该方法, 将必要信息进行序列化
Load() error // 实现该方法, 将存储媒介的内容反序列化
}
``` ```
`NewJsonFileHotReloadStorage`简单实现了该接口,它采用`JSON`的方式存储会话信息。 `NewJsonFileHotReloadStorage`简单实现了该接口,它采用`JSON`的方式存储会话信息。

View File

@ -274,6 +274,18 @@ msg.Agree()
#### 设置为已读
```go
msg.AsRead()
```
该当前消息设置为已读
#### 设置消息的上下文 #### 设置消息的上下文
用于多个消息处理函数之间的通信,并且是协程安全的。 用于多个消息处理函数之间的通信,并且是协程安全的。
@ -320,6 +332,14 @@ sentMsg.Revoke()
#### 判断是否可以撤回
```go
sentMsg.CanRevoke()
```
#### 转发给好友 #### 转发给好友
```go ```go

61
url.go
View File

@ -5,49 +5,50 @@ type mode string
// 向外暴露2种模式 // 向外暴露2种模式
const ( const (
Normal mode = "normal" Normal mode = "normal"
Desktop mode = "desktop" // 突破网页版登录限制 Desktop mode = "desktop" // 突破网页版登录限制
) )
const ( const (
webwxinit = "/cgi-bin/mmwebwx-bin/webwxinit" webwxinit = "/cgi-bin/mmwebwx-bin/webwxinit"
webwxstatusnotify = "/cgi-bin/mmwebwx-bin/webwxstatusnotify" webwxstatusnotify = "/cgi-bin/mmwebwx-bin/webwxstatusnotify"
webwxsync = "/cgi-bin/mmwebwx-bin/webwxsync" webwxsync = "/cgi-bin/mmwebwx-bin/webwxsync"
webwxsendmsg = "/cgi-bin/mmwebwx-bin/webwxsendmsg" webwxsendmsg = "/cgi-bin/mmwebwx-bin/webwxsendmsg"
webwxgetcontact = "/cgi-bin/mmwebwx-bin/webwxgetcontact" webwxgetcontact = "/cgi-bin/mmwebwx-bin/webwxgetcontact"
webwxsendmsgimg = "/cgi-bin/mmwebwx-bin/webwxsendmsgimg" webwxsendmsgimg = "/cgi-bin/mmwebwx-bin/webwxsendmsgimg"
webwxsendappmsg = "/cgi-bin/mmwebwx-bin/webwxsendappmsg" webwxsendappmsg = "/cgi-bin/mmwebwx-bin/webwxsendappmsg"
webwxbatchgetcontact = "/cgi-bin/mmwebwx-bin/webwxbatchgetcontact" webwxbatchgetcontact = "/cgi-bin/mmwebwx-bin/webwxbatchgetcontact"
webwxoplog = "/cgi-bin/mmwebwx-bin/webwxoplog" webwxoplog = "/cgi-bin/mmwebwx-bin/webwxoplog"
webwxverifyuser = "/cgi-bin/mmwebwx-bin/webwxverifyuser" webwxverifyuser = "/cgi-bin/mmwebwx-bin/webwxverifyuser"
synccheck = "/cgi-bin/mmwebwx-bin/synccheck" synccheck = "/cgi-bin/mmwebwx-bin/synccheck"
webwxuploadmedia = "/cgi-bin/mmwebwx-bin/webwxuploadmedia" webwxuploadmedia = "/cgi-bin/mmwebwx-bin/webwxuploadmedia"
webwxgetmsgimg = "/cgi-bin/mmwebwx-bin/webwxgetmsgimg" webwxgetmsgimg = "/cgi-bin/mmwebwx-bin/webwxgetmsgimg"
webwxgetvoice = "/cgi-bin/mmwebwx-bin/webwxgetvoice" webwxgetvoice = "/cgi-bin/mmwebwx-bin/webwxgetvoice"
webwxgetvideo = "/cgi-bin/mmwebwx-bin/webwxgetvideo" webwxgetvideo = "/cgi-bin/mmwebwx-bin/webwxgetvideo"
webwxlogout = "/cgi-bin/mmwebwx-bin/webwxlogout" webwxlogout = "/cgi-bin/mmwebwx-bin/webwxlogout"
webwxgetmedia = "/cgi-bin/mmwebwx-bin/webwxgetmedia" webwxgetmedia = "/cgi-bin/mmwebwx-bin/webwxgetmedia"
webwxupdatechatroom = "/cgi-bin/mmwebwx-bin/webwxupdatechatroom" webwxupdatechatroom = "/cgi-bin/mmwebwx-bin/webwxupdatechatroom"
webwxrevokemsg = "/cgi-bin/mmwebwx-bin/webwxrevokemsg" webwxrevokemsg = "/cgi-bin/mmwebwx-bin/webwxrevokemsg"
webwxcheckupload = "/cgi-bin/mmwebwx-bin/webwxcheckupload" webwxcheckupload = "/cgi-bin/mmwebwx-bin/webwxcheckupload"
webwxpushloginurl = "/cgi-bin/mmwebwx-bin/webwxpushloginurl" webwxpushloginurl = "/cgi-bin/mmwebwx-bin/webwxpushloginurl"
webwxgeticon = "/cgi-bin/mmwebwx-bin/webwxgeticon"
webwxnewloginpage = "https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage" webwxnewloginpage = "https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage"
jslogin = "https://login.wx.qq.com/jslogin" jslogin = "https://login.wx.qq.com/jslogin"
login = "https://login.wx.qq.com/cgi-bin/mmwebwx-bin/login" login = "https://login.wx.qq.com/cgi-bin/mmwebwx-bin/login"
qrcode = "https://login.weixin.qq.com/qrcode/" qrcode = "https://login.weixin.qq.com/qrcode/"
) )
type WechatDomain string type WechatDomain string
func (w WechatDomain) BaseHost() string { func (w WechatDomain) BaseHost() string {
return "https://" + string(w) return "https://" + string(w)
} }
func (w WechatDomain) FileHost() string { func (w WechatDomain) FileHost() string {
return "https://file." + string(w) return "https://file." + string(w)
} }
func (w WechatDomain) SyncHost() string { func (w WechatDomain) SyncHost() string {
return "https://webpush." + string(w) return "https://webpush." + string(w)
} }

10
user.go
View File

@ -1,9 +1,9 @@
package openwechat package openwechat
import ( import (
"bytes"
"errors" "errors"
"fmt" "fmt"
"io"
"net/http" "net/http"
"os" "os"
"strings" "strings"
@ -56,7 +56,7 @@ func (u *User) String() string {
// GetAvatarResponse 获取用户头像 // GetAvatarResponse 获取用户头像
func (u *User) GetAvatarResponse() (*http.Response, error) { 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 下载用户头像 // SaveAvatar 下载用户头像
@ -66,16 +66,12 @@ func (u *User) SaveAvatar(filename string) error {
return err return err
} }
defer resp.Body.Close() defer resp.Body.Close()
buffer := bytes.Buffer{}
if _, err := buffer.ReadFrom(resp.Body); err != nil {
return err
}
file, err := os.Create(filename) file, err := os.Create(filename)
if err != nil { if err != nil {
return err return err
} }
defer file.Close() defer file.Close()
_, err = file.Write(buffer.Bytes()) _, err = io.Copy(file, resp.Body)
return err return err
} }