From 024568d5de53db762ed61c45055b80ed508db6c8 Mon Sep 17 00:00:00 2001 From: johlanse Date: Thu, 10 Mar 2022 14:33:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8F=90=E4=BA=A4=E7=AD=94=E6=A1=88?= =?UTF-8?q?=E6=97=B6=E5=87=BA=E7=8E=B0=E6=BB=91=E5=9D=97=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E6=98=A8=E5=AE=8C=E4=B8=80=E4=B8=AA=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=90=8E=E4=BC=9A=E5=85=B3=E9=97=AD=E5=BD=93=E5=89=8D?= =?UTF-8?q?tab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/core.go | 9 +++++++++ lib/respond.go | 13 +++++++++++-- lib/study.go | 7 ++++++- lib/utils.go | 1 + main.go | 10 ++++++++++ 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/lib/core.go b/lib/core.go index 44e8015..a0d97e2 100644 --- a/lib/core.go +++ b/lib/core.go @@ -24,6 +24,7 @@ import ( "github.com/mxschmitt/playwright-go" "github.com/nfnt/resize" log "github.com/sirupsen/logrus" + goqrcode "github.com/skip2/go-qrcode" "golang.org/x/image/bmp" ) @@ -111,6 +112,14 @@ func (c *Core) L() ([]Cookie, error) { log.Infoln(g.Result) codeURL := fmt.Sprintf("https://login.xuexi.cn/login/qrcommit?showmenu=false&code=%v&appId=dingoankubyrfkttorhpou", g.Result) + err = goqrcode.WriteFile(codeURL, goqrcode.Medium, 128, "qrcode.png") + if err != nil { + log.Errorln("图片生成错误" + err.Error()) + err = nil + } else { + log.Infoln("二维码已生成到目录下的qrcode.png") + } + qrCodeString := qrcodeTerminal.New2(qrcodeTerminal.ConsoleColors.BrightBlack, qrcodeTerminal.ConsoleColors.BrightWhite, qrcodeTerminal.QRCodeRecoveryLevels.Low).Get(codeURL) qrCodeString.Print() c.Push("text", "https://johlanse.github.io/study_xxqg/scheme.html?"+url.QueryEscape(codeURL)) diff --git a/lib/respond.go b/lib/respond.go index f3c0bd6..5fbb4a0 100644 --- a/lib/respond.go +++ b/lib/respond.go @@ -48,6 +48,9 @@ func (c *Core) RespondDaily(cookies []Cookie, model string) { return } + defer func() { + page.Close() + }() page.Goto("https://pc.xuexi.cn/points/my-points.html") err = (*c.context).AddCookies(cookieToParam(cookies)...) if err != nil { @@ -160,9 +163,15 @@ func (c *Core) RespondDaily(cookies []Cookie, model string) { return } if en { + page.Mouse().Move(496, 422) + time.Sleep(1 * time.Second) + page.Mouse().Down() + + page.Mouse().Move(772, 416, playwright.MouseMoveOptions{}) + page.Mouse().Up() + time.Sleep(10 * time.Second) log.Infoln("可能存在滑块") - c.Push("text", "答题过程出现滑块") - return + c.Push("text", "答题过程出现滑块,正在尝试滑动") } } switch model { diff --git a/lib/study.go b/lib/study.go index e6e68a8..b2f64de 100644 --- a/lib/study.go +++ b/lib/study.go @@ -116,6 +116,9 @@ func (c *Core) LearnArticle(cookies []Cookie) { if err != nil { return } + defer func() { + page.Close() + }() err = (*c.context).AddCookies(cookieToParam(cookies)...) if err != nil { @@ -208,7 +211,9 @@ func (c *Core) LearnVideo(cookies []Cookie) { if err != nil { return } - + defer func() { + page.Close() + }() var resp string err = gout.GET("http://1.15.144.22/stealth.min.js").BindBody(&resp).Do() if err != nil { diff --git a/lib/utils.go b/lib/utils.go index d902ab9..b4d40da 100644 --- a/lib/utils.go +++ b/lib/utils.go @@ -21,6 +21,7 @@ func cookieToJar(cookies []Cookie) []*http.Cookie { Domain: c.Domain, Secure: c.Secure, HttpOnly: c.HTTPOnly, + SameSite: http.SameSiteDefaultMode, }, ) } diff --git a/main.go b/main.go index 2442b97..f319675 100644 --- a/main.go +++ b/main.go @@ -37,6 +37,16 @@ func init() { log.SetLevel(level) } +func init() { + pid := os.Getpid() + pi := strconv.Itoa(pid) + err := os.WriteFile("pid.pid", []byte(pi), 0666) + if err != nil { + log.Errorln("pid写入失败") + return + } +} + var ( config lib.Config )