forked from zqjzqj/mtSecKill
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7a8a199
Showing
10 changed files
with
908 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
.idea/ | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Jd_Seckill | ||
|
||
## 特别声明: | ||
|
||
* 本仓库发布的`mtSecKill`项目中涉及的任何脚本,仅用于测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。 | ||
|
||
* 本项目内所有资源文件,禁止任何公众号、自媒体进行任何形式的转载、发布。 | ||
|
||
* `zqijzqj` 对任何脚本问题概不负责,包括但不限于由任何脚本错误导致的任何损失或损害. | ||
|
||
* 间接使用脚本的任何用户,包括但不限于建立VPS或在某些行为违反国家/地区法律或相关法规的情况下进行传播, `zqjzqj` 对于由此引起的任何隐私泄漏或其他后果概不负责。 | ||
|
||
* 请勿将`mtSecKill`项目的任何内容用于商业或非法目的,否则后果自负。 | ||
|
||
* 如果任何单位或个人认为该项目的脚本可能涉嫌侵犯其权利,则应及时通知并提供身份证明,所有权证明,我们将在收到认证文件后删除相关脚本。 | ||
|
||
* 以任何方式查看此项目的人或直接或间接使用`mtSecKill`项目的任何脚本的使用者都应仔细阅读此声明。`zqjzqj` 保留随时更改或补充此免责声明的权利。一旦使用并复制了任何相关脚本或`mtSecKill`项目,则视为您已接受此免责声明。 | ||
|
||
* 您必须在下载后的24小时内从计算机或手机中完全删除以上内容。 | ||
|
||
* 本项目遵循`GPL-3.0 License`协议,如果本特别声明与`GPL-3.0 License`协议有冲突之处,以本特别声明为准。 | ||
|
||
* 该版本为未测试版本 运行过程可能会出错 从理论上来说 应该抢不了 后续会测试优化 | ||
|
||
* mtSecKill -sku=100012043978 -num=2 -works=6 -time=09:59:59 运行参数 均有默认可以不加 | ||
|
||
> ***您使用或者复制了本仓库且本人制作的任何代码或项目,则视为`已接受`此声明,请仔细阅读*** | ||
> ***您在本声明未发出之时点使用或者复制了本仓库且本人制作的任何代码或项目且此时还在使用,则视为`已接受`此声明,请仔细阅读*** | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
package chromedpEngine | ||
|
||
import ( | ||
"context" | ||
"github.com/chromedp/cdproto/dom" | ||
"github.com/chromedp/cdproto/log" | ||
"github.com/chromedp/cdproto/network" | ||
"github.com/chromedp/cdproto/page" | ||
"github.com/chromedp/cdproto/target" | ||
"github.com/chromedp/chromedp" | ||
"github.com/zqijzqj/mtSecKill/global" | ||
"github.com/zqijzqj/mtSecKill/logs" | ||
"math/rand" | ||
"net/http" | ||
"sync" | ||
"time" | ||
) | ||
|
||
var DefaultOptions = []chromedp.ExecAllocatorOption{ | ||
chromedp.Flag("headless", false), | ||
chromedp.Flag("hide-scrollbars", false), | ||
chromedp.Flag("mute-audio", true), | ||
chromedp.Flag("disable-infobars", true), | ||
chromedp.Flag("enable-automation", false), | ||
chromedp.Flag("ignore-certificate-errors", true), | ||
chromedp.Flag("start-maximized", true), | ||
|
||
//chromedp.Flag("blink-settings", "imagesEnabled=false"), | ||
chromedp.Flag("disable-default-apps", false), | ||
chromedp.Flag("no-sandbox", false), | ||
// 隐身模式启动 | ||
//chromedp.Flag("incognito", true), | ||
chromedp.Flag("disable-extensions", false), | ||
chromedp.Flag("disable-plugins", false), | ||
//chromedp.Flag("disable-software-rasterizer", true), | ||
chromedp.NoDefaultBrowserCheck, | ||
chromedp.DisableGPU, | ||
chromedp.NoFirstRun, | ||
} | ||
|
||
var globalCtx *GlobalBackgroundCtx = nil | ||
var mu sync.Mutex | ||
type GlobalBackgroundCtx struct { | ||
background context.Context | ||
Cancel context.CancelFunc | ||
} | ||
|
||
func GetGlobalCtx() context.Context { | ||
if globalCtx == nil { | ||
NewGlobalCtx() | ||
} | ||
return globalCtx.background | ||
} | ||
|
||
|
||
func NewGlobalCtx() { | ||
|
||
mu.Lock() | ||
defer mu.Unlock() | ||
if globalCtx != nil { | ||
return | ||
} | ||
c, cc := context.WithCancel(context.Background()) | ||
globalCtx = &GlobalBackgroundCtx{ | ||
background: c, | ||
Cancel: cc, | ||
} | ||
} | ||
|
||
func CancelGlobalCtx() { | ||
mu.Lock() | ||
defer mu.Unlock() | ||
if globalCtx == nil { | ||
return | ||
} | ||
cc := globalCtx.Cancel | ||
cc() | ||
logs.PrintlnSuccess("cancel global ctx...") | ||
globalCtx = nil | ||
return | ||
} | ||
|
||
var UserAgent = []string{ | ||
"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36", | ||
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50", | ||
"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0", | ||
"Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.10) Gecko/20100922 Ubuntu/10.10 (maverick) Firefox/3.6.10", | ||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0", | ||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE", | ||
"Mozilla/5.0 (Windows NT 6.1; Win64; x64; Trident/7.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; rv:11.0) like Gecko", | ||
"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 OPR/60.0.3255.84", | ||
"Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11", | ||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2", | ||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36", | ||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER", | ||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3676.400 QQBrowser/10.4.3473.400", | ||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36 Maxthon/5.2.7.2500", | ||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36", | ||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 BIDUBrowser/8.7 Safari/537.36", | ||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36 QIHU 360EE", | ||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36", | ||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36", | ||
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1)", | ||
"Mozilla/5.0 (Windows; U; Windows NT 6.0; en; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7", | ||
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36", | ||
} | ||
|
||
func GetRandUserAgent() string { | ||
RE: | ||
al := len(UserAgent) | ||
if al > 1 { | ||
rand.Seed(time.Now().UnixNano()) | ||
return UserAgent[rand.Intn(al)] | ||
} | ||
goto RE | ||
} | ||
|
||
func AddDefaultOptions(option ...chromedp.ExecAllocatorOption) { | ||
DefaultOptions = append(DefaultOptions, option...) | ||
} | ||
|
||
func RequestByCookie(ctx context.Context, req *http.Request) (*http.Response, error) { | ||
httpClient := &http.Client{} | ||
cookies, err := network.GetAllCookies().Do(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, c := range cookies { | ||
ct := time.Unix(int64(c.Expires), 0) | ||
c2 := &http.Cookie{ | ||
Name: c.Name, | ||
Value: c.Value, | ||
Path: c.Path, | ||
Domain: c.Domain, | ||
Expires: ct, | ||
RawExpires: ct.Format(global.DateTimeFormatStr), | ||
Secure: c.Secure, | ||
HttpOnly: c.HTTPOnly, | ||
} | ||
req.AddCookie(c2) | ||
} | ||
return httpClient.Do(req) | ||
} | ||
|
||
|
||
func CreateOptions(opts ...chromedp.ExecAllocatorOption) []chromedp.ExecAllocatorOption { | ||
options := append(chromedp.DefaultExecAllocatorOptions[:], DefaultOptions...) | ||
options = append(options, opts...) | ||
return options | ||
} | ||
|
||
func WaitDocumentUpdated(ctx context.Context) (<-chan struct{}, context.CancelFunc) { | ||
ctxNew, ccNew := context.WithCancel(ctx) | ||
_ = dom.Enable().Do(ctxNew) | ||
_ = page.Enable().Do(ctxNew) | ||
ch := make(chan struct{}, 1) | ||
chromedp.ListenTarget(ctxNew, func(ev interface{}) { | ||
isUpdated := false | ||
switch ev.(type) { | ||
case *dom.EventDocumentUpdated: | ||
isUpdated = true | ||
case *dom.EventCharacterDataModified: | ||
isUpdated = true | ||
case *target.EventTargetInfoChanged: | ||
isUpdated = true | ||
case *target.EventTargetCreated: | ||
isUpdated = true | ||
default: | ||
return | ||
} | ||
if isUpdated { | ||
select { | ||
case <- ctxNew.Done(): | ||
case ch <- struct{}{}: | ||
} | ||
close(ch) | ||
ccNew() | ||
return | ||
} | ||
}) | ||
return ch, ccNew | ||
} | ||
|
||
func NewExecCtx(opts ...chromedp.ExecAllocatorOption) (context.Context, context.CancelFunc) { | ||
topC, _ := context.WithCancel(GetGlobalCtx()) | ||
c, _ := chromedp.NewExecAllocator(topC, CreateOptions(opts...)...) | ||
ctx, cancel := chromedp.NewContext(c) | ||
return ctx, cancel | ||
} | ||
|
||
func NewExecAllocator(tasks chromedp.Tasks, opts ...chromedp.ExecAllocatorOption) error { | ||
//超时设置 | ||
topC, topCC := context.WithCancel(GetGlobalCtx()) | ||
defer topCC() | ||
c, cc := chromedp.NewExecAllocator(topC, CreateOptions(opts...)...) | ||
defer cc() | ||
ctx, cancel := chromedp.NewContext(c) | ||
defer cancel() | ||
_ = log.Disable().Do(ctx) | ||
err := chromedp.Run(ctx, tasks) | ||
logs.PrintlnSuccess("chromedp.Run end...") | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
//阻塞浏览器方法 | ||
func WaitAction(wait sync.WaitGroup) chromedp.ActionFunc { | ||
return func(ctx context.Context) error { | ||
wait.Add(1) | ||
wait.Wait() | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"flag" | ||
"github.com/zqijzqj/mtSecKill/global" | ||
"github.com/zqijzqj/mtSecKill/logs" | ||
"github.com/zqijzqj/mtSecKill/secKill" | ||
"os" | ||
"strings" | ||
"time" | ||
) | ||
|
||
var skuId = flag.String("sku", "100012043978", "茅台商品ID") | ||
var num = flag.Int("num", 2, "茅台商品ID") | ||
var works = flag.Int("works", 6, "并发数") | ||
var start = flag.String("time", "09:59:59", "开始时间---不带日期") | ||
|
||
func main() { | ||
var err error | ||
execPath := "" | ||
RE: | ||
jdSecKill := secKill.NewJdSecKill(execPath, *skuId, *num, *works) | ||
jdSecKill.StartTime, err = global.Hour2Unix(*start) | ||
if err != nil { | ||
logs.Fatal("开始时间初始化失败", err) | ||
} | ||
|
||
if jdSecKill.StartTime.Unix() < time.Now().Unix() { | ||
jdSecKill.StartTime = jdSecKill.StartTime.AddDate(0, 0, 1) | ||
} | ||
logs.PrintlnInfo("开始执行时间为:", jdSecKill.StartTime.Format(global.DateTimeFormatStr)) | ||
err = jdSecKill.Run() | ||
if err != nil { | ||
if strings.Contains(err.Error(), "exec") { | ||
logs.PrintlnInfo("默认浏览器执行路径未找到,"+execPath+" 请重新输入:") | ||
scanner := bufio.NewScanner(os.Stdin) | ||
for scanner.Scan() { | ||
execPath = scanner.Text() | ||
if execPath != "" { | ||
break | ||
} | ||
} | ||
goto RE | ||
} | ||
logs.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package global | ||
|
||
|
||
//这个包放置公共常量 | ||
const ( | ||
DateTimeFormatStr = "2006-01-02 15:04:05" | ||
DateFormatStr = "2006-01-02" | ||
|
||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package global | ||
|
||
import ( | ||
"crypto/md5" | ||
"encoding/json" | ||
"fmt" | ||
"math/rand" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
func GenerateRangeNum(min, max int64) int64 { | ||
rand.Seed(time.Now().UnixNano()) | ||
randNum := rand.Int63n(max - min) + min | ||
return randNum | ||
} | ||
|
||
func Hour2Unix(hour string) (time.Time, error) { | ||
return time.ParseInLocation(DateTimeFormatStr, time.Now().Format(DateFormatStr) + " " + hour, time.Local) | ||
} | ||
|
||
func Md5(s string) string { | ||
data := []byte(s) | ||
has := md5.Sum(data) | ||
return fmt.Sprintf("%x", has) | ||
} | ||
|
||
func Json2Map(j string) map[string]interface{} { | ||
r := make(map[string]interface{}) | ||
_ = json.Unmarshal([]byte(j), &r) | ||
return r | ||
} | ||
|
||
|
||
func RandFloats(min, max float64, n int) float64 { | ||
rand.Seed(time.Now().UnixNano()) | ||
res := min + rand.Float64() * (max - min) | ||
res, _ = strconv.ParseFloat(fmt.Sprintf("%."+strconv.Itoa(n)+"f", res), 64) | ||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module github.com/zqijzqj/mtSecKill | ||
|
||
go 1.14 | ||
|
||
require ( | ||
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 | ||
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/tidwall/gjson v1.6.7 | ||
golang.org/x/sys v0.0.0-20201223074533-0d417f636930 // indirect | ||
) |
Oops, something went wrong.