|
@@ -5,21 +5,44 @@ import ( |
|
@@ -5,21 +5,44 @@ import ( |
5
|
"openapi/internal/push"
|
5
|
"openapi/internal/push"
|
6
|
)
|
6
|
)
|
7
|
|
7
|
|
8
|
-type Template struct {
|
|
|
9
|
- ClientId string `json:"cid,omitempty"`
|
|
|
10
|
- RequestId string `json:"requestid,omitempty"`
|
|
|
11
|
- Message *Message `json:"message"`
|
|
|
12
|
-}
|
|
|
13
|
-
|
|
|
14
|
//1.消息模板
|
8
|
//1.消息模板
|
15
|
type NotificationTemplate struct {
|
9
|
type NotificationTemplate struct {
|
16
|
*Template
|
10
|
*Template
|
17
|
Notification *Notification `json:"notification"`
|
11
|
Notification *Notification `json:"notification"`
|
18
|
}
|
12
|
}
|
19
|
|
13
|
|
|
|
14
|
+//1.新建通知模板
|
|
|
15
|
+func NewNotificationTemplate(options *push.Options) *NotificationTemplate {
|
|
|
16
|
+ return &NotificationTemplate{
|
|
|
17
|
+ Template: NewTemplate(options),
|
|
|
18
|
+ Notification: &Notification{
|
|
|
19
|
+ Style: (&Style{}).SetStyle0(options),
|
|
|
20
|
+ Transmission: NewTransmission(options),
|
|
|
21
|
+ },
|
|
|
22
|
+ }
|
|
|
23
|
+}
|
|
|
24
|
+
|
20
|
//2.透传模板
|
25
|
//2.透传模板
|
21
|
-type TransmissionTemplate struct{}
|
26
|
+type TransmissionTemplate struct {
|
|
|
27
|
+ *Template
|
|
|
28
|
+ Transmission *Transmission `json:"transmission"`
|
|
|
29
|
+ PushInfo *PushInfo `json:"push_info"`
|
|
|
30
|
+}
|
22
|
|
31
|
|
|
|
32
|
+//2.新建透传模板
|
|
|
33
|
+func NewTransmissionTemplate(options *push.Options) *TransmissionTemplate {
|
|
|
34
|
+ return &TransmissionTemplate{
|
|
|
35
|
+ Template: NewTemplate(options),
|
|
|
36
|
+ Transmission: NewTransmission(options),
|
|
|
37
|
+ PushInfo: NewPushInfo(options),
|
|
|
38
|
+ }
|
|
|
39
|
+}
|
|
|
40
|
+
|
|
|
41
|
+type Template struct {
|
|
|
42
|
+ ClientId string `json:"cid,omitempty"`
|
|
|
43
|
+ RequestId string `json:"requestid,omitempty"`
|
|
|
44
|
+ Message *Message `json:"message"`
|
|
|
45
|
+}
|
23
|
type Notification struct {
|
46
|
type Notification struct {
|
24
|
Style *Style `json:"style"`
|
47
|
Style *Style `json:"style"`
|
25
|
*Transmission
|
48
|
*Transmission
|
|
@@ -29,9 +52,11 @@ type Message struct { |
|
@@ -29,9 +52,11 @@ type Message struct { |
29
|
IsOffline bool `json:"is_offline"`
|
52
|
IsOffline bool `json:"is_offline"`
|
30
|
MsgType string `json:"msgtype"`
|
53
|
MsgType string `json:"msgtype"`
|
31
|
}
|
54
|
}
|
|
|
55
|
+
|
|
|
56
|
+//透传
|
32
|
type Transmission struct {
|
57
|
type Transmission struct {
|
33
|
- TransmissionType bool `json:"transmission_type"`
|
|
|
34
|
- TransmissionContent string `json:"transmission_content,omitempty"`
|
58
|
+ TransmissionType bool `json:"transmission_type"` //收到消息是否立即启动应用,true为立即启动,false则广播等待启动,默认是否
|
|
|
59
|
+ TransmissionContent string `json:"transmission_content,omitempty"` //透传内容
|
35
|
DurationBegin string `json:"duration_begin,omitempty"`
|
60
|
DurationBegin string `json:"duration_begin,omitempty"`
|
36
|
DurationEnd string `json:"duration_end,omitempty"`
|
61
|
DurationEnd string `json:"duration_end,omitempty"`
|
37
|
}
|
62
|
}
|
|
@@ -47,16 +72,6 @@ func (o *Transmission) SetDuration(begin, end string) { |
|
@@ -47,16 +72,6 @@ func (o *Transmission) SetDuration(begin, end string) { |
47
|
o.DurationEnd = end
|
72
|
o.DurationEnd = end
|
48
|
}
|
73
|
}
|
49
|
|
74
|
|
50
|
-//1.新建单推
|
|
|
51
|
-func NewNotificationTemplate(options *push.Options) *NotificationTemplate {
|
|
|
52
|
- return &NotificationTemplate{
|
|
|
53
|
- Template: NewTemplate(options),
|
|
|
54
|
- Notification: &Notification{
|
|
|
55
|
- Style: (&Style{}).SetStyle0(options),
|
|
|
56
|
- Transmission: NewTransmission(options),
|
|
|
57
|
- },
|
|
|
58
|
- }
|
|
|
59
|
-}
|
|
|
60
|
func NewTemplate(options *push.Options) *Template {
|
75
|
func NewTemplate(options *push.Options) *Template {
|
61
|
return &Template{
|
76
|
return &Template{
|
62
|
Message: NewMessage(options),
|
77
|
Message: NewMessage(options),
|
|
@@ -67,10 +82,10 @@ func NewTemplate(options *push.Options) *Template { |
|
@@ -67,10 +82,10 @@ func NewTemplate(options *push.Options) *Template { |
67
|
func NewTransmission(options *push.Options) *Transmission {
|
82
|
func NewTransmission(options *push.Options) *Transmission {
|
68
|
t := &Transmission{}
|
83
|
t := &Transmission{}
|
69
|
if len(options.TransmissionContent) == 0 {
|
84
|
if len(options.TransmissionContent) == 0 {
|
70
|
- t.SetTransmissionType(false)
|
85
|
+ //t.SetTransmissionType(false)
|
71
|
return t
|
86
|
return t
|
72
|
}
|
87
|
}
|
73
|
- t.SetTransmissionType(true)
|
88
|
+ t.SetTransmissionType(false)
|
74
|
t.SetTransmissionContent(options.TransmissionContent)
|
89
|
t.SetTransmissionContent(options.TransmissionContent)
|
75
|
return t
|
90
|
return t
|
76
|
}
|
91
|
}
|
|
@@ -89,7 +104,8 @@ func resolveMsgType(msgType int) string { |
|
@@ -89,7 +104,8 @@ func resolveMsgType(msgType int) string { |
89
|
switch msgType {
|
104
|
switch msgType {
|
90
|
case push.SystemNotification:
|
105
|
case push.SystemNotification:
|
91
|
return "notification"
|
106
|
return "notification"
|
92
|
-
|
107
|
+ case push.Transmission:
|
|
|
108
|
+ return "transmission"
|
93
|
}
|
109
|
}
|
94
|
return "notification"
|
110
|
return "notification"
|
95
|
}
|
111
|
}
|
|
@@ -105,13 +121,16 @@ type Style struct { |
|
@@ -105,13 +121,16 @@ type Style struct { |
105
|
Logo string `json:"logo,omitempty"` //通知的图标名称,包含后缀名(需要在客户端开发时嵌入),如“push.png”
|
121
|
Logo string `json:"logo,omitempty"` //通知的图标名称,包含后缀名(需要在客户端开发时嵌入),如“push.png”
|
106
|
//IsRing bool `json:"is_ring"` //收到通知是否响铃:true响铃,false不响铃。默认响铃
|
122
|
//IsRing bool `json:"is_ring"` //收到通知是否响铃:true响铃,false不响铃。默认响铃
|
107
|
//IsVibrate bool `json:"is_vibrate"` //收到通知是否振动:true振动,false不振动。默认振动
|
123
|
//IsVibrate bool `json:"is_vibrate"` //收到通知是否振动:true振动,false不振动。默认振动
|
|
|
124
|
+ NotifyId int `json:"notify_id"` //需要被覆盖的消息已经增加了notifyId字段,用于实现下发消息的覆盖。新的消息使用相同的notifyId下发。
|
108
|
}
|
125
|
}
|
109
|
|
126
|
|
|
|
127
|
+//设置默认样式 0
|
110
|
func (s *Style) SetStyle0(options *push.Options) *Style {
|
128
|
func (s *Style) SetStyle0(options *push.Options) *Style {
|
111
|
s.Type = 0
|
129
|
s.Type = 0
|
112
|
s.Title = options.Title
|
130
|
s.Title = options.Title
|
113
|
s.Text = options.Content
|
131
|
s.Text = options.Content
|
114
|
s.Logo = "push.png" //TODO:设置Logo地址
|
132
|
s.Logo = "push.png" //TODO:设置Logo地址
|
|
|
133
|
+ s.NotifyId = 1
|
115
|
return s
|
134
|
return s
|
116
|
}
|
135
|
}
|
117
|
|
136
|
|
|
@@ -126,9 +145,47 @@ type AuthSignResponse struct { |
|
@@ -126,9 +145,47 @@ type AuthSignResponse struct { |
126
|
AuthToken string `json:"auth_token"`
|
145
|
AuthToken string `json:"auth_token"`
|
127
|
}
|
146
|
}
|
128
|
|
147
|
|
|
|
148
|
+//应答结果
|
129
|
type Result struct {
|
149
|
type Result struct {
|
130
|
Result string `json:"result"`
|
150
|
Result string `json:"result"`
|
131
|
TaskId string `json:"taskid"`
|
151
|
TaskId string `json:"taskid"`
|
132
|
Status string `json:"status"`
|
152
|
Status string `json:"status"`
|
133
|
Desc string `json:"desc"`
|
153
|
Desc string `json:"desc"`
|
134
|
}
|
154
|
}
|
|
|
155
|
+
|
|
|
156
|
+//透传附加的推送信息
|
|
|
157
|
+func NewPushInfo(options *push.Options) (v *PushInfo) {
|
|
|
158
|
+ v = &PushInfo{
|
|
|
159
|
+ Aps: NewAps(options),
|
|
|
160
|
+ }
|
|
|
161
|
+ return
|
|
|
162
|
+}
|
|
|
163
|
+func NewAps(options *push.Options) (v *Aps) {
|
|
|
164
|
+ v = &Aps{
|
|
|
165
|
+ Alert: NewAlert(options),
|
|
|
166
|
+ AutoBadge: "+1",
|
|
|
167
|
+ ContentAvailable: 1,
|
|
|
168
|
+ }
|
|
|
169
|
+ return
|
|
|
170
|
+}
|
|
|
171
|
+func NewAlert(options *push.Options) (v *Alert) {
|
|
|
172
|
+ v = &Alert{
|
|
|
173
|
+ Title: options.Title,
|
|
|
174
|
+ Body: options.Content,
|
|
|
175
|
+ }
|
|
|
176
|
+ return
|
|
|
177
|
+}
|
|
|
178
|
+
|
|
|
179
|
+type PushInfo struct {
|
|
|
180
|
+ Aps *Aps `json:"aps"`
|
|
|
181
|
+}
|
|
|
182
|
+type Aps struct {
|
|
|
183
|
+ Alert *Alert `json:"alert"`
|
|
|
184
|
+ AutoBadge string `json:"autoBadge"` //用于计算应用上面未读数字
|
|
|
185
|
+ ContentAvailable int `json:"content-available"` //推送直接带有透传数据 0:有通知栏消息 1:无通知栏消息
|
|
|
186
|
+ Payload string `json:"payload,omitempty"`
|
|
|
187
|
+}
|
|
|
188
|
+type Alert struct {
|
|
|
189
|
+ Title string `json:"title"`
|
|
|
190
|
+ Body string `json:"body"`
|
|
|
191
|
+} |