@@ -2,7 +2,6 @@ package xiaomipush
22
33import (
44 "encoding/json"
5- "fmt"
65 "strconv"
76 "time"
87)
@@ -25,21 +24,6 @@ const (
2524 MaxTimeToLive = time .Hour * 24 * 7 * 2
2625)
2726
28- func NewAndroidMessage (title , description string ) * Message {
29- return & Message {
30- UniqueID : "" ,
31- Payload : "" ,
32- Title : title ,
33- Description : description ,
34- PassThrough : 0 ,
35- NotifyType : - 1 , // default notify type
36- TimeToLive : 0 ,
37- TimeToSend : 0 ,
38- NotifyID : 0 ,
39- Extra : make (map [string ]string ),
40- }
41- }
42-
4327func (m * Message ) SetUniqueID (uniqueID string ) * Message {
4428 m .UniqueID = uniqueID
4529 return m
@@ -115,10 +99,61 @@ func (m *Message) JSON() []byte {
11599 if err != nil {
116100 panic (err )
117101 }
118- fmt .Println ("m" , string (bytes ))
119102 return bytes
120103}
121104
105+ //-----------------------------------------------------------------------------------//
106+ // 发送给Android设备的Message对象
107+ func NewAndroidMessage (title , description string ) * Message {
108+ return & Message {
109+ UniqueID : "" ,
110+ Payload : "" ,
111+ Title : title ,
112+ Description : description ,
113+ PassThrough : 0 ,
114+ NotifyType : - 1 , // default notify type
115+ TimeToLive : 0 ,
116+ TimeToSend : 0 ,
117+ NotifyID : 0 ,
118+ Extra : make (map [string ]string ),
119+ }
120+ }
121+
122+ //-----------------------------------------------------------------------------------//
123+ // 发送给IOS设备的Message对象
124+ func NewIOSMessage (description string ) * Message {
125+ return & Message {
126+ UniqueID : "" ,
127+ Payload : "" ,
128+ Title : "" ,
129+ Description : description ,
130+ PassThrough : 0 ,
131+ NotifyType : - 1 , // default notify type
132+ TimeToLive : 0 ,
133+ TimeToSend : 0 ,
134+ NotifyID : 0 ,
135+ Extra : make (map [string ]string ),
136+ }
137+ }
138+
139+ // 可选项,自定义通知数字角标。
140+ func (i * Message ) SetBadge (badge int64 ) * Message {
141+ i .Extra ["badge" ] = strconv .FormatInt (badge , 10 )
142+ return i
143+ }
144+
145+ // 可选项,iOS8推送消息快速回复类别。
146+ func (i * Message ) SetCategory (category string ) * Message {
147+ i .Extra ["category" ] = category
148+ return i
149+ }
150+
151+ // 可选项,自定义消息铃声。
152+ func (i * Message ) SetSoundURL (soundURL string ) * Message {
153+ i .Extra ["sound_url" ] = soundURL
154+ return i
155+ }
156+
122157//-----------------------------------------------------------------------------------//
123158// TargetedMessage封装了MiPush推送服务系统中的消息Message对象,和该Message对象所要发送到的目标。
124159
@@ -161,38 +196,3 @@ func (tm *TargetedMessage) JSON() []byte {
161196 }
162197 return bytes
163198}
164-
165- //-----------------------------------------------------------------------------------//
166- // 发送给IOS设备的Message对象
167- func NewIOSMessage (description string ) * Message {
168- return & Message {
169- UniqueID : "" ,
170- Payload : "" ,
171- Title : "" ,
172- Description : description ,
173- PassThrough : 0 ,
174- NotifyType : - 1 , // default notify type
175- TimeToLive : 0 ,
176- TimeToSend : 0 ,
177- NotifyID : 0 ,
178- Extra : make (map [string ]string ),
179- }
180- }
181-
182- // 可选项,自定义通知数字角标。
183- func (i * Message ) SetBadge (badge int64 ) * Message {
184- i .Extra ["badge" ] = strconv .FormatInt (badge , 10 )
185- return i
186- }
187-
188- // 可选项,iOS8推送消息快速回复类别。
189- func (i * Message ) SetCategory (category string ) * Message {
190- i .Extra ["category" ] = category
191- return i
192- }
193-
194- // 可选项,自定义消息铃声。
195- func (i * Message ) SetSoundURL (soundURL string ) * Message {
196- i .Extra ["sound_url" ] = soundURL
197- return i
198- }
0 commit comments