-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotification.go
More file actions
200 lines (180 loc) · 6.01 KB
/
Copy pathnotification.go
File metadata and controls
200 lines (180 loc) · 6.01 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package jpush
//Notification 通知
type Notification struct {
Alert string `json:"alert"`
Android *AndroidNotification `json:"android,omitempty"`
IOS *IOSNotification `json:"ios,omitempty"`
}
//AndroidNotification 安卓推送
type AndroidNotification struct {
Alert string `json:"alert"`
Title string `json:"title,omitempty"`
BuilderID int `json:"builder_id,omitempty"`
Priority int `json:"priority,omitempty"`
Category string `json:"category,omitempty"`
Style int `json:"style,omitempty"`
AlertType int `json:"alert_type,omitempty"`
BigText string `json:"big_text,omitempty"`
Inbox interface{} `json:"inbox,omitempty"`
BigPicPath string `json:"big_pic_path,omitempty"`
Extras map[string]string `json:"extras,omitempty"`
}
//IOSNotification IOSNotification
type IOSNotification struct {
Alert interface{} `json:"alert"`
Sound string `json:"sound,omitempty"`
Badge int `json:"badge,omitempty"`
ContentAvailable bool `json:"content-available,omitempty"`
MutableContent bool `json:"mutable-content,omitempty"`
Category string `json:"category,omitempty"`
Extras map[string]string `json:"extras,omitempty"`
}
// IOSAlert IOSAlert
type IOSAlert struct {
Title string `json:"alert"`
Body string `json:"body"`
TitleLocKey string `json:"title-loc-key,omitempty"`
TitleLocArgs []string `json:"title-loc-args,omitempty"`
ActionLocKey string `json:"action-loc-key,omitempty"`
LocKey string `json:"loc-key,omitempty"`
LocArgs []string `json:"loc-args,omitempty"`
LaunchImage string `json:"launch-image,omitempty"`
}
//CreateNotification 创建一个推送
func CreateNotification(alert string) (notification *Notification) {
return &Notification{
Alert: alert,
}
}
//SetNotificationAlert 设置通知Alert
func (notification *Notification) SetNotificationAlert(alert string) {
notification.Alert = alert
if notification.Android != nil {
notification.Android.Alert = alert
}
if notification.IOS != nil {
notification.IOS.Alert = alert
}
}
//AddAndroidNotification 添加安卓通知
func (notification *Notification) AddAndroidNotification(Android *AndroidNotification) {
notification.Android = Android
}
//SetAndroidNotificationTitle 设置安卓通知标题
func (notification *Notification) SetAndroidNotificationTitle(title string) {
if notification.Android == nil {
notification.Android = &AndroidNotification{
Alert: notification.Alert,
}
}
notification.Android.Title = title
}
//SetAndroidNotificationBuilder 设置安卓通知栏样式ID
func (notification *Notification) SetAndroidNotificationBuilder(id int) {
if notification.Android == nil {
notification.Android = &AndroidNotification{
Alert: notification.Alert,
}
}
notification.Android.BuilderID = id
}
//SetAndroidNotificationPriority 设置安卓通知栏展示优先级
func (notification *Notification) SetAndroidNotificationPriority(priority int) {
if notification.Android == nil {
notification.Android = &AndroidNotification{
Alert: notification.Alert,
}
}
notification.Android.Priority = priority
}
//SetAndroidNotificationExtras 设置安卓通知扩展字段
func (notification *Notification) SetAndroidNotificationExtras(extras map[string]string) {
if notification.Android == nil {
notification.Android = &AndroidNotification{
Alert: notification.Alert,
}
}
notification.Android.Extras = extras
}
//AddAndroidNotificationExtras 设置安卓通知扩展字段
func (notification *Notification) AddAndroidNotificationExtras(key, val string) {
if notification.Android == nil {
notification.Android = &AndroidNotification{
Alert: notification.Alert,
}
}
if notification.Android.Extras == nil {
notification.Android.Extras = make(map[string]string)
}
notification.Android.Extras[key] = val
}
//AddIOSNotification 添加IOS通知
func (notification *Notification) AddIOSNotification(IOS *IOSNotification) {
notification.IOS = IOS
}
//SetIOSNotificationExtras 设置IOS通知扩展字段
func (notification *Notification) SetIOSNotificationExtras(extras map[string]string) {
if notification.IOS == nil {
notification.IOS = &IOSNotification{
Alert: notification.Alert,
}
}
notification.IOS.Extras = extras
}
//SetIOSNotificationSound 设置IOS通知提示声音
func (notification *Notification) SetIOSNotificationSound(sound string) {
if notification.IOS == nil {
notification.IOS = &IOSNotification{
Alert: notification.Alert,
}
}
notification.IOS.Sound = sound
}
//AddIOSNotificationExtras 设置IOS通知扩展字段
func (notification *Notification) AddIOSNotificationExtras(key, val string) {
if notification.IOS == nil {
notification.IOS = &IOSNotification{
Alert: notification.Alert,
}
}
if notification.IOS.Extras == nil {
notification.IOS.Extras = make(map[string]string)
}
notification.IOS.Extras[key] = val
}
//AddExtras 添加通知扩展
func (notification *Notification) AddExtras(key, val string) {
if notification.Android == nil {
notification.Android = &AndroidNotification{
Alert: notification.Alert,
}
}
if notification.IOS == nil {
notification.IOS = &IOSNotification{
Alert: notification.Alert,
}
}
if notification.Android.Extras == nil {
notification.Android.Extras = make(map[string]string)
}
notification.Android.Extras[key] = val
if notification.IOS.Extras == nil {
notification.IOS.Extras = make(map[string]string)
}
notification.IOS.Extras[key] = val
}
//SetExtras 设置通知扩展
func (notification *Notification) SetExtras(extras map[string]string) {
if notification.Android == nil {
notification.Android = &AndroidNotification{
Alert: notification.Alert,
}
}
if notification.IOS == nil {
notification.IOS = &IOSNotification{
Alert: notification.Alert,
}
}
notification.Android.Extras = extras
notification.IOS.Extras = extras
}