add message Image get support

This commit is contained in:
ivy1996-encode 2021-03-14 10:29:43 +08:00
parent bf6ce1aff0
commit 526431f400
3 changed files with 34 additions and 12 deletions

View File

@ -349,3 +349,13 @@ func (c *Client) WebWxVerifyUser(storage WechatStorage, info RecommendInfo, veri
req.Header.Add("Content-Type", jsonContentType)
return c.Do(req)
}
func (c *Client) WebWxGetMsgImg(msg *Message, info LoginInfo) (*http.Response, error) {
path, _ := url.Parse(webWxGetMsgImgUrl)
params := url.Values{}
params.Add("MsgID", msg.MsgId)
params.Add("skey", info.SKey)
params.Add("type", "slave")
path.RawQuery = params.Encode()
return c.Get(path.String())
}

View File

@ -29,6 +29,7 @@ const (
webWxVerifyUserUrl = "https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxverifyuser"
syncCheckUrl = "https://webpush.wx2.qq.com/cgi-bin/mmwebwx-bin/synccheck"
webWxUpLoadMediaUrl = "https://file.wx2.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia"
webWxGetMsgImgUrl = "https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxgetmsgimg"
jsonContentType = "application/json; charset=utf-8"
)

View File

@ -3,6 +3,7 @@ package openwechat
import (
"context"
"errors"
"net/http"
"os"
"strings"
"sync"
@ -170,6 +171,17 @@ func (m *Message) IsSystem() bool {
return m.MsgType == 10000
}
func (m *Message) IsNotify() bool {
return m.MsgType == 51 && m.StatusNotifyCode != 0
}
func (m *Message) GetMsgImageResponse() (*http.Response, error) {
if !m.IsPicture() {
return nil, errors.New("Picture type message required")
}
return m.Bot.Caller.Client.WebWxGetMsgImg(m, m.Bot.storage.GetLoginInfo())
}
// 用在多个messageHandler之间传递信息
func (m *Message) Set(key string, value interface{}) {
m.mu.Lock()
@ -194,9 +206,7 @@ func (m *Message) init(bot *Bot) {
m.Content = strings.Join(data[1:], "")
m.senderInGroupUserName = data[0]
receiver, err := m.Receiver()
if err != nil {
return
}
if err == nil {
displayName := receiver.DisplayName
if displayName == "" {
displayName = receiver.NickName
@ -209,6 +219,7 @@ func (m *Message) init(bot *Bot) {
}
}
}
}
//func (m *Message) Agree() error {
// if !m.IsFriendAdd() {