2021-11-12 07:46:33 +00:00
|
|
|
|
package lib
|
|
|
|
|
|
|
|
|
|
import (
|
2021-11-26 02:58:01 +00:00
|
|
|
|
"errors"
|
2021-11-12 07:46:33 +00:00
|
|
|
|
"fmt"
|
2022-03-17 15:11:43 +00:00
|
|
|
|
"net/http"
|
2021-11-27 08:24:24 +00:00
|
|
|
|
"time"
|
2021-11-12 07:46:33 +00:00
|
|
|
|
|
|
|
|
|
"github.com/guonaihong/gout"
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Score struct {
|
2022-02-16 07:10:38 +00:00
|
|
|
|
TotalScore int `json:"total_score"`
|
|
|
|
|
TodayScore int `json:"today_score"`
|
|
|
|
|
Content map[string]Data `json:"content"`
|
2021-11-12 07:46:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Data struct {
|
2022-02-16 07:10:38 +00:00
|
|
|
|
CurrentScore int `json:"current_score"`
|
|
|
|
|
MaxScore int `json:"max_score"`
|
2021-11-12 07:46:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-17 15:11:43 +00:00
|
|
|
|
func GetUserScore(cookies []*http.Cookie) (Score, error) {
|
2021-11-12 07:46:33 +00:00
|
|
|
|
var score Score
|
|
|
|
|
var resp []byte
|
|
|
|
|
// 获取用户总分
|
2022-03-17 15:11:43 +00:00
|
|
|
|
err := gout.GET(user_totalScore_url).SetCookies(cookies...).SetHeader(gout.H{
|
2021-11-12 07:46:33 +00:00
|
|
|
|
"Cache-Control": "no-cache",
|
|
|
|
|
}).BindBody(&resp).Do()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Errorln("获取用户总分错误" + err.Error())
|
|
|
|
|
|
|
|
|
|
return Score{}, err
|
|
|
|
|
}
|
2021-11-26 02:58:01 +00:00
|
|
|
|
data := string(resp)
|
|
|
|
|
log.Infoln(data)
|
|
|
|
|
if !gjson.GetBytes(resp, "ok").Bool() {
|
|
|
|
|
return Score{}, errors.New("token check failed")
|
|
|
|
|
}
|
2021-11-12 07:46:33 +00:00
|
|
|
|
log.Debugln(gjson.GetBytes(resp, "@this|@pretty"))
|
|
|
|
|
score.TotalScore = int(gjson.GetBytes(resp, "data.score").Int())
|
|
|
|
|
|
|
|
|
|
// 获取用户今日得分
|
2022-03-17 15:11:43 +00:00
|
|
|
|
err = gout.GET(user_todayTotalScore_url).SetCookies(cookies...).SetHeader(gout.H{
|
2021-11-12 07:46:33 +00:00
|
|
|
|
"Cache-Control": "no-cache",
|
|
|
|
|
}).BindBody(&resp).Do()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Errorln("获取用户每日总分错误" + err.Error())
|
|
|
|
|
|
|
|
|
|
return Score{}, err
|
|
|
|
|
}
|
|
|
|
|
log.Debugln(gjson.GetBytes(resp, "@this|@pretty"))
|
|
|
|
|
score.TodayScore = int(gjson.GetBytes(resp, "data.score").Int())
|
|
|
|
|
|
2022-03-17 15:11:43 +00:00
|
|
|
|
err = gout.GET(user_rateScore_url).SetCookies(cookies...).SetHeader(gout.H{
|
2021-11-12 07:46:33 +00:00
|
|
|
|
"Cache-Control": "no-cache",
|
|
|
|
|
}).BindBody(&resp).Do()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Errorln("获取用户积分出现错误" + err.Error())
|
|
|
|
|
return Score{}, err
|
|
|
|
|
}
|
|
|
|
|
log.Debugln(gjson.GetBytes(resp, "@this|@pretty"))
|
|
|
|
|
datas := gjson.GetBytes(resp, "data.taskProgress").Array()
|
|
|
|
|
m := make(map[string]Data, 7)
|
|
|
|
|
m["article"] = Data{
|
|
|
|
|
CurrentScore: int(datas[0].Get("currentScore").Int()),
|
|
|
|
|
MaxScore: int(datas[0].Get("dayMaxScore").Int()),
|
|
|
|
|
}
|
|
|
|
|
m["video"] = Data{
|
|
|
|
|
CurrentScore: int(datas[1].Get("currentScore").Int()),
|
|
|
|
|
MaxScore: int(datas[1].Get("dayMaxScore").Int()),
|
|
|
|
|
}
|
|
|
|
|
m["weekly"] = Data{
|
|
|
|
|
CurrentScore: int(datas[2].Get("currentScore").Int()),
|
|
|
|
|
MaxScore: int(datas[2].Get("dayMaxScore").Int()),
|
|
|
|
|
}
|
|
|
|
|
m["video_time"] = Data{
|
|
|
|
|
CurrentScore: int(datas[3].Get("currentScore").Int()),
|
|
|
|
|
MaxScore: int(datas[3].Get("dayMaxScore").Int()),
|
|
|
|
|
}
|
|
|
|
|
m["login"] = Data{
|
|
|
|
|
CurrentScore: int(datas[4].Get("currentScore").Int()),
|
|
|
|
|
MaxScore: int(datas[4].Get("dayMaxScore").Int()),
|
|
|
|
|
}
|
|
|
|
|
m["special"] = Data{
|
|
|
|
|
CurrentScore: int(datas[5].Get("currentScore").Int()),
|
|
|
|
|
MaxScore: int(datas[5].Get("dayMaxScore").Int()),
|
|
|
|
|
}
|
|
|
|
|
m["daily"] = Data{
|
|
|
|
|
CurrentScore: int(datas[6].Get("currentScore").Int()),
|
|
|
|
|
MaxScore: int(datas[6].Get("dayMaxScore").Int()),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
score.Content = m
|
|
|
|
|
|
|
|
|
|
return score, err
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-26 02:58:01 +00:00
|
|
|
|
func PrintScore(score Score) string {
|
|
|
|
|
result := ""
|
2021-11-27 08:34:29 +00:00
|
|
|
|
result += fmt.Sprintf("当前学习总积分:%d 今日得分:%d\n", score.TotalScore, score.TodayScore)
|
2021-11-27 08:24:24 +00:00
|
|
|
|
result += fmt.Sprintf("[%v] [INFO]: 登录:%v/%v 文章学习:%v/%v 视频学习:%v/%v 视频时长:%v/%v\n[%v] [INFO]: 每日答题:%v/%v 每周答题:%v/%v 专项答题:%v/%v",
|
|
|
|
|
time.Now().Format("2006-01-02 15:04:05"),
|
2021-11-26 02:58:01 +00:00
|
|
|
|
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,
|
2021-11-27 08:24:24 +00:00
|
|
|
|
time.Now().Format("2006-01-02 15:04:05"),
|
2021-11-26 02:58:01 +00:00
|
|
|
|
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
|
2021-11-12 07:46:33 +00:00
|
|
|
|
}
|
2021-11-27 08:24:24 +00:00
|
|
|
|
|
2022-04-20 13:31:46 +00:00
|
|
|
|
func formatScore(score Score) string {
|
2021-11-27 08:24:24 +00:00
|
|
|
|
result := ""
|
2021-11-27 08:34:29 +00:00
|
|
|
|
result += fmt.Sprintf("当前学习总积分:%d 今日得分:%d\n", score.TotalScore, score.TodayScore)
|
2021-11-27 08:24:24 +00:00
|
|
|
|
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,
|
|
|
|
|
)
|
|
|
|
|
return result
|
|
|
|
|
}
|