From 6979a83dd88f8af8e66bbdd42db46ba9b2ca4841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Tue, 15 Oct 2024 01:31:26 +0900 Subject: [PATCH] feat(emozi): add api IsValid --- emozi/login.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/emozi/login.go b/emozi/login.go index 5a51e1d..93e570c 100644 --- a/emozi/login.go +++ b/emozi/login.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "encoding/json" "errors" + "net/http" "net/url" "github.com/FloatTech/floatbox/binary" @@ -65,3 +66,15 @@ func (usr *User) Login() error { usr.auth = r.Get("result.token").Str return nil } + +// IsValid 检查是否有效 +func (usr *User) IsValid() bool { + if usr.name == "" || usr.pswd == "" || usr.auth == "" { + return false + } + _, err := web.RequestDataWithHeaders(http.DefaultClient, api+"", "GET", func(r *http.Request) error { + r.Header.Set("Authorization", usr.auth) + return nil + }, nil) + return err == nil +}