-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush_option.go
79 lines (66 loc) · 2.15 KB
/
push_option.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
package jpushclient
import "encoding/json"
type Option struct {
SendNo int `json:"sendno,omitempty"` //推送序号
TimeToLive int `json:"time_to_live,omitempty"` //离线消息保留时长(秒)
OverrideMsgId int64 `json:"override_msg_id,omitempty"` //要覆盖的消息 ID
ApnsProduction bool `json:"apns_production,omitempty"` //APNs 是否生产环境
ApnsCollapseId string `json:"apns_collapse_id,omitempty"` //更新 iOS 通知的标识符
BigPushDuration int `json:"big_push_duration,omitempty"` //定速推送时长(分钟)
ThirdPartyChannel map[string]any `json:"third_party_channel,omitempty"` //推送请求下发通道
Classification int `json:"classification,omitempty"`
TargetEvent []string `json:"target_event,omitempty"`
}
func (op *Option) SetSendNo(no int) *Option {
op.SendNo = no
return op
}
func (op *Option) SetTimeToLive(timeToLive int) *Option {
op.TimeToLive = timeToLive
return op
}
func (op *Option) SetOverrideMsgId(id int64) *Option {
op.OverrideMsgId = id
return op
}
func (op *Option) SetApns(apns bool) *Option {
op.ApnsProduction = apns
return op
}
func (op *Option) SetBigPushDuration(bigPushDuration int) *Option {
op.BigPushDuration = bigPushDuration
return op
}
func (op *Option) SetApnsId(apnsCollapseId string) *Option {
op.ApnsCollapseId = apnsCollapseId
return op
}
func (op *Option) AddThirdPartyChannel(key string, value any) *Option {
if op.ThirdPartyChannel == nil {
op.ThirdPartyChannel = make(map[string]any)
}
op.ThirdPartyChannel[key] = value
return op
}
func (op *Option) SetClassification(classification int) *Option {
op.Classification = classification
return op
}
func (op *Option) SetTargetEvent(targetEvent []string) *Option {
op.TargetEvent = targetEvent
return op
}
func (op *Option) ToJson() (string, error) {
content, err := json.Marshal(op)
if err != nil {
return "", err
}
return string(content), nil
}
func (op *Option) ToBytes() ([]byte, error) {
content, err := json.Marshal(op)
if err != nil {
return nil, err
}
return content, nil
}