forked from sideshow/apns2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
47 lines (38 loc) · 943 Bytes
/
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
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/AlexStocks/apns2"
"github.com/AlexStocks/apns2/certificate"
)
func main() {
certPath := flag.String("cert", "", "Path to .p12 certificate file (Required)")
token := flag.String("token", "", "Push token (Required)")
topic := flag.String("topic", "", "Topic (Required)")
flag.Parse()
if *certPath == "" || *token == "" || *topic == "" {
flag.PrintDefaults()
os.Exit(1)
}
cert, err := certificate.FromP12File(*certPath, "")
if err != nil {
log.Fatal("Cert Error:", err)
}
notification := &apns2.Notification{}
notification.DeviceToken = *token
notification.Topic = *topic
notification.Payload = []byte(`{
"aps" : {
"alert" : "Hello!"
}
}
`)
client := apns2.NewClient(cert).Production()
res, err := client.Push(notification)
if err != nil {
log.Fatal("Error:", err)
}
fmt.Printf("%v %v %v\n", res.StatusCode, res.ApnsID, res.Reason)
}