push plus推送减少推送次数,当数据达到十条后再一起推送
This commit is contained in:
parent
d12dad7ae8
commit
08e49b4ad4
1
main.go
1
main.go
|
@ -259,4 +259,5 @@ func do(m string) {
|
|||
}
|
||||
message := "学习完成:今日得分:" + strconv.Itoa(score.TodayScore)
|
||||
core.Push("markdown", message)
|
||||
core.Push("flush", "学习完成")
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package push
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/guonaihong/gout"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
@ -12,14 +13,13 @@ type PushPlus struct {
|
|||
}
|
||||
|
||||
func (p *PushPlus) Init() func(kind, message string) {
|
||||
return func(kind, message string) {
|
||||
if kind == "image" {
|
||||
message = fmt.Sprintf("", "data:image/png;base64,"+message)
|
||||
}
|
||||
var datas []string
|
||||
|
||||
send := func(data string) {
|
||||
err := gout.POST("http://www.pushplus.plus/send").SetJSON(gout.H{
|
||||
"token": p.Token,
|
||||
"title": "study_xxqg",
|
||||
"content": message,
|
||||
"content": data,
|
||||
"template": "markdown",
|
||||
"channel": "wechat",
|
||||
}).Do()
|
||||
|
@ -28,4 +28,18 @@ func (p *PushPlus) Init() func(kind, message string) {
|
|||
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