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.
61 lines
1.3 KiB
61 lines
1.3 KiB
package message
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"log"
|
|
"message-demo/global"
|
|
"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{
|
|
DeviceKey: b.key,
|
|
Title: message.Title,
|
|
Body: message.Content,
|
|
// 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"`
|
|
}
|