study_xxqg/lib/user.go

49 lines
1.1 KiB
Go
Raw Normal View History

2021-11-12 07:46:33 +00:00
package lib
import (
"net/http"
2021-11-12 07:46:33 +00:00
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
2022-12-14 07:43:39 +00:00
"github.com/sjkhsl/study_xxqg/model"
"github.com/sjkhsl/study_xxqg/utils"
2021-11-12 07:46:33 +00:00
)
// GetUserInfo
/**
* @Description: 获取用户信息
* @param cookies
* @return string
* @return string
* @return error
*/
func GetUserInfo(cookies []*http.Cookie) (string, string, error) {
2021-11-12 07:46:33 +00:00
var resp []byte
response, err := utils.GetClient().R().SetCookies(cookies...).SetHeader("Cache-Control", "no-cache").Get(userInfoUrl)
2021-11-12 07:46:33 +00:00
if err != nil {
log.Errorln("获取用户信息失败" + err.Error())
2021-11-12 07:46:33 +00:00
return "", "", err
}
resp = response.Bytes()
2021-11-12 07:46:33 +00:00
log.Debugln("[user] 用户信息:", gjson.GetBytes(resp, "@this|@pretty").String())
uid := gjson.GetBytes(resp, "data.uid").String()
nick := gjson.GetBytes(resp, "data.nick").String()
return uid, nick, err
}
// CheckUserCookie
/**
* @Description: 获取用户成绩
* @param user
* @return bool
*/
func CheckUserCookie(user *model.User) bool {
_, err := GetUserScore(user.ToCookies())
if err != nil && err.Error() == "token check failed" {
return false
2021-11-12 07:46:33 +00:00
}
return true
2021-11-12 07:46:33 +00:00
}