-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.go
195 lines (171 loc) · 5.1 KB
/
template.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
package getui
const (
// MediaTypeImage 图片
MediaTypeImage MediaType = iota + 1
// MediaTypeAudio 音频
MediaTypeAudio
// MediaTypeVideo 视频
MediaTypeVideo
)
// Template 模板
type Template interface {
// Name 名字
Name() string
}
// MediaType 媒体类型
type MediaType int
// Style 模板样式
// http://docs.getui.com/getui/server/rest/template/
type Style struct {
Type int `json:"type"`
Text string `json:"text"`
Title string `json:"title"`
BigStyle int `json:"big_style,omitempty"`
BigImageURL string `json:"big_image_url,omitempty"`
Logo string `json:"logo,omitempty"`
LogoURL string `json:"logourl,omitempty"`
IsRing bool `json:"is_ring,omitempty"`
IsVibrate bool `json:"is_vibrate,omitempty"`
IsClearable bool `json:"is_clearable,omitempty"`
NotifyID int `json:"notify_id,omitempty"`
ChannelLevel int `json:"channel_level,omitempty"`
}
// NewStyle 样式
// 默认: type=0
func NewStyle(text, title string) Style {
return Style{
Type: 0,
Text: text,
Title: title,
Logo: "",
IsRing: true,
IsVibrate: true,
IsClearable: true,
BigStyle: 1,
ChannelLevel: 4,
}
}
// Notification 应用模板样式
// 模板消息的一种 (Template)
// http://docs.getui.com/getui/server/rest/template/
type Notification struct {
TransmissionType bool `json:"transmission_type,omitempty"`
TransmissionContent string `json:"transmission_content,omitempty"`
DurationBegin string `json:"duration_begin,omitempty"`
DurationEnd string `json:"duration_end,omitempty"`
Style Style `json:"style"`
}
// Name 模板名字
func (Notification) Name() string {
return "notification"
}
// NewNotification 返回消息类型
func NewNotification(text, title string) *Notification {
return &Notification{
TransmissionType: true,
Style: NewStyle(text, title),
}
}
// Link 打开网页模板
// http://docs.getui.com/getui/server/rest/template/
type Link struct {
URL string `json:"url"`
DurationBegin string `json:"duration_begin,omitempty"`
DurationEnd string `json:"duration_end,omitempty"`
Style Style `json:"style"`
}
// Name 模板名字
func (Link) Name() string {
return "link"
}
// NewLink 返回消息类型
func NewLink(url, text, title string) *Link {
return &Link{
URL: url,
Style: NewStyle(text, title),
}
}
// Transmission 透传
// http://docs.getui.com/getui/server/rest/template/
type Transmission struct {
TransmissionContent string `json:"transmission_content"`
TransmissionType bool `json:"transmission_type,omitempty"`
DurationBegin string `json:"duration_begin,omitempty"`
DurationEnd string `json:"duration_end,omitempty"`
}
// Name 模板名字
func (Transmission) Name() string {
return "transmission"
}
// NewTransmission 返回透传模板
// title 横幅标题
// text 横幅内容
// content 透传内容
func NewTransmission(text, title, content string) (*Transmission, PushInfo) {
alert := Alert{}
alert.Body = text
alert.Title = title
aps := APS{}
aps.Alert = alert
aps.AutoBadge = `+1`
aps.ContentAvailable = 0
pushInfo := PushInfo{}
pushInfo.APS = aps
pushInfo.Payload = content
return &Transmission{
TransmissionType: true,
TransmissionContent: content,
}, pushInfo
}
// StartActivity 打开指定页面
// http://docs.getui.com/getui/server/rest/template/
type StartActivity struct {
TransmissionType bool `json:"transmission_type,omitempty"`
TransmissionContent string `json:"transmission_content,omitempty"`
DurationBegin string `json:"duration_begin,omitempty"`
DurationEnd string `json:"duration_end,omitempty"`
Intent string `json:"intent"`
Style Style `json:"style"`
}
// Name 返回模板名字
func (StartActivity) Name() string {
return "startactivity"
}
// NewStartActivity 返回打开指定页面的模板
func NewStartActivity(text, title string) *StartActivity {
return &StartActivity{
TransmissionType: true,
Style: NewStyle(text, title),
}
}
// Alert 消息
type Alert struct {
Title string `json:"title"`
Body string `json:"body"`
LocKey string `json:"loc-key,omitempty"`
LocArgs []string `json:"loc-args,omitempty"`
LaunchImage string `json:"launch-image,omitempty"`
TitleLocKey string `json:"title-loc-key,omitempty"`
TitleLocArgs string `json:"title-loc-args,omitempty"`
ActionLocKey string `json:"action-loc-key,omitempty"`
}
// APS 苹果推送
type APS struct {
Alert Alert `json:"alert"`
AutoBadge string `json:"autoBadge"`
ContentAvailable int `json:"content-available"`
Sound string `json:"sound,omitempty"`
Category string `json:"category,omitempty"`
}
// Media 媒体信息
type Media struct {
URL string `json:"url"`
Type MediaType `json:"type"`
OnlyWifi bool `json:"only_wifi,omitempty"`
}
// PushInfo IOS推送
type PushInfo struct {
APS APS `json:"aps"`
Payload string `json:"payload,omitempty"`
Multimedia []Media `json:"multimedia,omitempty"`
}