diff --git a/bot.go b/bot.go index d1480ba..4b2de9d 100644 --- a/bot.go +++ b/bot.go @@ -307,6 +307,14 @@ func (b *Bot) UUID() string { return b.uuid } +// SetUUID +// @description: 设置UUID,可以用来手动登录用 +// @receiver b +// @param uuid +func (b *Bot) SetUUID(uuid string) { + b.uuid = uuid +} + // Context returns current context of bot func (b *Bot) Context() context.Context { return b.context diff --git a/bot_login.go b/bot_login.go index d56c29b..5cde2ff 100644 --- a/bot_login.go +++ b/bot_login.go @@ -167,9 +167,13 @@ type SacnLogin struct{} // Login 实现了 BotLogin 接口 func (s *SacnLogin) Login(bot *Bot) error { - uuid, err := bot.Caller.GetLoginUUID() - if err != nil { - return err + uuid := bot.uuid + if uuid == "" { + var err error + uuid, err = bot.Caller.GetLoginUUID() + if err != nil { + return err + } } return s.checkLogin(bot, uuid) } diff --git a/bot_test.go b/bot_test.go index b1f6db9..70d754a 100644 --- a/bot_test.go +++ b/bot_test.go @@ -128,4 +128,30 @@ func TestSender(t *testing.T) { bot.Block() } +// TestGetUUID +// @description: 获取登录二维码(UUID) +// @param t +func TestGetUUID(t *testing.T) { + bot := DefaultBot(Desktop) + uuid, err := bot.Caller.GetLoginUUID() + if err != nil { + t.Error(err) + return + } + t.Log(uuid) +} + +// TestLoginWithUUID +// @description: 使用UUID登录 +// @param t +func TestLoginWithUUID(t *testing.T) { + uuid := "oZZsO0Qv8Q==" + bot := DefaultBot(Desktop) + bot.SetUUID(uuid) + err := bot.Login() + if err != nil { + t.Errorf("登录失败: %v", err.Error()) + return + } +}