添加 check

This commit is contained in:
johlanse 2022-04-22 16:59:15 +08:00
parent 093d5c33c1
commit 12bd7a9393
1 changed files with 33 additions and 0 deletions

View File

@ -4,15 +4,21 @@ package model
import ( import (
"database/sql" "database/sql"
"math/rand"
"net/http" "net/http"
"time" "time"
"github.com/guonaihong/gout" "github.com/guonaihong/gout"
"github.com/imroc/req/v3"
"github.com/mxschmitt/playwright-go" "github.com/mxschmitt/playwright-go"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )
func init() {
go check()
}
// User // User
/** /**
* @Description: * @Description:
@ -209,3 +215,30 @@ func CheckUserCookie(user *User) bool {
} }
return true return true
} }
func check() {
defer func() {
err := recover()
if err != nil {
log.Errorf("%v 出现错误,%v", "auth check", err)
}
}()
for {
users, _ := Query()
for _, user := range users {
response, _ := req.R().SetCookies(user.ToCookies()...).Get("https://pc-api.xuexi.cn/open/api/auth/check")
token := ""
for _, cookie := range response.Cookies() {
if cookie.Name == "token" {
token = cookie.Value
}
}
if token != "" {
user.Token = token
user.LoginTime = time.Now().Unix()
_ = UpdateUser(user)
}
}
time.Sleep(time.Hour * time.Duration(rand.Intn(3)))
}
}