diff --git a/conf.ini b/conf.ini index 3856915..eba8fae 100644 --- a/conf.ini +++ b/conf.ini @@ -53,4 +53,11 @@ port = # 邮箱地址 xxxxxxxx@xx.com email_user = # 邮箱授权码(并不一定是邮箱密码) xxxxxxxxxxxxxxxx -email_pwd = \ No newline at end of file +email_pwd = + +#钉钉机器人配置 +[dingtalk] +# 机器人的Webhook地址(https://oapi.dingtalk.com/robot/send?access_token=XXXXXX)的access_token +access_token = +# 密钥,机器人安全设置页面,加签一栏下面显示的SEC开头的字符串 +secret = \ No newline at end of file diff --git a/go.mod b/go.mod index e87c3fc..2d16b81 100644 --- a/go.mod +++ b/go.mod @@ -5,14 +5,18 @@ go 1.15 require ( github.com/Albert-Zhan/httpc v0.0.0-20190712132051-aed72924b5e6 github.com/PuerkitoBio/goquery v1.6.0 + github.com/blinkbean/dingtalk v0.0.0-20201231030509-45a553a84503 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/json-iterator/go v1.1.10 // indirect github.com/spf13/cobra v1.1.1 github.com/tidwall/gjson v1.6.7 github.com/unknwon/goconfig v0.0.0-20200908083735-df7de6a44db8 + 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 ) diff --git a/jd_seckill/seckill.go b/jd_seckill/seckill.go index 8be8e04..96e5b0e 100644 --- a/jd_seckill/seckill.go +++ b/jd_seckill/seckill.go @@ -63,7 +63,9 @@ func (this *Seckill) MakeReserve() { reserveUrl := gjson.Get(body, "url").String() req = httpc.NewRequest(this.client) _, _, _ = req.SetUrl("https:" + reserveUrl).SetMethod("get").Send().End() - log.Println("预约成功,已获得抢购资格 / 您已成功预约过了,无需重复预约") + msg := "预约成功,已获得抢购资格 / 您已成功预约过了,无需重复预约![我的预约](https://yushou.jd.com/member/qualificationList.action)" + _ = service.SendMessage(this.conf, "茅台抢购通知", msg) + log.Println(msg) } } diff --git a/service/dingtalk.go b/service/dingtalk.go new file mode 100644 index 0000000..7de4c74 --- /dev/null +++ b/service/dingtalk.go @@ -0,0 +1,35 @@ +package service + +import ( + "github.com/blinkbean/dingtalk" + "github.com/unknwon/goconfig" + "log" +) + +type Dingtalk struct { + conf *goconfig.ConfigFile +} + +func NewDingtalk(conf *goconfig.ConfigFile) *Dingtalk { + return &Dingtalk{conf: conf} +} + +func (this *Dingtalk) Send(title, msg string) error { + cli := dingtalk.InitDingTalkWithSecret( + this.conf.MustValue("dingtalk", "access_token", ""), + this.conf.MustValue("dingtalk", "secret", ""), + ) + markdown := []string{ + "### " + title, + "---------", + msg, + } + err := cli.SendMarkDownMessageBySlice(title, markdown) + if err != nil { + log.Println(err) + } else { + log.Println("钉钉机器人推送成功") + } + + return nil +} diff --git a/service/service.go b/service/service.go index 83b17af..35c6d4c 100644 --- a/service/service.go +++ b/service/service.go @@ -2,20 +2,26 @@ package service import "github.com/unknwon/goconfig" -func SendMessage(conf *goconfig.ConfigFile,title,msg string) error { - if conf.MustValue("messenger","enable","false")=="true" { +func SendMessage(conf *goconfig.ConfigFile, title, msg string) error { + if conf.MustValue("messenger", "enable", "false") == "true" { + //钉钉机器人 + if conf.MustValue("messenger", "type", "none") == "dingtalk" { + dingtalk := NewDingtalk(conf) + err := dingtalk.Send(title, msg) + return err + } //邮件发送 - if conf.MustValue("messenger","type","none")=="smtp" { - email:=NewEmail(conf) - err:=email.Send([]string{conf.MustValue("messenger","email","")},title,msg) + if conf.MustValue("messenger", "type", "none") == "smtp" { + email := NewEmail(conf) + err := email.Send([]string{conf.MustValue("messenger", "email", "")}, title, msg) return err } //Server酱推送 - if conf.MustValue("messenger","type","none")=="wechat" { - wechat:=NewWechat(conf) - err:=wechat.Send(title,msg) + if conf.MustValue("messenger", "type", "none") == "wechat" { + wechat := NewWechat(conf) + err := wechat.Send(title, msg) return err } } return nil -} \ No newline at end of file +}