2021-11-22 12:07:55 +00:00
|
|
|
package push
|
|
|
|
|
|
|
|
import (
|
2022-04-20 13:31:46 +00:00
|
|
|
"fmt"
|
2022-09-22 12:17:06 +00:00
|
|
|
"strings"
|
2022-04-20 13:31:46 +00:00
|
|
|
|
2021-11-22 12:07:55 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2022-09-22 12:17:06 +00:00
|
|
|
|
2022-12-14 07:43:39 +00:00
|
|
|
"github.com/sjkhsl/study_xxqg/conf"
|
|
|
|
"github.com/sjkhsl/study_xxqg/utils"
|
2021-11-22 12:07:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type PushPlus struct {
|
|
|
|
Token string
|
|
|
|
}
|
|
|
|
|
2022-08-15 07:07:03 +00:00
|
|
|
func (p *PushPlus) Init() func(id string, kind, message string) {
|
2022-05-14 04:11:55 +00:00
|
|
|
send := func(data string) {
|
2022-09-22 12:17:06 +00:00
|
|
|
_, err := utils.GetClient().R().SetBodyJsonMarshal(map[string]string{
|
2021-11-22 12:07:55 +00:00
|
|
|
"token": p.Token,
|
|
|
|
"title": "study_xxqg",
|
2022-05-14 04:11:55 +00:00
|
|
|
"content": data,
|
2021-11-22 12:07:55 +00:00
|
|
|
"template": "markdown",
|
|
|
|
"channel": "wechat",
|
2022-10-30 14:41:22 +00:00
|
|
|
"topic": conf.GetConfig().Push.PushPlus.Topic,
|
2022-09-22 12:17:06 +00:00
|
|
|
}).Post("http://www.pushplus.plus/send")
|
2021-11-22 12:07:55 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorln(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2022-05-14 04:11:55 +00:00
|
|
|
|
2022-08-15 07:07:03 +00:00
|
|
|
return func(id string, kind, message string) {
|
2022-09-22 12:17:06 +00:00
|
|
|
message = strings.ReplaceAll(message, "\n", "<br/>")
|
2022-05-20 11:55:55 +00:00
|
|
|
switch {
|
|
|
|
case kind == "image":
|
2022-05-14 04:11:55 +00:00
|
|
|
message = fmt.Sprintf("", "data:image/png;base64,"+message)
|
|
|
|
send(message)
|
2022-05-20 11:55:55 +00:00
|
|
|
case kind == "flush":
|
2022-08-10 10:17:49 +00:00
|
|
|
if message != "" {
|
|
|
|
send(message)
|
2022-05-24 13:36:35 +00:00
|
|
|
}
|
2022-05-20 11:55:55 +00:00
|
|
|
default:
|
2022-08-10 10:17:49 +00:00
|
|
|
if log.GetLevel() == log.DebugLevel {
|
|
|
|
send(message)
|
2022-05-14 04:11:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-22 12:07:55 +00:00
|
|
|
}
|