|
|
@ -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("获取秒杀初始化信息失败,返回信息: 网页") |
|
|
|
} |
|
|
|
errorCount=errorCount-1 |
|
|
|
time.Sleep(300*time.Millisecond) |
|
|
|
errorMsg = body |
|
|
|
} |
|
|
|
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 |
|
|
|
} |
|
|
|