-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (40 loc) · 1.05 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
"strconv"
"strings"
// _ "github.com/joho/godotenv/autoload"
)
func main() {
p := Plugin{}
// var err error
p.AppToken = os.Getenv("PLUGIN_APP_TOKEN")
p.Content = os.Getenv("PLUGIN_CONTENT")
p.ContentType, _ = strconv.Atoi(os.Getenv("PLUGIN_CONTENT_TYPE"))
p.Uids = strings.Split(os.Getenv("PLUGIN_UIDS"), ",")
// p.TopicIds = strings.Split(os.Getenv("PLUGIN_TOPIC_IDS"), ",")
p.URL = os.Getenv("PLUGIN_URL")
p.Exec()
}
type Plugin struct {
AppToken string `json:"appToken"`
Content string `json:"content"`
ContentType int `json:"contentType"`
TopicIds []int `json:"topicIds,omitempty"`
Uids []string `json:"uids"`
URL string `json:"url,omitempty"`
}
func (p *Plugin) Exec() {
jsonStr, _ := json.Marshal(p)
fmt.Println(string(jsonStr))
postUrl := "http://wxpusher.zjiecode.com/api/send/message"
_, err := http.Post(postUrl, "application/json", bytes.NewBuffer(jsonStr))
if err != nil {
os.Exit(-1)
}
// fmt.Println(res)
}