You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.4 KiB

2 years ago
package message
import (
"bytes"
"message-demo/global"
"encoding/json"
"log"
"net/http"
)
type Bark struct {
url string
key string
}
var b = Bark{}
func initBark() {
//b.url = "https://bark.zggsong.cn/push/"
//b.key = "CpYMsRyciG9hrktVXSAeW3" //mac
//b.key = "wHfht3s7R3wTEUB2FmSHM8" //iphone
b.url = global.GLO_CONF.BarkUrl
b.key = global.GLO_CONF.BarkKey
Register("bark", b)
}
func (m Bark) Send(message MessageBody) {
log.Println("[bark] Sending by bark...")
var reqBody = Request{
//Badge: 2,
DeviceKey: b.key,
Title: message.Title,
Body: message.Content,
Icon: "https://m.luxshare-ict.com/favicon.ico",
Url: "https:////github.com/zggsong",
}
req, _ := json.Marshal(reqBody)
resp, err := http.Post(m.url, "application/json; charset=utf-8", bytes.NewReader(req))
if err != nil {
log.Fatalf("[bark] http post failed: %v\n", err)
}
defer resp.Body.Close()
log.Printf("[bark] Send successful")
}
type Request struct {
Body string `json:"body"`
DeviceKey string `json:"device_key"`
Title string `json:"title"`
Badge int `json:"badge"`
Category string `json:"category"`
Sound string `json:"sound"`
Icon string `json:"icon"`
Group string `json:"group"`
Url string `json:"url"`
}
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
Timestamp int `json:"timestamp"`
}