push plus推送减少推送次数,当数据达到十条后再一起推送
This commit is contained in:
parent
d12dad7ae8
commit
08e49b4ad4
5
main.go
5
main.go
|
@ -213,8 +213,8 @@ func do(m string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//switch {
|
// switch {
|
||||||
//case len(users) < 1:
|
// case len(users) < 1:
|
||||||
// log.Infoln("未检测到有效用户信息,将采用登录模式")
|
// log.Infoln("未检测到有效用户信息,将采用登录模式")
|
||||||
// u, err := core.L(config.Retry.Times)
|
// u, err := core.L(config.Retry.Times)
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
|
@ -259,4 +259,5 @@ func do(m string) {
|
||||||
}
|
}
|
||||||
message := "学习完成:今日得分:" + strconv.Itoa(score.TodayScore)
|
message := "学习完成:今日得分:" + strconv.Itoa(score.TodayScore)
|
||||||
core.Push("markdown", message)
|
core.Push("markdown", message)
|
||||||
|
core.Push("flush", "学习完成")
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package push
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/guonaihong/gout"
|
"github.com/guonaihong/gout"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -12,14 +13,13 @@ type PushPlus struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PushPlus) Init() func(kind, message string) {
|
func (p *PushPlus) Init() func(kind, message string) {
|
||||||
return func(kind, message string) {
|
var datas []string
|
||||||
if kind == "image" {
|
|
||||||
message = fmt.Sprintf("", "data:image/png;base64,"+message)
|
send := func(data string) {
|
||||||
}
|
|
||||||
err := gout.POST("http://www.pushplus.plus/send").SetJSON(gout.H{
|
err := gout.POST("http://www.pushplus.plus/send").SetJSON(gout.H{
|
||||||
"token": p.Token,
|
"token": p.Token,
|
||||||
"title": "study_xxqg",
|
"title": "study_xxqg",
|
||||||
"content": message,
|
"content": data,
|
||||||
"template": "markdown",
|
"template": "markdown",
|
||||||
"channel": "wechat",
|
"channel": "wechat",
|
||||||
}).Do()
|
}).Do()
|
||||||
|
@ -28,4 +28,18 @@ func (p *PushPlus) Init() func(kind, message string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return func(kind, message string) {
|
||||||
|
if kind == "image" {
|
||||||
|
message = fmt.Sprintf("", "data:image/png;base64,"+message)
|
||||||
|
send(message)
|
||||||
|
} else if kind == "flush" {
|
||||||
|
send(strings.Join(datas, "\n"))
|
||||||
|
} else {
|
||||||
|
datas = append(datas, message)
|
||||||
|
if len(datas) > 10 {
|
||||||
|
send(strings.Join(datas, "\n"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue