1 Star 0 Fork 0

liuliang/jpush-api-golang-client

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
payload.go 1.87 KB
一键复制 编辑 原始数据 按行查看 历史
liuliang 提交于 2022-11-09 13:44 +08:00 . init
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)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dashiqiao/jpush-api-golang-client.git
git@gitee.com:dashiqiao/jpush-api-golang-client.git
dashiqiao
jpush-api-golang-client
jpush-api-golang-client
v1.0.1

搜索帮助