Skip to content

Commit

Permalink
自动清理二维码图片
Browse files Browse the repository at this point in the history
  • Loading branch information
pppscn committed Jan 6, 2021
1 parent 9e87050 commit 806d7e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion jd_seckill/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("二维码信息校验失败")
Expand Down Expand Up @@ -135,4 +136,13 @@ func (this *User) GetUserInfo() (string,error) {
}
b,_:=common.GbkToUtf8([]byte(nickName))
return string(b), nil
}
}

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

0 comments on commit 806d7e5

Please sign in to comment.