notification.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package apns2
  2. import (
  3. "encoding/json"
  4. )
  5. // NOTE these structs and "Table" refer to https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html
  6. // Payload payload.
  7. type Payload struct {
  8. Aps Aps `json:"aps"`
  9. URL string `json:"url"` // bilibili schedule
  10. TaskID string `json:"task_id"`
  11. Token string `json:"tid"`
  12. Image string `json:"image_url,omitempty"`
  13. }
  14. // Marshal marshals payload.
  15. func (p *Payload) Marshal() []byte {
  16. payload, _ := json.Marshal(p)
  17. return payload
  18. }
  19. // Aps Apple Push Service request meta.
  20. type Aps struct {
  21. // If this property is included, the system displays a standard alert or a banner, based on the user’s setting.
  22. // You can specify a string or a dictionary as the value of alert.
  23. // If you specify a string, it becomes the message text of an alert with two buttons: Close and View.
  24. // If the user taps View, the app launches.
  25. // If you specify a dictionary, refer to Table 5-2 for descriptions of the keys of this dictionary.
  26. // The JSON \U notation is not supported. Put the actual UTF-8 character in the alert text instead.
  27. Alert Alert `json:"alert,omitempty"`
  28. // The number to display as the badge of the app icon.
  29. // If this property is absent, the badge is not changed. To remove the badge, set the value of this property to 0.
  30. Badge int `json:"badge,omitempty"`
  31. // The name of a sound file in the app bundle or in the Library/Sounds folder of the app’s data container.
  32. // The sound in this file is played as an alert. If the sound file doesn’t exist or default is specified
  33. // as the value, the default alert sound is played. The audio must be in one of the audio data formats
  34. // that are compatible with system sounds; see Preparing Custom Alert Sounds for details.
  35. Sound string `json:"sound,omitempty"`
  36. // Provide this key with a value of 1 to indicate that new content is available.
  37. // Including this key and value means that when your app is launched in the background or resumed,
  38. // application:didReceiveRemoteNotification:fetchCompletionHandler: is called.
  39. ContentAvailable int `json:"content-available,omitempty"`
  40. // Provide this key with a string value that represents the identifier property of the
  41. // UIMutableUserNotificationCategory object you created to define custom actions.
  42. // To learn more about using custom actions, see Registering Your Actionable Notification Types.
  43. Category string `json:"category,omitempty"`
  44. // MutableContent .
  45. MutableContent int `json:"mutable-content,omitempty"`
  46. }
  47. // Alert alert message.
  48. type Alert struct {
  49. Title string `json:"title,omitempty"`
  50. Body string `json:"body,omitempty"`
  51. // could support any more other field
  52. }
  53. // Response reponse message.
  54. type Response struct {
  55. ApnsID string
  56. // Http status. (refer to Table 6-4)
  57. StatusCode int
  58. // The APNs error string indicating the reason for the notification failure (if
  59. // any). The error code is specified as a string. For a list of possible
  60. // values, see the Reason constants above.
  61. // If the notification was accepted, this value will be "".
  62. Reason string
  63. // If the value of StatusCode is 410, this is the last time at which APNs
  64. // confirmed that the device token was no longer valid for the topic.
  65. // Timestamp time.Time
  66. }