payload.go 963 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package jpushclient
  2. import (
  3. "encoding/json"
  4. )
  5. type PayLoad struct {
  6. Platform interface{} `json:"platform"`
  7. Audience interface{} `json:"audience"`
  8. Notification interface{} `json:"notification,omitempty"`
  9. Message interface{} `json:"message,omitempty"`
  10. Options *Option `json:"options,omitempty"`
  11. }
  12. func NewPushPayLoad() *PayLoad {
  13. pl := &PayLoad{}
  14. o := &Option{}
  15. o.ApnsProduction = false
  16. pl.Options = o
  17. return pl
  18. }
  19. func (this *PayLoad) SetPlatform(pf *Platform) {
  20. this.Platform = pf.Os
  21. }
  22. func (this *PayLoad) SetAudience(ad *Audience) {
  23. this.Audience = ad.Object
  24. }
  25. func (this *PayLoad) SetOptions(o *Option) {
  26. this.Options = o
  27. }
  28. func (this *PayLoad) SetMessage(m *Message) {
  29. this.Message = m
  30. }
  31. func (this *PayLoad) SetNotice(notice *Notice) {
  32. this.Notification = notice
  33. }
  34. func (this *PayLoad) ToBytes() ([]byte, error) {
  35. content, err := json.Marshal(this)
  36. if err != nil {
  37. return nil, err
  38. }
  39. return content, nil
  40. }