forked from Scorpio69t/jpush-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayload.go
65 lines (56 loc) · 1.87 KB
/
payload.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
package jpush
import "encoding/json"
type PayLoad struct {
Platform *Platform `json:"platform"` // 平台
Audience *Audience `json:"audience"` // 推送目标
Notification *Notification `json:"notification,omitempty"` // 推送内容
Message *Message `json:"message,omitempty"` // 推送内容
Options *Options `json:"options,omitempty"` // 推送选项
Cid string `json:"cid,omitempty"` // 推送唯一标识符
}
// NewPayLoad 创建一个新的推送对象
func NewPayLoad() *PayLoad {
p := &PayLoad{}
p.Options = &Options{}
p.Options.ApnsProduction = false
return p
}
// SetPlatform 设置平台
func (p *PayLoad) SetPlatform(platform *Platform) {
p.Platform = platform
}
// SetAudience 设置推送目标
func (p *PayLoad) SetAudience(audience *Audience) {
p.Audience = audience
}
// SetNotification 设置推送内容
func (p *PayLoad) SetNotification(notification *Notification) {
p.Notification = notification
}
// SetMessage 设置推送内容
func (p *PayLoad) SetMessage(message *Message) {
p.Message = message
}
// SetOptions 设置推送选项
func (p *PayLoad) SetOptions(options *Options) {
p.Options = options
}
// Bytes 返回推送对象的json字节数组
func (p *PayLoad) Bytes() ([]byte, error) {
payload := struct {
Platform interface{} `json:"platform"`
Audience interface{} `json:"audience"`
Notification *Notification `json:"notification,omitempty"`
Message *Message `json:"message,omitempty"`
Options *Options `json:"options,omitempty"`
Cid string `json:"cid,omitempty"`
}{
Platform: p.Platform.Interface(),
Audience: p.Audience.Interface(),
Notification: p.Notification,
Message: p.Message,
Options: p.Options,
Cid: p.Cid,
}
return json.Marshal(payload)
}