修复登陆逻辑

This commit is contained in:
eatMoreApple 2021-04-27 17:28:17 +08:00
parent 6dacca9dba
commit 2761e43c49
4 changed files with 18 additions and 1 deletions

3
bot.go
View File

@ -3,6 +3,7 @@ package openwechat
import (
"errors"
"fmt"
"log"
)
type Bot struct {
@ -91,7 +92,6 @@ func (b *Bot) login(data []byte) error {
if err != nil {
return err
}
// 将LoginInfo存到storage里面
b.storage.LoginInfo = info
@ -158,6 +158,7 @@ func (b *Bot) stopAsyncCALL(err error) {
b.exit <- true
b.err = err
b.self = nil
log.Printf("exit with : %s", err.Error())
}
// 获取新的消息

View File

@ -80,6 +80,9 @@ func (c *Caller) GetLoginInfo(body []byte) (*LoginInfo, error) {
if err := resp.ScanXML(&loginInfo); err != nil {
return nil, err
}
if !loginInfo.Ok() {
return nil, loginInfo
}
return &loginInfo, nil
}

View File

@ -17,6 +17,14 @@ type LoginInfo struct {
PassTicket string `xml:"pass_ticket"`
}
func (l LoginInfo) Ok() bool {
return l.Ret == 0
}
func (l LoginInfo) Error() string {
return l.Message
}
// 初始的请求信息
// 几乎所有的请求都要携带该参数
type BaseRequest struct {

View File

@ -210,6 +210,11 @@ func (m *Message) IsSysNotice() bool {
return m.MsgType == 9999
}
// 判断是否为操作通知消息
func (m *Message) StatusNotify() bool {
return m.MsgType == 51
}
// 判断消息是否为文件类型的消息
func (m *Message) HasFile() bool {
return m.IsPicture() || m.IsVoice() || m.IsVideo() || m.IsMedia()