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) + } +}