diff --git a/conf/config.go b/conf/config.go index 7b1cec5..f8be011 100644 --- a/conf/config.go +++ b/conf/config.go @@ -72,6 +72,12 @@ type Config struct { // 专项答题可接受的最小值 SpecialMinScore int `json:"special_min_score" yaml:"special_min_score"` + PushDeer struct { + Enable bool `json:"enable" yaml:"enable"` + Api string `json:"api" yaml:"api"` + Token string `json:"token" yaml:"token"` + } `json:"push_deer" yaml:"push_deer"` + ReverseOrder bool `json:"reverse_order" yaml:"reverse_order"` JiGuangPush struct { diff --git a/conf/config_default.yml b/conf/config_default.yml index c6136f0..b29a9b4 100644 --- a/conf/config_default.yml +++ b/conf/config_default.yml @@ -77,6 +77,13 @@ wechat: # 微信管理员的openid,可点击关于按钮获得,配置后请重启程序 super_open_id: "" + +# pushDeer推送配置,详情参考psuhDeer官网:http://www.pushdeer.com/official.html +push_deer: + enable: false + api: "https://api2.pushdeer.com" + token: "" + # 登录重试配置 retry: # 重试次数 diff --git a/docs/push.md b/docs/push.md index 7ebeacd..7405117 100644 --- a/docs/push.md +++ b/docs/push.md @@ -79,7 +79,7 @@ web: # 监听的端口号 0-65535可选 port: 8081 # web端登录得账号 - account: admin + account:admin # web端登录的密码 password: admin ``` @@ -153,4 +153,16 @@ tg: `/study_all` 按顺序对cookie有效的所有用户进行学习 +### PushDeer推送配置 +pishDeer也仅支持单向推送 + +配置: +```yaml +push_deer: + enable: true + api: "https://api2.pushdeer.com" + token: "" +``` + +自行注册pushDeer后获取token,配置token到配置文件即可,api默认为官方api,若为自建,则配置对应接口即可 \ No newline at end of file diff --git a/go.mod b/go.mod index 4d007ff..717cd9f 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ replace github.com/willf/bitset v1.2.1 => github.com/bits-and-blooms/bitset v1.2 require ( github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f + github.com/Luoxin/go-pushdeer-sdk v0.0.0-20220308071956-e50d1ec38c98 github.com/dustin/go-humanize v1.0.0 github.com/gin-gonic/gin v1.7.1 github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.4.0-beta.0 @@ -30,12 +31,12 @@ require ( ) require ( - github.com/Luoxin/go-pushdeer-sdk v0.0.0-20220308071956-e50d1ec38c98 // indirect github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-playground/locales v0.13.0 // indirect github.com/go-playground/universal-translator v0.17.0 // indirect github.com/go-playground/validator/v10 v10.5.0 // indirect + github.com/go-resty/resty/v2 v2.7.0 // indirect github.com/go-stack/stack v1.8.1 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/hashicorp/errwrap v1.0.0 // indirect diff --git a/go.sum b/go.sum index 957c625..435c8c2 100644 --- a/go.sum +++ b/go.sum @@ -24,6 +24,7 @@ github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+ github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= github.com/go-playground/validator/v10 v10.5.0 h1:X9rflw/KmpACwT8zdrm1upefpvdy6ur8d1kWyq6sg3E= github.com/go-playground/validator/v10 v10.5.0/go.mod h1:xm76BBt941f7yWdGnI2DVPFFg1UK3YY04qifoXU3lOk= +github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY= github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I= github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= diff --git a/push/push.go b/push/push.go index 8ea2605..b44934b 100644 --- a/push/push.go +++ b/push/push.go @@ -45,6 +45,10 @@ func GetPush(config conf.Config) func(id string, kind string, message string) { log.Infoln("已配置tg推送") pushs = append(pushs, tgPush) } + if config.PushDeer.Enable { + log.Infoln("已配置pushDeer推送") + pushs = append(pushs, InitPushDeer()) + } if config.JiGuangPush.Enable { pushs = append(pushs, func(id, kind, message string) { _ = PushMessage("", message, message, id) diff --git a/push/pushDeer.go b/push/pushDeer.go new file mode 100644 index 0000000..84c8e9f --- /dev/null +++ b/push/pushDeer.go @@ -0,0 +1,36 @@ +package push + +import ( + "net/url" + "strings" + + log "github.com/sirupsen/logrus" + + "github.com/johlanse/study_xxqg/conf" + "github.com/johlanse/study_xxqg/utils" +) + +func InitPushDeer() func(id, kind, message string) { + config := conf.GetConfig() + + return func(id, kind, message string) { + values := url.Values{} + values.Add("pushkey", config.PushDeer.Token) + values.Add("text", strings.ReplaceAll(message, "
", "\n")) + if kind == "flush" { + _, _ = utils.GetClient().R().SetBody(values.Encode()). + SetHeader("Content-type", "application/x-www-form-urlencoded"). + Post(config.PushDeer.Api + "/message/push") + + } else { + if log.GetLevel() == log.DebugLevel { + _, _ = utils.GetClient().R().SetBody(values.Encode()). + SetHeader("Content-type", "application/x-www-form-urlencoded"). + Post(config.PushDeer.Api + "/message/push") + + } + } + + } + +}