fix #31 support iOS expiration field

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-04-09 12:15:39 +08:00
parent e507877b45
commit 0bd6840f28
2 changed files with 18 additions and 8 deletions

View File

@ -7,6 +7,7 @@ import (
apns "github.com/sideshow/apns2"
"github.com/sideshow/apns2/certificate"
"github.com/sideshow/apns2/payload"
"time"
)
type ExtendJSON struct {
@ -59,6 +60,7 @@ type RequestPushNotification struct {
Notification gcm.Notification `json:"notification,omitempty"`
// iOS
Expiration int64 `json:"expiration,omitempty"`
ApnsID string `json:"apns_id,omitempty"`
Topic string `json:"topic,omitempty"`
Badge int `json:"badge,omitempty"`
@ -141,6 +143,10 @@ func GetIOSNotification(req RequestPushNotification) *apns.Notification {
notification.Topic = req.Topic
}
if req.Expiration > 0 {
notification.Expiration = time.Unix(req.Expiration, 0)
}
if len(req.Priority) > 0 && req.Priority == "normal" {
notification.Priority = apns.PriorityLow
}

View File

@ -8,6 +8,7 @@ import (
"log"
"os"
"testing"
"time"
)
func TestDisabledAndroidIosConf(t *testing.T) {
@ -59,12 +60,14 @@ func TestCorrectConf(t *testing.T) {
func TestIOSNotificationStructure(t *testing.T) {
var dat map[string]interface{}
var unix = time.Now().Unix()
test := "test"
message := "Welcome notification Server"
req := RequestPushNotification{
ApnsID: test,
Topic: test,
Expiration: time.Now().Unix(),
Priority: "normal",
Message: message,
Badge: 1,
@ -106,6 +109,7 @@ func TestIOSNotificationStructure(t *testing.T) {
assert.Equal(t, test, notification.ApnsID)
assert.Equal(t, test, notification.Topic)
assert.Equal(t, unix, notification.Expiration.Unix())
assert.Equal(t, ApnsPriorityLow, notification.Priority)
assert.Equal(t, message, alert)
assert.Equal(t, 1, int(badge))