feat: add pushme message

This commit is contained in:
engigu
2026-02-04 19:30:34 +08:00
parent 0c80b9cbe2
commit c1209ccee5
9 changed files with 162 additions and 0 deletions
+1
View File
@@ -66,6 +66,7 @@ const (
MessageTypeAliyunSMS = "AliyunSMS"
MessageTypeTelegram = "Telegram"
MessageTypeBark = "Bark"
MessageTypePushMe = "PushMe"
)
// 限制goroutine的最大数量
+51
View File
@@ -0,0 +1,51 @@
package message
import (
"fmt"
"io"
"net/http"
"net/url"
"strings"
)
type PushMe struct {
PushKey string
URL string
Date string
Type string
}
func (p *PushMe) Request(title, content string) (string, error) {
apiURL := p.URL
if apiURL == "" {
apiURL = "https://push.i-i.me/"
}
data := url.Values{}
data.Set("push_key", p.PushKey)
data.Set("title", title)
data.Set("content", content)
if p.Date != "" {
data.Set("date", p.Date)
}
if p.Type != "" {
data.Set("type", p.Type)
}
resp, err := http.Post(apiURL, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
if err != nil {
return "", err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
if resp.StatusCode == 200 && string(body) == "success" {
return string(body), nil
}
return string(body), fmt.Errorf("PushMe response error: %s", string(body))
}