-
Notifications
You must be signed in to change notification settings - Fork 3
/
notification-message.go
213 lines (181 loc) · 7.57 KB
/
notification-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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
package goPushSdk
import (
"encoding/json"
)
//"noticeBarInfo": {
// "noticeBarType": 通知栏样式(0, "标准"),(2, "安卓原生")【int 非必填,值为0】
// "title": 推送标题, 【string 必填,字数限制1~32字符】
// "content": 推送内容, 【string 必填,字数限制1~100字符】
//}
type NoticeBarInfo struct {
NoticeBarType int `json:"noticeBarType"`
Title string `json:"title"`
Content string `json:"content"`
}
//"noticeExpandInfo": {
// "noticeExpandType": 展开方式 (0, "标准"),(1, "文本")【int 非必填,值为0、1】
// "noticeExpandContent": 展开内容, 【string noticeExpandType为文本时,必填】
// }
type NoticeExpandInfo struct {
NoticeExpandType int `json:"noticeExpandType"`
NoticeExpandContent string `json:"noticeExpandContent"`
}
//"clickTypeInfo": {
// "clickType": 点击动作 (0,"打开应用"),(1,"打开应用页面"),(2,"打开URI页面"),(3, "应用客户端自定义")【int 非必填,默认为0】
// "url": URI页面地址, 【string clickType为打开URI页面时,必填, 长度限制1000字节】
// "parameters":参数 【JSON格式】【非必填】
// "activity":应用页面地址 【string clickType为打开应用页面时,必填, 长度限制1000字节】
// "customAttribute":应用客户端自定义【string clickType为应用客户端自定义时,必填, 输入长度为1000字节以内】
// }
type ClickTypeInfo struct {
ClickType int `json:"clickType"`
Url string `json:"url"`
Parameters map[string]interface{} `json:"parameters"`
Activity string `json:"activity"`
CustomAttribute string `json:"customAttribute"`
}
//"pushTimeInfo": {
// "offLine": 是否进离线消息(0 否 1 是[validTime]) 【int 非必填,默认值为1】
// "validTime": 有效时长 (1到72 小时内的正整数) 【int offLine值为1时,必填,默认24】
// }
type PushTimeInfo struct {
OffLine int `json:"offLine"`
ValidTime int `json:"validTime"`
}
//"advanceInfo": {
// "suspend":是否通知栏悬浮窗显示 (1 显示 0 不显示) 【int 非必填,默认1】
// "clearNoticeBar":是否可清除通知栏 (1 可以 0 不可以) 【int 非必填,默认1】
// "fixDisplay":是否定时展示 (1 是 0 否) 【int 非必填,默认0】
// "fixStartDisplayTime": 定时展示开始时间(yyyy-MM-dd HH:mm:ss) 【str 非必填】
// "fixEndDisplayTime ": 定时展示结束时间(yyyy-MM-dd HH:mm:ss) 【str 非必填】
// "notificationType": {
// "vibrate": 震动 (0关闭 1 开启) , 【int 非必填,默认1】
// "lights": 闪光 (0关闭 1 开启), 【int 非必填,默认1】
// "sound": 声音 (0关闭 1 开启), 【int 非必填,默认1】
// }
// }
type AdvanceInfo struct {
Suspend int `json:"suspend"`
ClearNoticeBar int `json:"clearNoticeBar"`
FixDisplay int `json:"fixDisplay"`
FixStartDisplayTime string `json:"fixStartDisplayTime"`
FixEndDisplayTime string `json:"fixEndDisplayTime"`
NotificationType NotificationType `json:"notificationType"`
}
type NotificationType struct {
Vibrate int `json:"vibrate"`
Lights int `json:"lights"`
Sound int `json:"sound"`
}
type NotificationMessage struct {
NoticeBarInfo NoticeBarInfo `json:"noticeBarInfo"`
NoticeExpandInfo NoticeExpandInfo `json:"noticeExpandInfo"`
ClickTypeInfo ClickTypeInfo `json:"clickTypeInfo"`
PushTimeInfo PushTimeInfo `json:"pushTimeInfo"`
AdvanceInfo AdvanceInfo `json:"advanceInfo"`
}
func BuildNotificationMessage() NotificationMessage {
var notification NotificationMessage
notification.NoticeBarInfo = NoticeBarInfo{2, "", ""}
notification.NoticeExpandInfo = NoticeExpandInfo{0, ""}
clickParameterMap := map[string]interface{}{"test": "test"}
notification.ClickTypeInfo = ClickTypeInfo{0, "", clickParameterMap, "", ""}
notification.PushTimeInfo = PushTimeInfo{0, 24}
notificationType := NotificationType{1, 1, 1}
notification.AdvanceInfo = AdvanceInfo{0, 0, 0, "", "", notificationType}
return notification
}
func (message NotificationMessage) noticeBarType(barType int) NotificationMessage {
message.NoticeBarInfo.NoticeBarType = barType
return message
}
func (message NotificationMessage) noticeTitle(title string) NotificationMessage {
message.NoticeBarInfo.Title = title
return message
}
func (message NotificationMessage) noticeContent(content string) NotificationMessage {
message.NoticeBarInfo.Content = content
return message
}
func (message NotificationMessage) noticeExpandType(noticeExpandType int) NotificationMessage {
message.NoticeExpandInfo.NoticeExpandType = noticeExpandType
return message
}
func (message NotificationMessage) noticeExpandContent(noticeExpandContent string) NotificationMessage {
message.NoticeExpandInfo.NoticeExpandContent = noticeExpandContent
return message
}
func (message NotificationMessage) noticeClickType(clickType int) NotificationMessage {
message.ClickTypeInfo.ClickType = clickType
return message
}
func (message NotificationMessage) noticeClickUrl(url string) NotificationMessage {
message.ClickTypeInfo.Url = url
return message
}
func (message NotificationMessage) noticeClickParams(params map[string]interface{}) NotificationMessage {
message.ClickTypeInfo.Parameters = params
return message
}
func (message NotificationMessage) noticeClickActivity(activity string) NotificationMessage {
message.ClickTypeInfo.Activity = activity
return message
}
func (message NotificationMessage) noticeClickCustomAttribute(attribute string) NotificationMessage {
message.ClickTypeInfo.CustomAttribute = attribute
return message
}
func (message NotificationMessage) offLine(offline int) NotificationMessage {
message.PushTimeInfo.OffLine = offline
return message
}
func (message NotificationMessage) validTime(validTime int) NotificationMessage {
message.PushTimeInfo.ValidTime = validTime
return message
}
func (message NotificationMessage) suspend(suspend int) NotificationMessage {
message.AdvanceInfo.Suspend = suspend
return message
}
func (message NotificationMessage) clearNoticeBar(clear bool) NotificationMessage {
message.AdvanceInfo.ClearNoticeBar = bool2Int(clear)
return message
}
func (message NotificationMessage) fixDisplay(fixDisplay bool) NotificationMessage {
message.AdvanceInfo.FixDisplay = bool2Int(fixDisplay)
return message
}
func (message NotificationMessage) fixStartDisplayTime(fixStartDisplayTime string) NotificationMessage {
message.AdvanceInfo.FixStartDisplayTime = fixStartDisplayTime
return message
}
func (message NotificationMessage) fixEndDisplayTime(fixEndDisplayTime string) NotificationMessage {
message.AdvanceInfo.FixEndDisplayTime = fixEndDisplayTime
return message
}
func (message NotificationMessage) vibrate(vibrate bool) NotificationMessage {
message.AdvanceInfo.NotificationType.Vibrate = bool2Int(vibrate)
return message
}
func (message NotificationMessage) lights(lights bool) NotificationMessage {
message.AdvanceInfo.NotificationType.Lights = bool2Int(lights)
return message
}
func (message NotificationMessage) sound(sound bool) NotificationMessage {
message.AdvanceInfo.NotificationType.Sound = bool2Int(sound)
return message
}
func (message NotificationMessage) toJson() string {
j, err := json.Marshal(message)
if err != nil {
return ""
}
return string(j)
}
func bool2Int(b bool) int {
if b {
return 1
} else {
return 0
}
}