修复群成员头像无法下载的问题 https://github.com/eatmoreapple/openwechat/issues/69
This commit is contained in:
parent
ef31047cc5
commit
57ad498e69
15
client.go
15
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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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`的方式存储会话信息。
|
||||
|
@ -274,6 +274,18 @@ msg.Agree()
|
||||
|
||||
|
||||
|
||||
#### 设置为已读
|
||||
|
||||
```go
|
||||
msg.AsRead()
|
||||
```
|
||||
|
||||
该当前消息设置为已读
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#### 设置消息的上下文
|
||||
|
||||
用于多个消息处理函数之间的通信,并且是协程安全的。
|
||||
@ -320,6 +332,14 @@ sentMsg.Revoke()
|
||||
|
||||
|
||||
|
||||
#### 判断是否可以撤回
|
||||
|
||||
```go
|
||||
sentMsg.CanRevoke()
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### 转发给好友
|
||||
|
||||
```go
|
||||
|
61
url.go
61
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)
|
||||
}
|
||||
|
10
user.go
10
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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user