notice.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package jpush
  2. const (
  3. // AndroidAlertTypeAll 全开
  4. AndroidAlertTypeAll = -1
  5. // AndroidAlertTypeNone 全关
  6. AndroidAlertTypeNone = 0
  7. // AndroidAlertTypeSound 开声音
  8. AndroidAlertTypeSound = 1
  9. // AndroidAlertTypeVibrate 开振动
  10. AndroidAlertTypeVibrate = 2
  11. // AndroidAlertTypeLight 开呼吸灯
  12. AndroidAlertTypeLight = 4
  13. // AndroidStyleDefault 默认通知栏样式
  14. AndroidStyleDefault = 0
  15. // AndroidStyleBigTxt big_text 字段大文本的形式展示
  16. AndroidStyleBigTxt = 1
  17. // AndroidStyleInbox inbox 字段 json 的每个 key 对应的 value 会被当作文本条目逐条展示
  18. AndroidStyleInbox = 2
  19. // AndroidStylePic big_pic_path 字段的图片URL展示成图片
  20. AndroidStylePic = 3
  21. )
  22. // Notice .
  23. type Notice struct {
  24. Alert string `json:"alert,omitempty"`
  25. Android *AndroidNotice `json:"android,omitempty"`
  26. IOS *IOSNotice `json:"ios,omitempty"`
  27. WINPhone *WinPhoneNotice `json:"winphone,omitempty"`
  28. }
  29. // AndroidNotice .
  30. type AndroidNotice struct {
  31. Alert string `json:"alert"`
  32. Title string `json:"title,omitempty"`
  33. AlertType int `json:"alert_type"`
  34. BuilderID int `json:"builder_id,omitempty"`
  35. Style int `json:"style,omitempty"`
  36. BigPicPath string `json:"big_pic_path,omitempty"`
  37. Extras map[string]interface{} `json:"extras,omitempty"`
  38. }
  39. // SetPic sets Android notice pic.
  40. func (an *AndroidNotice) SetPic(pic string) {
  41. an.Style = AndroidStylePic
  42. an.BigPicPath = pic
  43. }
  44. // IOSNotice .
  45. type IOSNotice struct {
  46. Alert interface{} `json:"alert"`
  47. Sound string `json:"sound,omitempty"`
  48. Badge string `json:"badge,omitempty"`
  49. ContentAvailable bool `json:"content-available,omitempty"`
  50. MutableContent bool `json:"mutable-content,omitempty"`
  51. Category string `json:"category,omitempty"`
  52. Extras map[string]interface{} `json:"extras,omitempty"`
  53. }
  54. // WinPhoneNotice .
  55. type WinPhoneNotice struct {
  56. Alert string `json:"alert"`
  57. Title string `json:"title,omitempty"`
  58. OpenPage string `json:"_open_page,omitempty"`
  59. Extras map[string]interface{} `json:"extras,omitempty"`
  60. }
  61. // SetAlert .
  62. func (n *Notice) SetAlert(alert string) {
  63. n.Alert = alert
  64. }
  65. // SetAndroidNotice .
  66. func (n *Notice) SetAndroidNotice(an *AndroidNotice) {
  67. n.Android = an
  68. }
  69. // SetIOSNotice .
  70. func (n *Notice) SetIOSNotice(in *IOSNotice) {
  71. n.IOS = in
  72. }
  73. // SetWinPhoneNotice .
  74. func (n *Notice) SetWinPhoneNotice(wn *WinPhoneNotice) {
  75. n.WINPhone = wn
  76. }