Merge pull request #33 from appleboy/ios
fix #31 support iOS expiration field
This commit is contained in:
commit
746627685c
|
@ -7,6 +7,7 @@ import (
|
||||||
apns "github.com/sideshow/apns2"
|
apns "github.com/sideshow/apns2"
|
||||||
"github.com/sideshow/apns2/certificate"
|
"github.com/sideshow/apns2/certificate"
|
||||||
"github.com/sideshow/apns2/payload"
|
"github.com/sideshow/apns2/payload"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ExtendJSON struct {
|
type ExtendJSON struct {
|
||||||
|
@ -59,6 +60,7 @@ type RequestPushNotification struct {
|
||||||
Notification gcm.Notification `json:"notification,omitempty"`
|
Notification gcm.Notification `json:"notification,omitempty"`
|
||||||
|
|
||||||
// iOS
|
// iOS
|
||||||
|
Expiration int64 `json:"expiration,omitempty"`
|
||||||
ApnsID string `json:"apns_id,omitempty"`
|
ApnsID string `json:"apns_id,omitempty"`
|
||||||
Topic string `json:"topic,omitempty"`
|
Topic string `json:"topic,omitempty"`
|
||||||
Badge int `json:"badge,omitempty"`
|
Badge int `json:"badge,omitempty"`
|
||||||
|
@ -141,6 +143,10 @@ func GetIOSNotification(req RequestPushNotification) *apns.Notification {
|
||||||
notification.Topic = req.Topic
|
notification.Topic = req.Topic
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if req.Expiration > 0 {
|
||||||
|
notification.Expiration = time.Unix(req.Expiration, 0)
|
||||||
|
}
|
||||||
|
|
||||||
if len(req.Priority) > 0 && req.Priority == "normal" {
|
if len(req.Priority) > 0 && req.Priority == "normal" {
|
||||||
notification.Priority = apns.PriorityLow
|
notification.Priority = apns.PriorityLow
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDisabledAndroidIosConf(t *testing.T) {
|
func TestDisabledAndroidIosConf(t *testing.T) {
|
||||||
|
@ -59,12 +60,14 @@ func TestCorrectConf(t *testing.T) {
|
||||||
|
|
||||||
func TestIOSNotificationStructure(t *testing.T) {
|
func TestIOSNotificationStructure(t *testing.T) {
|
||||||
var dat map[string]interface{}
|
var dat map[string]interface{}
|
||||||
|
var unix = time.Now().Unix()
|
||||||
|
|
||||||
test := "test"
|
test := "test"
|
||||||
message := "Welcome notification Server"
|
message := "Welcome notification Server"
|
||||||
req := RequestPushNotification{
|
req := RequestPushNotification{
|
||||||
ApnsID: test,
|
ApnsID: test,
|
||||||
Topic: test,
|
Topic: test,
|
||||||
|
Expiration: time.Now().Unix(),
|
||||||
Priority: "normal",
|
Priority: "normal",
|
||||||
Message: message,
|
Message: message,
|
||||||
Badge: 1,
|
Badge: 1,
|
||||||
|
@ -106,6 +109,7 @@ func TestIOSNotificationStructure(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, test, notification.ApnsID)
|
assert.Equal(t, test, notification.ApnsID)
|
||||||
assert.Equal(t, test, notification.Topic)
|
assert.Equal(t, test, notification.Topic)
|
||||||
|
assert.Equal(t, unix, notification.Expiration.Unix())
|
||||||
assert.Equal(t, ApnsPriorityLow, notification.Priority)
|
assert.Equal(t, ApnsPriorityLow, notification.Priority)
|
||||||
assert.Equal(t, message, alert)
|
assert.Equal(t, message, alert)
|
||||||
assert.Equal(t, 1, int(badge))
|
assert.Equal(t, 1, int(badge))
|
||||||
|
|
Loading…
Reference in New Issue