燕鹏 преди 4 години
родител
ревизия
182db53ae8
  1. 2
      conf.ini
  2. 31
      jd_seckill/seckill.go

2
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个

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

Зареждане…
Отказ
Запис