|
@ -73,9 +73,24 @@ func (this *Seckill) getSeckillUrl() (string,error) { |
|
|
req.SetHeader("User-Agent", this.getUserAgent()) |
|
|
req.SetHeader("User-Agent", this.getUserAgent()) |
|
|
req.SetHeader("Host", "itemko.jd.com") |
|
|
req.SetHeader("Host", "itemko.jd.com") |
|
|
req.SetHeader("Referer", fmt.Sprintf("https://item.jd.com/%s.html", skuId)) |
|
|
req.SetHeader("Referer", fmt.Sprintf("https://item.jd.com/%s.html", skuId)) |
|
|
|
|
|
req.SetUrl("https://itemko.jd.com/itemShowBtn?callback=jQuery" + strconv.Itoa(common.Rand(1000000, 9999999)) + "&skuId=" + skuId + "&from=pc&_=" + strconv.Itoa(int(time.Now().Unix()*1000))).SetMethod("get") |
|
|
url := "" |
|
|
url := "" |
|
|
for { |
|
|
for { |
|
|
_,body,_:=req.SetUrl("https://itemko.jd.com/itemShowBtn?callback=jQuery{}"+strconv.Itoa(common.Rand(1000000,9999999))+"&skuId="+skuId+"&from=pc&_="+strconv.Itoa(int(time.Now().Unix()*1000))).SetMethod("get").Send().End() |
|
|
_, body, _ := req.Send().End() |
|
|
|
|
|
//临时打印数据
|
|
|
|
|
|
log.Println("返回信息:"+body) |
|
|
|
|
|
//先注释,测试过gjson可以解析jQuery1153906({"type":"3","state":"13","url":""})格式
|
|
|
|
|
|
/* var cbBody string |
|
|
|
|
|
cbBody = body |
|
|
|
|
|
spBody := strings.Split(body, "(") |
|
|
|
|
|
if len(spBody) >= 2 { |
|
|
|
|
|
cbBody = strings.Trim(spBody[1], ")") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if gjson.Get(cbBody, "url").Exists() && gjson.Get(cbBody, "url").String() != "" { |
|
|
|
|
|
url = gjson.Get(cbBody, "url").String() |
|
|
|
|
|
break |
|
|
|
|
|
}*/ |
|
|
if gjson.Get(body, "url").Exists() && gjson.Get(body, "url").String() != "" { |
|
|
if gjson.Get(body, "url").Exists() && gjson.Get(body, "url").String() != "" { |
|
|
url = gjson.Get(body, "url").String() |
|
|
url = gjson.Get(body, "url").String() |
|
|
break |
|
|
break |
|
@ -83,6 +98,7 @@ func (this *Seckill) getSeckillUrl() (string,error) { |
|
|
log.Println("抢购链接获取失败,稍后自动重试") |
|
|
log.Println("抢购链接获取失败,稍后自动重试") |
|
|
time.Sleep(300 * time.Millisecond) |
|
|
time.Sleep(300 * time.Millisecond) |
|
|
} |
|
|
} |
|
|
|
|
|
url = "https:"+url |
|
|
//https://divide.jd.com/user_routing?skuId=8654289&sn=c3f4ececd8461f0e4d7267e96a91e0e0&from=pc
|
|
|
//https://divide.jd.com/user_routing?skuId=8654289&sn=c3f4ececd8461f0e4d7267e96a91e0e0&from=pc
|
|
|
url = strings.ReplaceAll(url, "divide", "marathon") |
|
|
url = strings.ReplaceAll(url, "divide", "marathon") |
|
|
//https://marathon.jd.com/captcha.html?skuId=8654289&sn=c3f4ececd8461f0e4d7267e96a91e0e0&from=pc
|
|
|
//https://marathon.jd.com/captcha.html?skuId=8654289&sn=c3f4ececd8461f0e4d7267e96a91e0e0&from=pc
|
|
@ -103,7 +119,13 @@ func (this *Seckill) RequestSeckillUrl() { |
|
|
} |
|
|
} |
|
|
url, _ := this.getSeckillUrl() |
|
|
url, _ := this.getSeckillUrl() |
|
|
skuId := this.conf.MustValue("config", "sku_id", "") |
|
|
skuId := this.conf.MustValue("config", "sku_id", "") |
|
|
req:=httpc.NewRequest(this.client) |
|
|
log.Println("访问商品的抢购连接...") |
|
|
|
|
|
client:=httpc.NewHttpClient() |
|
|
|
|
|
client.SetCookieJar(common.CookieJar) |
|
|
|
|
|
client.SetRedirect(func(req *http.Request, via []*http.Request) error { |
|
|
|
|
|
return http.ErrUseLastResponse |
|
|
|
|
|
}) |
|
|
|
|
|
req := httpc.NewRequest(client) |
|
|
req.SetHeader("User-Agent", this.getUserAgent()) |
|
|
req.SetHeader("User-Agent", this.getUserAgent()) |
|
|
req.SetHeader("Host", "marathon.jd.com") |
|
|
req.SetHeader("Host", "marathon.jd.com") |
|
|
req.SetHeader("Referer", fmt.Sprintf("https://item.jd.com/%s.html", skuId)) |
|
|
req.SetHeader("Referer", fmt.Sprintf("https://item.jd.com/%s.html", skuId)) |
|
@ -113,8 +135,13 @@ func (this *Seckill) RequestSeckillUrl() { |
|
|
func (this *Seckill) SeckillPage() { |
|
|
func (this *Seckill) SeckillPage() { |
|
|
log.Println("访问抢购订单结算页面...") |
|
|
log.Println("访问抢购订单结算页面...") |
|
|
skuId := this.conf.MustValue("config", "sku_id", "") |
|
|
skuId := this.conf.MustValue("config", "sku_id", "") |
|
|
seckillNum:=this.conf.MustValue("config","seckill_num","") |
|
|
seckillNum := this.conf.MustValue("config", "seckill_num", "2") |
|
|
req:=httpc.NewRequest(this.client) |
|
|
client:=httpc.NewHttpClient() |
|
|
|
|
|
client.SetCookieJar(common.CookieJar) |
|
|
|
|
|
client.SetRedirect(func(req *http.Request, via []*http.Request) error { |
|
|
|
|
|
return http.ErrUseLastResponse |
|
|
|
|
|
}) |
|
|
|
|
|
req := httpc.NewRequest(client) |
|
|
req.SetHeader("User-Agent", this.getUserAgent()) |
|
|
req.SetHeader("User-Agent", this.getUserAgent()) |
|
|
req.SetHeader("Host", "marathon.jd.com") |
|
|
req.SetHeader("Host", "marathon.jd.com") |
|
|
req.SetHeader("Referer", fmt.Sprintf("https://item.jd.com/%s.html", skuId)) |
|
|
req.SetHeader("Referer", fmt.Sprintf("https://item.jd.com/%s.html", skuId)) |
|
@ -124,7 +151,7 @@ func (this *Seckill) SeckillPage() { |
|
|
func (this *Seckill) SeckillInitInfo() (string, error) { |
|
|
func (this *Seckill) SeckillInitInfo() (string, error) { |
|
|
log.Println("获取秒杀初始化信息...") |
|
|
log.Println("获取秒杀初始化信息...") |
|
|
skuId := this.conf.MustValue("config", "sku_id", "") |
|
|
skuId := this.conf.MustValue("config", "sku_id", "") |
|
|
seckillNum:=this.conf.MustValue("config","seckill_num","") |
|
|
seckillNum := this.conf.MustValue("config", "seckill_num", "2") |
|
|
req := httpc.NewRequest(this.client) |
|
|
req := httpc.NewRequest(this.client) |
|
|
req.SetHeader("User-Agent", this.getUserAgent()) |
|
|
req.SetHeader("User-Agent", this.getUserAgent()) |
|
|
req.SetHeader("Host", "marathon.jd.com") |
|
|
req.SetHeader("Host", "marathon.jd.com") |
|
@ -147,7 +174,7 @@ func (this *Seckill) SubmitSeckillOrder() bool { |
|
|
eid := this.conf.MustValue("config", "eid", "") |
|
|
eid := this.conf.MustValue("config", "eid", "") |
|
|
fp := this.conf.MustValue("config", "fp", "") |
|
|
fp := this.conf.MustValue("config", "fp", "") |
|
|
skuId := this.conf.MustValue("config", "sku_id", "") |
|
|
skuId := this.conf.MustValue("config", "sku_id", "") |
|
|
seckillNum:=this.conf.MustValue("config","seckill_num","") |
|
|
seckillNum := this.conf.MustValue("config", "seckill_num", "2") |
|
|
paymentPwd := this.conf.MustValue("account", "payment_pwd", "") |
|
|
paymentPwd := this.conf.MustValue("account", "payment_pwd", "") |
|
|
initInfo, err := this.SeckillInitInfo() |
|
|
initInfo, err := this.SeckillInitInfo() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|