huawei

package
v0.0.0-...-83adff0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ResponseCodeSuccess success code
	ResponseCodeSuccess = "80000000"
	// ResponseCodeSomeTokenInvalid some tokens failed
	ResponseCodeSomeTokenInvalid = "80100000"
	// ResponseCodeAllTokenInvalid all tokens failed
	ResponseCodeAllTokenInvalid = "80100002"
	// ResponseCodeAllTokenInvalidNew .
	ResponseCodeAllTokenInvalidNew = "80300007"
)
View Source
const (
	// MsgTypePassthrough 消息类型:透传
	MsgTypePassthrough = 1
	// MsgTypeNotification 消息类型:通知栏消息
	MsgTypeNotification = 3

	// ActionTypeCustom 动作类型:自定义
	ActionTypeCustom = 1
	// ActionTypeURL 动作类型:打开URL
	ActionTypeURL = 2
	// ActionTypeAPP 动作类型:打开APP
	ActionTypeAPP = 3

	// CallbackTokenUninstalled 应用被卸载了
	CallbackTokenUninstalled = 2
	// CallbackTokenNotApply 终端安装了该应用,但从未打开过,未申请token,所以不能展示
	CallbackTokenNotApply = 5
	// CallbackTokenInactive 非活跃设备,消息丢弃
	CallbackTokenInactive = 10
)

Variables

View Source
var (
	// ErrLimit .
	ErrLimit = errors.New("触发华为系统级流控")
)

Functions

This section is empty.

Types

type Access

type Access struct {
	AppID  string
	Token  string
	Expire int64
}

Access huawei access token.

func NewAccess

func NewAccess(clientID, clientSecret string) (a *Access, err error)

NewAccess get token.

func (*Access) IsExpired

func (a *Access) IsExpired() bool

IsExpired judge that whether privilige expired.

type Action

type Action struct {
	Type  int   `json:"type"`
	Param Param `json:"param"`
}

Action .

type Body

type Body struct {
	Content string `json:"content"`
	Title   string `json:"title"`
}

Body .

type Callback

type Callback struct {
	Statuses []*CallbackItem `json:"statuses"`
}

Callback 华为推送回执(回调)

type CallbackItem

type CallbackItem struct {
	BiTag     string `json:"biTag"`
	AppID     string `json:"appid"`
	Token     string `json:"token"`
	Status    int    `json:"status"`
	Timestamp int64  `json:"timestamp"`
}

CallbackItem http://developer.huawei.com/consumer/cn/service/hms/catalog/huaweipush_agent.html?page=hmssdk_huaweipush_devguide_server_agent#3.3 消息回执

type Client

type Client struct {
	Access     *Access
	HTTPClient *http.Client
	Stats      stat.Stat
	SDKCtx     string
	Package    string
}

Client huawei push http client.

func NewClient

func NewClient(pkg string, a *Access, timeout time.Duration) *Client

NewClient new huawei push HTTP client.

func (*Client) Push

func (c *Client) Push(payload *Message, tokens []string, expire time.Time) (response *Response, err error)

Push push notifications. access_token: 必选,使用OAuth2进行鉴权时的ACCESSTOKEN nsp_ts: 必选,服务请求时间戳,自GMT 时间 1970-1-1 0:0:0至今的秒数。如果传入的时间与服务器时间相 差5分钟以上,服务器可能会拒绝请求。 nsp_svc: 必选, 本接口固定为openpush.message.api.send device_token_list: 以半角逗号分隔的华为PUSHTOKEN列表,单次最多只是1000个 expire_time: 格式ISO 8601[6]:2013-06-03T17:30,采用本地时间精确到分钟 payload: 描述投递消息的JSON结构体,描述PUSH消息的:类型、内容、显示、点击动作、报表统计和扩展信 息。具体参考下面的详细说明。

type Ext

type Ext struct {
	BiTag     string              `json:"biTag"`
	Icon      string              `json:"icon"`
	Customize []map[string]string `json:"customize"`
}

Ext .

type Hps

type Hps struct {
	Msg Msg `json:"msg"`
	Ext Ext `json:"ext"`
}

Hps .

type InvalidTokenResponse

type InvalidTokenResponse struct {
	Success       int      `json:"success"`
	Failure       int      `json:"failure"`
	IllegalTokens []string `json:"illegal_tokens"`
}

InvalidTokenResponse invalid tokens info in the push response.

type Message

type Message struct {
	Hps Hps `json:"hps"`
}

Message request message.

func NewMessage

func NewMessage() *Message

NewMessage get message.

func (*Message) JSON

func (m *Message) JSON() (res string, err error)

JSON encode the message.

func (*Message) SetBiTag

func (m *Message) SetBiTag(tag string) *Message

SetBiTag set biTag.

func (*Message) SetContent

func (m *Message) SetContent(content string) *Message

SetContent sets content.

func (*Message) SetCustomize

func (m *Message) SetCustomize(key, val string) *Message

SetCustomize set ext info.

func (*Message) SetIcon

func (m *Message) SetIcon(url string) *Message

SetIcon sets icon.

func (*Message) SetIntent

func (m *Message) SetIntent(intent string) *Message

SetIntent sets intent.

func (*Message) SetMsgType

func (m *Message) SetMsgType(typ int) *Message

SetMsgType sets title.

func (*Message) SetPkg

func (m *Message) SetPkg(pkg string) *Message

SetPkg sets app package name.

func (*Message) SetTitle

func (m *Message) SetTitle(title string) *Message

SetTitle sets title.

type Msg

type Msg struct {
	Type   int    `json:"type"`
	Body   Body   `json:"body"`
	Action Action `json:"action"`
}

Msg .

type Param

type Param struct {
	Intent     string `json:"intent"`
	AppPkgName string `json:"appPkgName"`
}

Param .

type Response

type Response struct {
	Code      string `json:"code"`
	Msg       string `json:"msg"`
	Err       string `json:"error"`
	RequestID string `json:"requestId"`
}

Response push response.

Jump to

Keyboard shortcuts

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