Browse Source

Merge branch 'main' of https://github.com/ztino/jd_seckill into main

main
燕鹏 4 years ago
parent
commit
6287936972
  1. 1
      .gitignore
  2. 14
      README.md
  3. 2
      cmd/jdTdudfp.go
  4. 3
      cmd/login.go
  5. 2
      cmd/logout.go
  6. 2
      cmd/reserve.go
  7. 2
      cmd/seckill.go
  8. 2
      common/var.go
  9. 2
      go.mod
  10. 5
      jd_seckill/seckill.go
  11. 2
      jd_seckill/session.go
  12. 13
      jd_seckill/user.go
  13. 66
      log/log.go
  14. 18
      main.go
  15. 2
      service/dingtalk.go
  16. 2
      service/email.go
  17. 9
      service/wechat.go

1
.gitignore

@ -21,3 +21,4 @@
/cookie.txt
*.bak
go.sum
/同步代码.sh

14
README.md

@ -1,8 +1,5 @@
Jd_Seckill
helloworld
=======
#### 还未收到安全通知,但是估计也快了,给大家建个Telegram群吧,茶余饭后,聊天扯淡,有条件的可以加入:https://t.me/joinchat/GsDnhtkdKJ4nbwJh
> ⚠ 此项目是[python jd_seckill](https://github.com/huanghyw/jd_seckill) 的go版本实现,旨在降低使用门栏和相互学习而创建。
**go版本的jd_seckill,京东抢茅台神器,支持跨平台,使用者请在发布页下载可执行文件,欢迎pr。**
@ -11,7 +8,7 @@ Jd_Seckill
>目前编译好的可执行文件有Windows,MacOS,Linux,arm,mips平台。
## 安装
## 安装(开发者)
方式一(推荐):
@ -45,6 +42,8 @@ jd_seckill login
> ⚠依赖谷歌浏览器,请安装谷歌浏览器,windows下请将安装目录加入系统变量Path
> ⚠ 京东可能在修改eid和fp的获取方式了,目前该功能获取不太稳定,请勿依赖该功能,目前观望中,不做更改
执行以下命令按照提示操作:
```shell
#参数--good_url商品链接必须设置,链接地址是一个可以加入购物车的商品
@ -82,6 +81,9 @@ jd_seckill version
#### 1. 推荐Chrome浏览器
#### 2. 网页扫码登录,或者账号密码登录
#### 3. 填写config.ini配置信息
> ⚠ 按照下方获取不到的,可以点击进入付款界面(输入支付密码页面),尝试下方步骤进行获取
(1)`eid`和`fp`找个普通商品随便下单,然后抓包就能看到,这两个值可以填固定的
> 随便找一个商品下单,然后进入结算页面,打开浏览器的调试窗口,切换到控制台Tab页,在控制台中输入变量`_JdTdudfp`,即可从输出的Json中获取`eid`和`fp`。
> 不会的话参考issue https://github.com/ztino/jd_seckill/issues/2
@ -99,6 +101,8 @@ jd_seckill version
> 在程序开始运行后,会检测本地时间与京东服务器时间,输出的差值为本地时间-京东服务器时间,即-50为本地时间比京东服务器时间慢50ms。
> 本代码的执行的抢购时间以本地电脑/服务器时间为准
> ⚠ 京东每月限购两瓶,如果本月已抢到两瓶,一个月后再抢吧,有的抢到1瓶的,使用脚本记得需要修改参数
(4)修改抢购瓶数
> 可在配置文件中找到seckill_num进行修改,默认值2瓶

2
cmd/jdTdudfp.go

@ -10,7 +10,7 @@ import (
"github.com/unknwon/goconfig"
"github.com/ztino/jd_seckill/common"
"github.com/ztino/jd_seckill/jd_seckill"
"log"
"github.com/ztino/jd_seckill/log"
"net/url"
"os"
"time"

3
cmd/login.go

@ -4,7 +4,7 @@ import (
"github.com/spf13/cobra"
"github.com/ztino/jd_seckill/common"
"github.com/ztino/jd_seckill/jd_seckill"
"log"
"github.com/ztino/jd_seckill/log"
"os"
"time"
)
@ -30,6 +30,7 @@ func startLogin(cmd *cobra.Command, args []string) {
return
}
user:=jd_seckill.NewUser(common.Client,common.Config)
user.DelQrCode()
log.Println("登录成功")
userInfo,_:=user.GetUserInfo()
log.Println("用户:"+userInfo)

2
cmd/logout.go

@ -3,7 +3,7 @@ package cmd
import (
"github.com/spf13/cobra"
"github.com/ztino/jd_seckill/common"
"log"
"github.com/ztino/jd_seckill/log"
"os"
)

2
cmd/reserve.go

@ -4,7 +4,7 @@ import (
"github.com/spf13/cobra"
"github.com/ztino/jd_seckill/common"
"github.com/ztino/jd_seckill/jd_seckill"
"log"
"github.com/ztino/jd_seckill/log"
)
func init() {

2
cmd/seckill.go

@ -8,7 +8,7 @@ import (
"github.com/tidwall/gjson"
"github.com/ztino/jd_seckill/common"
"github.com/ztino/jd_seckill/jd_seckill"
"log"
"github.com/ztino/jd_seckill/log"
"net/http"
"os"
"strconv"

2
common/var.go

@ -7,7 +7,7 @@ import (
const (
SoftName = "jd_seckill"
Version = "0.2.0"
Version = "0.2.1"
DateTimeFormatStr = "2006-01-02 15:04:05"
DateFormatStr = "2006-01-02"
)

2
go.mod

@ -9,6 +9,7 @@ require (
github.com/chromedp/cdproto v0.0.0-20201204063249-be40c824ad18
github.com/chromedp/chromedp v0.5.4
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gookit/color v1.3.6
github.com/json-iterator/go v1.1.10 // indirect
github.com/makiuchi-d/gozxing v0.0.0-20200903113411-25f730ed83da
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
@ -18,6 +19,7 @@ require (
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
golang.org/x/sys v0.0.0-20201231184435-2d18734c6014 // indirect
golang.org/x/text v0.3.4
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
)

5
jd_seckill/seckill.go

@ -8,8 +8,8 @@ import (
"github.com/tidwall/gjson"
"github.com/unknwon/goconfig"
"github.com/ztino/jd_seckill/common"
"github.com/ztino/jd_seckill/log"
"github.com/ztino/jd_seckill/service"
"log"
"net/http"
"strconv"
"strings"
@ -241,9 +241,6 @@ func (this *Seckill) SubmitSeckillOrder() bool {
return false
}
//临时打印数据
log.Println("返回信息:"+body)
if !gjson.Valid(body) {
log.Println("抢购失败,返回信息:" + body)
_ = service.SendMessage(this.conf, "茅台抢购通知", "抢购失败,返回信息:"+body)

2
jd_seckill/session.go

@ -5,8 +5,8 @@ import (
"errors"
"github.com/Albert-Zhan/httpc"
"github.com/ztino/jd_seckill/common"
"github.com/ztino/jd_seckill/log"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"

13
jd_seckill/user.go

@ -7,7 +7,7 @@ import (
"github.com/tidwall/gjson"
"github.com/unknwon/goconfig"
"github.com/ztino/jd_seckill/common"
"log"
"github.com/ztino/jd_seckill/log"
"net/http"
"os"
"path/filepath"
@ -85,6 +85,7 @@ func (this *User) TicketInfo(ticket string) (string,error) {
req.SetHeader("User-Agent",this.getUserAgent())
req.SetHeader("Referer","https://passport.jd.com/uc/login?ltype=logout")
resp,body,err:=req.SetUrl("https://passport.jd.com/uc/qrCodeTicketValidation?t="+ticket).SetMethod("get").Send().End()
defer this.DelQrCode()
if err!=nil || resp.StatusCode!=http.StatusOK {
log.Println("二维码信息校验失败")
return "",errors.New("二维码信息校验失败")
@ -135,4 +136,12 @@ func (this *User) GetUserInfo() (string,error) {
}
b,_:=common.GbkToUtf8([]byte(nickName))
return string(b), nil
}
}
func (this *User) DelQrCode() {
dir, _ := os.Getwd()
qrPath := filepath.Join(dir, `./qr_code.png`)
if common.Exists(qrPath) {
_=os.Remove(qrPath)
}
}

66
log/log.go

@ -0,0 +1,66 @@
package log
import (
"github.com/gookit/color"
"io"
"log"
"os"
"time"
)
//重写log标准库,需要多少个方法就加多少个
var file = "./logs/jd_seckill_" + time.Now().Format("20060102") + ".log"
//将日志同时输出到控制台和文件
func Println(v ...interface{}) {
logFile, logErr := os.OpenFile(file, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
if logErr != nil {
panic(logErr)
}
defer logFile.Close()
mw := io.MultiWriter(os.Stdout, logFile)
log.SetOutput(mw)
//log.SetPrefix("[jd_seckill]")
log.SetFlags(log.LstdFlags | log.Lshortfile | log.Lmicroseconds)
log.Println(v...)
}
//将日志同时输出到控制台和文件
func ColorPrintln(color2 color.Color, v ...interface{}) {
logFile, logErr := os.OpenFile(file, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
if logErr != nil {
panic(logErr)
}
defer logFile.Close()
log.SetOutput(logFile)
//log.SetPrefix("[jd_seckill]")
log.SetFlags(log.LstdFlags | log.Lshortfile | log.Lmicroseconds)
log.Println(v...)
color2.Light().Println(v...)
}
func Fatal(v ...interface{}) {
log.Fatal(v...)
}
func Printf(format string, v ...interface{}) {
log.Printf(format, v...)
}
func Success(v ...interface{}) {
ColorPrintln(color.Green, v...)
}
func Info(v ...interface{}) {
ColorPrintln(color.LightCyan, v...)
}
func Warning(v ...interface{}) {
ColorPrintln(color.Yellow, v...)
}
func Error(v ...interface{}) {
ColorPrintln(color.FgLightRed, v...)
os.Exit(0)
}

18
main.go

@ -5,28 +5,16 @@ import (
"github.com/unknwon/goconfig"
"github.com/ztino/jd_seckill/cmd"
"github.com/ztino/jd_seckill/common"
"io"
"log"
"github.com/ztino/jd_seckill/log"
"os"
"runtime"
"time"
)
func init() {
//日志初始化,将日志同时输出到控制台和文件
//日志初始化
if !common.IsDir("./logs/") {
_=os.Mkdir("./logs/",0777)
_ = os.Mkdir("./logs/", 0777)
}
file := "./logs/jd_seckill_" + time.Now().Format("20060102") + ".log"
logFile, logErr := os.OpenFile(file, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
if logErr != nil {
panic(logErr)
}
defer logFile.Close()
mw := io.MultiWriter(os.Stdout, logFile)
log.SetOutput(mw)
log.SetPrefix("[jd_seckill] ")
log.SetFlags(log.LstdFlags | log.Lshortfile | log.LUTC)
//客户端设置初始化
common.Client=httpc.NewHttpClient()

2
service/dingtalk.go

@ -3,7 +3,7 @@ package service
import (
"github.com/blinkbean/dingtalk"
"github.com/unknwon/goconfig"
"log"
"github.com/ztino/jd_seckill/log"
)
type Dingtalk struct {

2
service/email.go

@ -2,8 +2,8 @@ package service
import (
"github.com/unknwon/goconfig"
"github.com/ztino/jd_seckill/log"
"gopkg.in/gomail.v2"
"log"
"strconv"
)

9
service/wechat.go

@ -6,8 +6,7 @@ import (
"github.com/Albert-Zhan/httpc"
"github.com/tidwall/gjson"
"github.com/unknwon/goconfig"
"log"
"net/http"
"github.com/ztino/jd_seckill/log"
)
type Wechat struct {
@ -23,11 +22,7 @@ func (this *Wechat) Send(title,msg string) error {
req:=httpc.NewRequest(client)
url:=fmt.Sprintf("http://sc.ftqq.com/%s.send",this.conf.MustValue("messenger","server_chan_sckey",""))
req.SetHeader("User-Agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36")
resp,body,err:=req.SetUrl(url+"?text="+title+"&desp="+msg).SetMethod("get").Send().End()
if err!=nil || resp.StatusCode!=http.StatusOK {
log.Println("微信推送失败,网络错误")
return errors.New("微信推送失败,网络错误")
}
_,body,_:=req.SetUrl(url+"?text="+title+"&desp="+msg).SetMethod("get").Send().End()
if gjson.Get(body,"errno").Int()!=0 {
log.Println("微信推送失败,返回错误:"+gjson.Get(body,"errmsg").String())
return errors.New("微信推送失败,返回错误:"+gjson.Get(body,"errmsg").String())

Loading…
Cancel
Save