蛋蛋星球-制度模式
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

115 řádky
4.0 KiB

  1. package jpush
  2. import "encoding/json"
  3. type Platform string
  4. const (
  5. PlatformAndroid Platform = "android"
  6. PlatformIOS Platform = "ios"
  7. PlatformWinPhone Platform = "winphone"
  8. )
  9. type PushAudience struct {
  10. Tag []string `json:"tag,omitempty"`
  11. TagAnd []string `json:"tag_and,omitempty"`
  12. TagNot []string `json:"tag_not,omitempty"`
  13. Alias []string `json:"alias,omitempty"`
  14. RegistrationId []string `json:"registration_id,omitempty"`
  15. Segment []string `json:"segment,omitempty"`
  16. ABTest []string `json:"abtest,omitempty"`
  17. }
  18. type PushNotification struct {
  19. Alert string `json:"alert,omitempty"`
  20. Android *NotificationAndroid `json:"android,omitempty"`
  21. Hmos *NotificationHmos `json:"hmos,omitempty"`
  22. IOS *NotificationIOS `json:"ios,omitempty"`
  23. WinPhone *NotificationWinPhone `json:"winphone,omitempty"`
  24. }
  25. type NotificationAndroid struct {
  26. Alert string `json:"alert"`
  27. Title string `json:"title,omitempty"`
  28. BuilderId int `json:"builder_id,int,omitempty"`
  29. Priority int `json:"priority,omitempty"`
  30. Category string `json:"category,omitempty"`
  31. Style int `json:"style,int,omitempty"`
  32. AlertType int `json:"alert_type,int,omitempty"`
  33. BigText string `json:"big_text,omitempty"`
  34. Inbox map[string]interface{} `json:"inbox,omitempty"`
  35. BigPicPath string `json:"big_pic_path,omitempty"`
  36. Extras map[string]interface{} `json:"extras,omitempty"`
  37. }
  38. type NotificationHmos struct {
  39. Alert string `json:"alert"`
  40. Title string `json:"title"`
  41. }
  42. type NotificationIOS struct {
  43. Alert interface{} `json:"alert"`
  44. Sound string `json:"sound,omitempty"`
  45. Badge int `json:"badge,int,omitempty"`
  46. ContentAvailable bool `json:"content-available,omitempty"`
  47. MutableContent bool `json:"mutable-content,omitempty"`
  48. Category string `json:"category,omitempty"`
  49. Extras map[string]interface{} `json:"extras,omitempty"`
  50. }
  51. type NotificationWinPhone struct {
  52. Alert string `json:"alert"`
  53. Title string `json:"title,omitempty"`
  54. OpenPage string `json:"_open_page,omitempty"`
  55. Extras map[string]interface{} `json:"extras,omitempty"`
  56. }
  57. type PushMessage struct {
  58. MsgContent string `json:"msg_content"`
  59. Title string `json:"title,omitempty"`
  60. ContentType string `json:"content_type,omitempty"`
  61. Extras map[string]interface{} `json:"extras,omitempty"`
  62. }
  63. type SmsMessage struct {
  64. Content string `json:"content"`
  65. DelayTime int `json:"delay_time,int,omitempty"`
  66. }
  67. type PushOptions struct {
  68. SendNo int `json:"sendno,int,omitempty"`
  69. TimeToLive int `json:"time_to_live,int,omitempty"`
  70. OverrideMsgId int64 `json:"override_msg_id,int64,omitempty"`
  71. ApnsProduction bool `json:"apns_production"`
  72. ApnsCollapseId string `json:"apns_collapse_id,omitempty"`
  73. BigPushDuration int `json:"big_push_duration,int,omitempty"`
  74. }
  75. type PushRequest struct {
  76. Cid string `json:"cid,omitempty"`
  77. Platform Platform `json:"platform"`
  78. Audience interface{} `json:"audience,omitempty"`
  79. Notification *PushNotification `json:"notification,omitempty"`
  80. Message *PushMessage `json:"message,omitempty"`
  81. SmsMessage *SmsMessage `json:"sms_message,omitempty"`
  82. Options *PushOptions `json:"options,omitempty"`
  83. }
  84. type Response struct {
  85. data []byte
  86. }
  87. func (res *Response) Array() ([]interface{}, error) {
  88. list := make([]interface{}, 0)
  89. err := json.Unmarshal(res.data, &list)
  90. return list, err
  91. }
  92. func (res *Response) Map() (map[string]interface{}, error) {
  93. result := make(map[string]interface{})
  94. err := json.Unmarshal(res.data, &result)
  95. return result, err
  96. }
  97. func (res *Response) Bytes() []byte {
  98. return res.data
  99. }