diff --git a/bot.go b/bot.go index 723470e..addcd53 100644 --- a/bot.go +++ b/bot.go @@ -141,10 +141,13 @@ func (b *Bot) LoginWithUUID(uuid string) error { switch resp.Code { case StatusSuccess: // 判断是否有登录回调,如果有执行它 + if err = b.HandleLogin(resp.Raw); err != nil { + return err + } if b.LoginCallBack != nil { b.LoginCallBack(resp.Raw) } - return b.HandleLogin(resp.Raw) + return nil case StatusScanned: // 执行扫码回调 if b.ScanCallBack != nil { diff --git a/caller.go b/caller.go index 8d01ed7..1714026 100644 --- a/caller.go +++ b/caller.go @@ -4,7 +4,9 @@ import ( "bytes" "encoding/json" "errors" + "fmt" "io" + "net/http" "net/url" "os" ) @@ -86,6 +88,10 @@ func (c *Caller) GetLoginInfo(body []byte) (*LoginInfo, error) { if err != nil { return nil, err } + // 判断是否重定向 + if resp.StatusCode != http.StatusMovedPermanently { + return nil, fmt.Errorf("%w: try to login with Desktop Mode", ErrForbidden) + } defer func() { _ = resp.Body.Close() }() var loginInfo LoginInfo diff --git a/errors.go b/errors.go index 19dfea8..4176404 100644 --- a/errors.go +++ b/errors.go @@ -18,3 +18,6 @@ func IgnoreNetworkError(errHandler func(err error)) func(error) { } } } + +// ErrForbidden 禁止当前账号登录 +var ErrForbidden = errors.New("login forbidden")