parent
cae06c2fb2
commit
c784566d41
24
lib/core.go
24
lib/core.go
|
@ -11,6 +11,7 @@ import (
|
|||
"image/png"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
qrcodeTerminal "github.com/Baozisoftware/qrcode-terminal-go"
|
||||
|
@ -137,7 +138,13 @@ func (c *Core) Login() ([]Cookie, error) {
|
|||
}
|
||||
log.Infoln("[core] ", "正在等待二维码加载")
|
||||
|
||||
_, _ = page.WaitForSelector(`#app > div > div.login_content > div > div.login_qrcode `)
|
||||
if runtime.GOOS == "windows" {
|
||||
time.Sleep(3 * time.Second)
|
||||
} else {
|
||||
_, _ = page.WaitForSelector(`#app > div > div.login_content > div > div.login_qrcode `, playwright.PageWaitForSelectorOptions{
|
||||
State: playwright.WaitForSelectorStateVisible,
|
||||
})
|
||||
}
|
||||
|
||||
_, err = page.Evaluate(`let h = document.body.scrollWidth/2;document.documentElement.scrollTop=h;`)
|
||||
|
||||
|
@ -149,13 +156,14 @@ func (c *Core) Login() ([]Cookie, error) {
|
|||
|
||||
log.Infoln("[core] ", "加载验证码中,请耐心等待")
|
||||
|
||||
frame := page.Frame(playwright.PageFrameOptions{
|
||||
Name: playwright.String(`ddlogin-iframe`),
|
||||
URL: nil,
|
||||
})
|
||||
if frame == nil {
|
||||
log.Errorln("获取frame失败")
|
||||
}
|
||||
//frame := page.Frame(playwright.PageFrameOptions{
|
||||
// Name: playwright.String(`ddlogin-iframe`),
|
||||
// URL: nil,
|
||||
//})
|
||||
//if frame == nil {
|
||||
// log.Errorln("获取frame失败")
|
||||
//}
|
||||
|
||||
removeNode(page)
|
||||
|
||||
screen, _ := page.Screenshot()
|
||||
|
|
26
lib/user.go
26
lib/user.go
|
@ -31,6 +31,12 @@ type User struct {
|
|||
Time int64 `json:"time"`
|
||||
}
|
||||
|
||||
// GetUsers
|
||||
/**
|
||||
* @Description: 获取所有cookie有效的用户
|
||||
* @return []User
|
||||
* @return error
|
||||
*/
|
||||
func GetUsers() ([]User, error) {
|
||||
file, err := os.ReadFile(user_path)
|
||||
if err != nil {
|
||||
|
@ -52,6 +58,12 @@ func GetUsers() ([]User, error) {
|
|||
return newUsers, err
|
||||
}
|
||||
|
||||
// SaveUser
|
||||
/**
|
||||
* @Description: 保存用户信息到user.json
|
||||
* @param user
|
||||
* @return error
|
||||
*/
|
||||
func SaveUser(user User) error {
|
||||
users, err := GetUsers()
|
||||
if err != nil {
|
||||
|
@ -83,6 +95,14 @@ func SaveUser(user User) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// GetUserInfo
|
||||
/**
|
||||
* @Description: 获取用户信息
|
||||
* @param cookies
|
||||
* @return string
|
||||
* @return string
|
||||
* @return error
|
||||
*/
|
||||
func GetUserInfo(cookies []Cookie) (string, string, error) {
|
||||
var resp []byte
|
||||
err := gout.GET(user_Info_url).
|
||||
|
@ -102,6 +122,12 @@ func GetUserInfo(cookies []Cookie) (string, string, error) {
|
|||
return uid, nick, err
|
||||
}
|
||||
|
||||
// CheckUserCookie
|
||||
/**
|
||||
* @Description: 获取用户成绩
|
||||
* @param user
|
||||
* @return bool
|
||||
*/
|
||||
func CheckUserCookie(user User) bool {
|
||||
_, err := GetUserScore(user.Cookies)
|
||||
if err != nil && err.Error() == "token check failed" {
|
||||
|
|
Loading…
Reference in New Issue