push

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package push 把中继收到的推送请求投给苹果推送服务。

用的是基于 p8 密钥的令牌鉴权(而不是证书):一把密钥可以同时用于开发与生产 环境,也不会像证书那样一年一换。令牌按苹果要求缓存复用,最多一小时换一次—— 每条推送都重签会被苹果限流。

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadPushRequest    = errors.New("bad push request")
	ErrPushNotConfigured = errors.New("push not configured")
	ErrBadDeviceToken    = errors.New("bad device token")
	ErrPushRejected      = errors.New("push rejected by Apple")
	ErrPushThrottled     = errors.New("push throttled by Apple")
	ErrPushTransport     = errors.New("push transport error")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	KeyPath  string // p8 私钥文件
	KeyID    string
	TeamID   string
	BundleID string
}

func LoadProfilesFile

func LoadProfilesFile(path string) ([]Config, error)

LoadProfilesFile 读可选的多档推送 JSON:[{"bundle_id":"...","key_path":"...","key_id":"...","team_id":"..."}]

func (Config) Enabled

func (c Config) Enabled() bool

type Result

type Result struct {
	StatusCode int
	Reason     string // Apple's verbatim reason string, empty on success
	ApnsID     string // Apple's apns-id, may be empty on failure
}

Result is the structured outcome of one APNs delivery attempt: 200 means accepted for delivery, which is NOT the same as shown on the phone (NSE decrypt, offline devices, user settings are all downstream).

type Router

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

Router 按 bundle id 选推送 profile。自建单租户只有一份默认配置。

func NewRouter

func NewRouter(fallback *Sender) *Router

func (*Router) Add

func (r *Router) Add(bundle string, sender *Sender)

func (*Router) Send

func (r *Router) Send(token, env, hostID, bundleID string, payload []byte) (Result, error)

func (*Router) SendFor

func (r *Router) SendFor(bundle, token, env, hostID string, payload []byte) (Result, error)

type Sender

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

func New

func New(config Config) (*Sender, error)

func (*Sender) Send

func (s *Sender) Send(token, env, hostID string, payload []byte) (Result, error)

Send delivers one push and returns the structured APNs outcome.

内容是加密的,所以推送本身必须带 mutable-content,让手机上的通知服务扩展 有机会在展示前把它解开;alert 里先放一句无信息量的占位,扩展解密成功后会 整条替换掉。用户关掉扩展或解密失败时,看到的就是这句占位——不理想,但绝不 会泄露内容,这个取舍是刻意的。

The returned Result only means accepted by APNs (200 = accepted), never that the phone displayed it. Callers must translate errors into receipts honestly: never treat "enqueued" as success, and never close the host connection because a push failed.

Jump to

Keyboard shortcuts

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