commit
						0253415455
					
				| 
						 | 
				
			
			@ -1,10 +1,10 @@
 | 
			
		|||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	_ "github.com/google/go-gcm"
 | 
			
		||||
	apns "github.com/sideshow/apns2"
 | 
			
		||||
	"github.com/sideshow/apns2/certificate"
 | 
			
		||||
	"github.com/sideshow/apns2/payload"
 | 
			
		||||
	_ "github.com/google/go-gcm"
 | 
			
		||||
	"log"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -13,13 +13,25 @@ type ExtendJSON struct {
 | 
			
		|||
	Value string `json:"val"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type alert struct {
 | 
			
		||||
	Action       string   `json:"action,omitempty"`
 | 
			
		||||
	ActionLocKey string   `json:"action-loc-key,omitempty"`
 | 
			
		||||
	Body         string   `json:"body,omitempty"`
 | 
			
		||||
	LaunchImage  string   `json:"launch-image,omitempty"`
 | 
			
		||||
	LocArgs      []string `json:"loc-args,omitempty"`
 | 
			
		||||
	LocKey       string   `json:"loc-key,omitempty"`
 | 
			
		||||
	Title        string   `json:"title,omitempty"`
 | 
			
		||||
	TitleLocArgs []string `json:"title-loc-args,omitempty"`
 | 
			
		||||
	TitleLocKey  string   `json:"title-loc-key,omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type RequestPushNotification struct {
 | 
			
		||||
	// Common
 | 
			
		||||
	Tokens   []string `json:"tokens" binding:"required"`
 | 
			
		||||
	Platform int      `json:"platform" binding:"required"`
 | 
			
		||||
	Message  string   `json:"message" binding:"required"`
 | 
			
		||||
	Priority string   `json:"priority,omitempty"`
 | 
			
		||||
	ContentAvailable bool `json:"content_available,omitempty"`
 | 
			
		||||
	Tokens           []string `json:"tokens" binding:"required"`
 | 
			
		||||
	Platform         int      `json:"platform" binding:"required"`
 | 
			
		||||
	Message          string   `json:"message" binding:"required"`
 | 
			
		||||
	Priority         string   `json:"priority,omitempty"`
 | 
			
		||||
	ContentAvailable bool     `json:"content_available,omitempty"`
 | 
			
		||||
 | 
			
		||||
	// Android
 | 
			
		||||
	CollapseKey    string `json:"collapse_key,omitempty"`
 | 
			
		||||
| 
						 | 
				
			
			@ -27,13 +39,16 @@ type RequestPushNotification struct {
 | 
			
		|||
	TimeToLive     int    `json:"time_to_live,omitempty"`
 | 
			
		||||
 | 
			
		||||
	// iOS
 | 
			
		||||
	ApnsID string       `json:"apns_id,omitempty"`
 | 
			
		||||
	Topic  string       `json:"topic,omitempty"`
 | 
			
		||||
	Badge  int          `json:"badge,omitempty"`
 | 
			
		||||
	Sound  string       `json:"sound,omitempty"`
 | 
			
		||||
	Expiry int          `json:"expiry,omitempty"`
 | 
			
		||||
	Retry  int          `json:"retry,omitempty"`
 | 
			
		||||
	Extend []ExtendJSON `json:"extend,omitempty"`
 | 
			
		||||
	ApnsID   string       `json:"apns_id,omitempty"`
 | 
			
		||||
	Topic    string       `json:"topic,omitempty"`
 | 
			
		||||
	Badge    int          `json:"badge,omitempty"`
 | 
			
		||||
	Sound    string       `json:"sound,omitempty"`
 | 
			
		||||
	Expiry   int          `json:"expiry,omitempty"`
 | 
			
		||||
	Retry    int          `json:"retry,omitempty"`
 | 
			
		||||
	Category string       `json:"category,omitempty"`
 | 
			
		||||
	URLArgs  []string     `json:"url-args,omitempty"`
 | 
			
		||||
	Extend   []ExtendJSON `json:"extend,omitempty"`
 | 
			
		||||
	Alert    alert        `json:"alert,omitempty"`
 | 
			
		||||
	// meta
 | 
			
		||||
	IDs []uint64 `json:"seq_id,omitempty"`
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -77,7 +92,7 @@ func pushNotificationIos(req RequestPushNotification, client *apns.Client) bool
 | 
			
		|||
			notification.Topic = req.Topic
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if len(req.Priority) > 0 && req.Priority == "low" {
 | 
			
		||||
		if len(req.Priority) > 0 && req.Priority == "normal" {
 | 
			
		||||
			notification.Priority = apns.PriorityLow
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -101,6 +116,50 @@ func pushNotificationIos(req RequestPushNotification, client *apns.Client) bool
 | 
			
		|||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Alert dictionary
 | 
			
		||||
 | 
			
		||||
		if len(req.Alert.Title) > 0 {
 | 
			
		||||
			payload.AlertTitle(req.Alert.Title)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if len(req.Alert.TitleLocKey) > 0 {
 | 
			
		||||
			payload.AlertTitleLocKey(req.Alert.TitleLocKey)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if len(req.Alert.LocArgs) > 0 {
 | 
			
		||||
			payload.AlertTitleLocArgs(req.Alert.LocArgs)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if len(req.Alert.Body) > 0 {
 | 
			
		||||
			payload.AlertBody(req.Alert.Body)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if len(req.Alert.LaunchImage) > 0 {
 | 
			
		||||
			payload.AlertLaunchImage(req.Alert.LaunchImage)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if len(req.Alert.LocKey) > 0 {
 | 
			
		||||
			payload.AlertLocKey(req.Alert.LocKey)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if len(req.Alert.Action) > 0 {
 | 
			
		||||
			payload.AlertAction(req.Alert.Action)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if len(req.Alert.ActionLocKey) > 0 {
 | 
			
		||||
			payload.AlertActionLocKey(req.Alert.ActionLocKey)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// General
 | 
			
		||||
 | 
			
		||||
		if len(req.Category) > 0 {
 | 
			
		||||
			payload.Category(req.Category)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if len(req.URLArgs) > 0 {
 | 
			
		||||
			payload.URLArgs(req.URLArgs)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		notification.Payload = payload
 | 
			
		||||
 | 
			
		||||
		// send ios notification
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,8 +2,8 @@ package main
 | 
			
		|||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"runtime"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"runtime"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func PrintGoPushVersion() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue