From ac07a680d87fbdf78604447aed992f9a14476f19 Mon Sep 17 00:00:00 2001 From: johlanse Date: Fri, 26 Nov 2021 10:58:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E6=A3=80=E6=B5=8B=E8=BF=87=E6=9C=9Fcookie=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/score.go | 25 ++++++++++++++++++++----- lib/user.go | 11 +++++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/lib/score.go b/lib/score.go index c76e2bf..60b5dfb 100644 --- a/lib/score.go +++ b/lib/score.go @@ -1,6 +1,7 @@ package lib import ( + "errors" "fmt" "github.com/guonaihong/gout" @@ -31,6 +32,11 @@ func GetUserScore(cookies []Cookie) (Score, error) { return Score{}, err } + data := string(resp) + log.Infoln(data) + if !gjson.GetBytes(resp, "ok").Bool() { + return Score{}, errors.New("token check failed") + } log.Debugln(gjson.GetBytes(resp, "@this|@pretty")) score.TotalScore = int(gjson.GetBytes(resp, "data.score").Int()) @@ -90,9 +96,18 @@ func GetUserScore(cookies []Cookie) (Score, error) { return score, err } -func PrintScore(score Score) { - log.Infoln(fmt.Sprintf("当前学习总积分:%d 今日得分:%d", score.TodayScore, score.TodayScore)) - for s, data := range score.Content { - log.Infoln(s, ": ", data.CurrentScore, "/", data.MaxScore) - } +func PrintScore(score Score) string { + result := "" + result += fmt.Sprintf("当前学习总积分:%d 今日得分:%d\n", score.TodayScore, score.TodayScore) + result += fmt.Sprintf("登录:%v/%v 文章学习:%v/%v 视频学习:%v/%v 视频时长:%v/%v\n每日答题:%v/%v 每周答题:%v/%v 专项答题:%v/%v", + score.Content["login"].CurrentScore, score.Content["login"].MaxScore, + score.Content["article"].CurrentScore, score.Content["article"].MaxScore, + score.Content["video"].CurrentScore, score.Content["video"].MaxScore, + score.Content["video_time"].CurrentScore, score.Content["video_time"].MaxScore, + score.Content["daily"].CurrentScore, score.Content["daily"].MaxScore, + score.Content["weekly"].CurrentScore, score.Content["weekly"].MaxScore, + score.Content["special"].CurrentScore, score.Content["special"].MaxScore, + ) + log.Infoln(result) + return result } diff --git a/lib/user.go b/lib/user.go index 1fffb9e..fc49aae 100644 --- a/lib/user.go +++ b/lib/user.go @@ -3,7 +3,6 @@ package lib import ( "encoding/json" "os" - "time" "github.com/guonaihong/gout" log "github.com/sirupsen/logrus" @@ -50,7 +49,7 @@ func GetUsers() ([]User, error) { } log.Infoln("用户" + users[i].Nick + "cookie已失效") } - return users, err + return newUsers, err } func SaveUser(user User) error { @@ -104,9 +103,9 @@ func GetUserInfo(cookies []Cookie) (string, string, error) { } func CheckUserCookie(user User) bool { - if time.Now().Unix() <= user.Time { - return true + _, err := GetUserScore(user.Cookies) + if err != nil && err.Error() == "token check failed" { + return false } - - return false + return true }