Browse Source

修改打印日志

main
燕鹏 4 years ago
parent
commit
182db53ae8
  1. 2
      conf.ini
  2. 31
      jd_seckill/seckill.go

2
conf.ini

@ -10,7 +10,7 @@ sku_id = 100012043978
# 抢购数量 # 抢购数量
seckill_num = 2 seckill_num = 2
# 抢购开始时间设定 2021-01-01 09:59:59 (PS.预约成功后会自动更新) # 抢购开始时间设定 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 = seckill_time =
# 抢购任务数量,默认5个 # 抢购任务数量,默认5个

31
jd_seckill/seckill.go

@ -185,6 +185,7 @@ func (this *Seckill) MakeReserve() {
} }
} }
// 获取抢购链接
func (this *Seckill) getSeckillUrl() (string, error) { func (this *Seckill) getSeckillUrl() (string, error) {
skuId := this.conf.MustValue("config", "sku_id", "") skuId := this.conf.MustValue("config", "sku_id", "")
req := httpc.NewRequest(this.client) req := httpc.NewRequest(this.client)
@ -202,7 +203,7 @@ func (this *Seckill) getSeckillUrl() (string, error) {
log.Println("抢购链接获取失败,稍后自动重试") log.Println("抢购链接获取失败,稍后自动重试")
time.Sleep(300 * time.Millisecond) time.Sleep(300 * time.Millisecond)
} }
url = "https:"+url 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
@ -224,7 +225,7 @@ func (this *Seckill) RequestSeckillUrl() {
url, _ := this.getSeckillUrl() url, _ := this.getSeckillUrl()
skuId := this.conf.MustValue("config", "sku_id", "") skuId := this.conf.MustValue("config", "sku_id", "")
log.Println("访问商品的抢购连接...") log.Println("访问商品的抢购连接...")
client:=httpc.NewHttpClient() client := httpc.NewHttpClient()
client.SetCookieJar(common.CookieJar) client.SetCookieJar(common.CookieJar)
client.SetRedirect(func(req *http.Request, via []*http.Request) error { client.SetRedirect(func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse return http.ErrUseLastResponse
@ -240,7 +241,7 @@ 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", "2") seckillNum := this.conf.MustValue("config", "seckill_num", "2")
client:=httpc.NewHttpClient() client := httpc.NewHttpClient()
client.SetCookieJar(common.CookieJar) client.SetCookieJar(common.CookieJar)
client.SetRedirect(func(req *http.Request, via []*http.Request) error { client.SetRedirect(func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse return http.ErrUseLastResponse
@ -264,19 +265,23 @@ func (this *Seckill) SeckillInitInfo() (string, error) {
req.SetData("isModifyAddress", "false") req.SetData("isModifyAddress", "false")
req.SetUrl("https://marathon.jd.com/seckillnew/orderService/pc/init.action").SetMethod("post") req.SetUrl("https://marathon.jd.com/seckillnew/orderService/pc/init.action").SetMethod("post")
//尝试获取三次 //尝试获取三次
errorCount:=3 errorCount := 3
errorMsg:="" errorMsg := ""
for errorCount > 0 { for errorCount > 0 {
_, body, _ := req.Send().End() _, body, _ := req.Send().End()
if body!="null" && gjson.Valid(body) { if body != "null" && gjson.Valid(body) {
log.Println("获取秒杀初始化信息成功") log.Println("获取秒杀初始化信息成功")
return body,nil return body, nil
}else{ } else {
log.Println("获取秒杀初始化信息失败,返回信息:"+body) if len(body) < 200 {
errorMsg=body log.Println("获取秒杀初始化信息失败,返回信息:" + body)
} else {
log.Println("获取秒杀初始化信息失败,返回信息: 网页")
}
errorMsg = body
} }
errorCount=errorCount-1 errorCount = errorCount - 1
time.Sleep(300*time.Millisecond) time.Sleep(300 * time.Millisecond)
} }
return "", errors.New(errorMsg) return "", errors.New(errorMsg)
} }
@ -293,7 +298,7 @@ func (this *Seckill) SubmitSeckillOrder() bool {
return false return false
} }
address := gjson.Get(initInfo, "addressList").Array() 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("抢购失败,可能你还未设置默认收货地址") log.Println("抢购失败,可能你还未设置默认收货地址")
return false return false
} }

Loading…
Cancel
Save