diff --git a/client.go b/client.go index e62132b..a5ae9df 100644 --- a/client.go +++ b/client.go @@ -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()) +} diff --git a/global.go b/global.go index 5140599..1381183 100644 --- a/global.go +++ b/global.go @@ -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" ) diff --git a/message.go b/message.go index b25fed8..ee8bba1 100644 --- a/message.go +++ b/message.go @@ -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,18 +206,17 @@ func (m *Message) init(bot *Bot) { m.Content = strings.Join(data[1:], "") m.senderInGroupUserName = data[0] receiver, err := m.Receiver() - if err != nil { - return - } - displayName := receiver.DisplayName - if displayName == "" { - displayName = receiver.NickName - } - atFlag := "@" + displayName - index := len(atFlag) + 1 + 1 - if strings.HasPrefix(m.Content, atFlag) && unicode.IsSpace(rune(m.Content[index])) { - m.IsAt = true - m.Content = m.Content[index+1:] + if err == nil { + displayName := receiver.DisplayName + if displayName == "" { + displayName = receiver.NickName + } + atFlag := "@" + displayName + index := len(atFlag) + 1 + 1 + if strings.HasPrefix(m.Content, atFlag) && unicode.IsSpace(rune(m.Content[index])) { + m.IsAt = true + m.Content = m.Content[index+1:] + } } } }