This repository has been archived by the owner on Jul 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.go
115 lines (102 loc) · 2.49 KB
/
message.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package goqqpushapi
import "encoding/json"
type PushMessage interface {
IsValid() bool
ToJson() string
}
type MessageAndroid struct {
Title string `json:"title"`
Content string `json:"content"`
CustomContent map[string]string `json:"custom_content"`
AcceptTime []TimeInterval `json:"accept_time"`
BuilderId int `json:"builder_id"`
NId int `json:"n_id"`
Ring int `json:"ring"`
Vibrate int `json:"vibrate"`
Clearable int `json:"clearable"`
Action ClickAction `json:"action"`
}
func NewMessageAndroid(title, content string) MessageAndroid {
var msg MessageAndroid
msg.Title = title
msg.Content = content
msg.CustomContent = make(map[string]string)
msg.AcceptTime = make([]TimeInterval, 0)
msg.BuilderId = 0
msg.NId = 0
msg.Ring = 0
msg.Vibrate = 1
msg.Clearable = 1
msg.Action.ActionType = TYPE_ACTIVITY
msg.Action.Brower.ConfirmOnUrl = 1
return msg
}
func (this MessageAndroid) IsValid() bool {
if this.Title == "" || this.Content == "" {
return false
}
for _, at := range this.AcceptTime {
if !at.IsValid() {
return false
}
}
if this.Ring != 0 && this.Ring != 1 {
return false
}
if this.Vibrate != 0 && this.Vibrate != 1 {
return false
}
if !this.Action.IsValid() {
return false
}
return true
}
func (this MessageAndroid) ToJson() string {
json, err := json.Marshal(this)
if err == nil {
return string(json)
} else {
return ""
}
}
type AlertData struct {
Body string `json:"body"`
ActionLocKey string `json:"action-loc-key"`
LocKey string `json:"loc-key"`
LocArgs []string `json:"loc-args"`
LaunchImage string `json:"launch-image"`
}
type ApsData struct {
Alert AlertData `json:"alert"`
Badge int `json:"badge"`
Sound string `json:"sound"`
ContentAvailable int `json:"content-available"`
}
type MessageIOS struct {
Aps ApsData `json:"aps"`
AcceptTime []TimeInterval `json:"accept_time"`
}
func NewMessageIOS(text string) MessageIOS {
var msg MessageIOS
msg.Aps.Alert.Body = text
return msg
}
func (this MessageIOS) IsValid() bool {
if this.Aps.Alert.Body == "" {
return false
}
for _, at := range this.AcceptTime {
if !at.IsValid() {
return false
}
}
return true
}
func (this MessageIOS) ToJson() string {
json, err := json.Marshal(this)
if err == nil {
return string(json)
} else {
return ""
}
}