From 182db53ae83c796bb76056867c6e4affa2fb9cec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=87=95=E9=B9=8F?= Date: Mon, 25 Jan 2021 13:31:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=93=E5=8D=B0=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf.ini | 2 +- jd_seckill/seckill.go | 31 ++++++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/conf.ini b/conf.ini index d67e581..6a798d7 100644 --- a/conf.ini +++ b/conf.ini @@ -10,7 +10,7 @@ sku_id = 100012043978 # 抢购数量 seckill_num = 2 # 抢购开始时间设定 2021-01-01 09:59:59 (PS.预约成功后会自动更新) -buy_time = 2021-01-08 09:59:56 +buy_time = 2021-01-26 09:59:59 # 抢购总时间,单位:分钟,默认两分钟 seckill_time = # 抢购任务数量,默认5个 diff --git a/jd_seckill/seckill.go b/jd_seckill/seckill.go index 414a63b..c1f3083 100644 --- a/jd_seckill/seckill.go +++ b/jd_seckill/seckill.go @@ -185,6 +185,7 @@ func (this *Seckill) MakeReserve() { } } +// 获取抢购链接 func (this *Seckill) getSeckillUrl() (string, error) { skuId := this.conf.MustValue("config", "sku_id", "") req := httpc.NewRequest(this.client) @@ -202,7 +203,7 @@ func (this *Seckill) getSeckillUrl() (string, error) { log.Println("抢购链接获取失败,稍后自动重试") time.Sleep(300 * time.Millisecond) } - url = "https:"+url + url = "https:" + url //https://divide.jd.com/user_routing?skuId=8654289&sn=c3f4ececd8461f0e4d7267e96a91e0e0&from=pc url = strings.ReplaceAll(url, "divide", "marathon") //https://marathon.jd.com/captcha.html?skuId=8654289&sn=c3f4ececd8461f0e4d7267e96a91e0e0&from=pc @@ -224,7 +225,7 @@ func (this *Seckill) RequestSeckillUrl() { url, _ := this.getSeckillUrl() skuId := this.conf.MustValue("config", "sku_id", "") log.Println("访问商品的抢购连接...") - client:=httpc.NewHttpClient() + client := httpc.NewHttpClient() client.SetCookieJar(common.CookieJar) client.SetRedirect(func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse @@ -240,7 +241,7 @@ func (this *Seckill) SeckillPage() { log.Println("访问抢购订单结算页面...") skuId := this.conf.MustValue("config", "sku_id", "") seckillNum := this.conf.MustValue("config", "seckill_num", "2") - client:=httpc.NewHttpClient() + client := httpc.NewHttpClient() client.SetCookieJar(common.CookieJar) client.SetRedirect(func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse @@ -264,19 +265,23 @@ func (this *Seckill) SeckillInitInfo() (string, error) { req.SetData("isModifyAddress", "false") req.SetUrl("https://marathon.jd.com/seckillnew/orderService/pc/init.action").SetMethod("post") //尝试获取三次 - errorCount:=3 - errorMsg:="" + errorCount := 3 + errorMsg := "" for errorCount > 0 { _, body, _ := req.Send().End() - if body!="null" && gjson.Valid(body) { + if body != "null" && gjson.Valid(body) { log.Println("获取秒杀初始化信息成功") - return body,nil - }else{ - log.Println("获取秒杀初始化信息失败,返回信息:"+body) - errorMsg=body + return body, nil + } else { + if len(body) < 200 { + log.Println("获取秒杀初始化信息失败,返回信息:" + body) + } else { + log.Println("获取秒杀初始化信息失败,返回信息: 网页") + } + errorMsg = body } - errorCount=errorCount-1 - time.Sleep(300*time.Millisecond) + errorCount = errorCount - 1 + time.Sleep(300 * time.Millisecond) } return "", errors.New(errorMsg) } @@ -293,7 +298,7 @@ func (this *Seckill) SubmitSeckillOrder() bool { return false } address := gjson.Get(initInfo, "addressList").Array() - if !gjson.Get(initInfo, "addressList").Exists() || len(address)<1 { + if !gjson.Get(initInfo, "addressList").Exists() || len(address) < 1 { log.Println("抢购失败,可能你还未设置默认收货地址") return false }