From 806d7e5bbb0773dd4ce96e8aea1a2524f40c83e4 Mon Sep 17 00:00:00 2001 From: pppscn <35696959@qq.com> Date: Wed, 6 Jan 2021 12:12:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=B8=85=E7=90=86=E4=BA=8C?= =?UTF-8?q?=E7=BB=B4=E7=A0=81=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/login.go | 1 + jd_seckill/user.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/login.go b/cmd/login.go index 8b5458d..3d1d95e 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -30,6 +30,7 @@ func startLogin(cmd *cobra.Command, args []string) { return } user:=jd_seckill.NewUser(common.Client,common.Config) + user.DelQrCode() log.Println("登录成功") userInfo,_:=user.GetUserInfo() log.Println("用户:"+userInfo) diff --git a/jd_seckill/user.go b/jd_seckill/user.go index 2e9f19e..ad65a88 100644 --- a/jd_seckill/user.go +++ b/jd_seckill/user.go @@ -85,6 +85,7 @@ func (this *User) TicketInfo(ticket string) (string,error) { req.SetHeader("User-Agent",this.getUserAgent()) req.SetHeader("Referer","https://passport.jd.com/uc/login?ltype=logout") resp,body,err:=req.SetUrl("https://passport.jd.com/uc/qrCodeTicketValidation?t="+ticket).SetMethod("get").Send().End() + defer this.DelQrCode() if err!=nil || resp.StatusCode!=http.StatusOK { log.Println("二维码信息校验失败") return "",errors.New("二维码信息校验失败") @@ -135,4 +136,13 @@ func (this *User) GetUserInfo() (string,error) { } b,_:=common.GbkToUtf8([]byte(nickName)) return string(b), nil -} \ No newline at end of file +} + +func (this *User) DelQrCode() { + dir, _ := os.Getwd() + qrPath := filepath.Join(dir, `./qr_code.png`) + log.Println(qrPath) + if _, err := os.Stat(qrPath); !os.IsNotExist(err) { + os.Remove(qrPath) + } +}