push

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// all audiences, all platforms
	ALL = "all"

	PLATFORM_IOS     = "ios"
	PLATFORM_ANDROID = "android"
	PLATFORM_WP      = "winphone"

	IosNotificationMaxSize = 2000

	MaxTimeToLive      = 10 * 24 * 60 * 60 // 10 天
	MaxBigPushDuration = 1400
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AndroidNotification

type AndroidNotification struct {
	Title       string `json:"title,omitempty"`
	BuilderId   int    `json:"builder_id,omitempty"`
	UriActivity string `json:"uri_activity"`
	UriAction   string `json:"uri_action"`
	Sound       string `json:"sound"`
	Intent      struct {
		Url string `json:"url"`
	} `json:"intent"`
	// contains filtered or unexported fields
}

Android 平台上的通知。

func NewAndroidNotification

func NewAndroidNotification(alert string) *AndroidNotification

func (*AndroidNotification) AddExtra

func (nc *AndroidNotification) AddExtra(key string, value interface{})

type Audience

type Audience struct {
	// contains filtered or unexported fields
}

推送设备对象,表示一条推送可以被推送到哪些设备列表。 确认推送设备对象,JPush 提供了多种方式,比如:别名、标签、注册ID、分群、广播等。

func NewAudience

func NewAudience() *Audience

func (*Audience) All

func (a *Audience) All()

func (*Audience) SetAlias

func (a *Audience) SetAlias(alias []string)

func (*Audience) SetRegistrationId

func (a *Audience) SetRegistrationId(ids []string)

func (*Audience) SetTag

func (a *Audience) SetTag(tags []string)

func (*Audience) SetTagAnd

func (a *Audience) SetTagAnd(tagAnds []string)

func (*Audience) Value

func (a *Audience) Value() interface{}

type IosNotification

type IosNotification struct {
	Sound            string `json:"sound,omitempty"`
	Badge            int    `json:"badge,omitempty"`
	ContentAvailable bool   `json:"content-available,omitempty"`
	Category         string `json:"category,omitempty"`
	// contains filtered or unexported fields
}

iOS 平台上 APNs 通知。

func NewIosNotification

func NewIosNotification(alert string) *IosNotification

func (*IosNotification) AddExtra

func (nc *IosNotification) AddExtra(key string, value interface{})

func (*IosNotification) Validate

func (in *IosNotification) Validate() error

APNs 协议定义通知长度为 2048 字节。 JPush 因为需要重新组包,并且考虑一点安全冗余, 要求"iOS":{ } 及大括号内的总体长度不超过:2000 个字节。

type Message

type Message struct {
	Content     string                 `json:"msg_content"`
	Title       string                 `json:"title,omitempty"`
	ContentType string                 `json:"content_type,omitempty"`
	Extras      map[string]interface{} `json:"extras,omitempty"`
}

应用内消息。或者称作:自定义消息,透传消息。 此部分内容不会展示到通知栏上,JPush SDK 收到消息内容后透传给 App。 收到消息后 App 需要自行处理。

func NewMessage

func NewMessage(content string) *Message

func (*Message) AddExtra

func (m *Message) AddExtra(key string, value interface{})

func (*Message) Validate

func (m *Message) Validate() error

type Notification

type Notification struct {
	Alert    string                `json:"alert,omitempty"`
	Android  *AndroidNotification  `json:"android,omitempty"`
	Ios      *IosNotification      `json:"ios,omitempty"`
	Winphone *WinphoneNotification `json:"winphone,omitempty"`
}

“通知”对象,是一条推送的实体内容对象之一(另一个是“消息”)

func NewNotification

func NewNotification(alert string) *Notification

func (*Notification) Validate

func (n *Notification) Validate() error

type Options

type Options struct {
	SendNo          int   `json:"sendno,omitempty"`
	TimeToLive      int   `json:"time_to_live,omitempty"`
	OverrideMsgId   int64 `json:"override_msg_id,omitempty"`
	ApnsProduction  bool  `json:"apns_production"`
	BigPushDuration int   `json:"big_push_duration,omitempty"`
}

推送可选项。

func NewOptions

func NewOptions() *Options

func (*Options) Validate

func (self *Options) Validate() error

可选项的校验没有那么严格,目前而言并没有出错的情况 只是针对某些值做一下范围限制

type Platform

type Platform struct {
	// contains filtered or unexported fields
}

func NewPlatform

func NewPlatform() *Platform

func (*Platform) Add

func (p *Platform) Add(platforms ...string) error

添加 platform,可选传参: "all", "ios", "android", "winphone"

func (*Platform) All

func (p *Platform) All()

func (*Platform) Value

func (p *Platform) Value() interface{}

如果有 "all",只会返回字符串 "all" 其他情况都是 []string{},包含具体的平台参数

type PushObject

type PushObject struct {
	Platform     *Platform     `json:"platform"`
	Audience     *Audience     `json:"audience"`
	Notification *Notification `json:"notification"`
	Message      *Message      `json:"message"`
	Options      *Options      `json:"options"`
}

一个推送对象,表示一条推送相关的所有信息。

func NewPushObject

func NewPushObject() *PushObject

func (*PushObject) MarshalJSON

func (po *PushObject) MarshalJSON() ([]byte, error)

实现 Marshaler interface

func (*PushObject) Validate

func (po *PushObject) Validate() error

type PushResult

type PushResult struct {
	common.ResponseBase

	// 成功时 msg_id 是 string 类型。。。
	// 失败时 msg_id 是 int 类型。。。
	MsgId  interface{} `json:"msg_id"`
	SendNo string      `json:"sendno"`
}

func (*PushResult) FromResponse

func (pr *PushResult) FromResponse(resp *http.Response) error

成功: {"sendno":"18", "msg_id":"1828256757"} 失败: {"msg_id": 1035959738, "error": {"message": "app_key does not exist", "code": 1008}}

func (*PushResult) String

func (pr *PushResult) String() string

type Validator

type Validator interface {
	Validate() error
}

type WinphoneNotification

type WinphoneNotification struct {
	Title    string `json:"title,omitempty"`
	OpenPage string `json:"_open_page,omitempty"`
	// contains filtered or unexported fields
}

Windows Phone 平台上的通知。

func NewWinphoneNotification

func NewWinphoneNotification(alert string) *WinphoneNotification

func (*WinphoneNotification) AddExtra

func (nc *WinphoneNotification) AddExtra(key string, value interface{})

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL