push

package module
v0.0.0-...-8b0e277 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2016 License: BSD-3-Clause Imports: 12 Imported by: 0

README

BaiduPushSDK-golang

百度云推送服务器端go语言版本SDK,封装了Rest api 3.0,包含目前开放的所有API,详见:http://push.baidu.com/doc/restapi/restapi

安装

go get github.com/ChangjunZhao/BaiduPushSDK-golang

使用方法

推送消息到客户端
package main

import (
	"fmt"
	"github.com/ChangjunZhao/BaiduPushSDK-golang"
)

func main() {
	// 新建客户端
	client := push.NewClient("Your API Key","Your Secret Key")
	// 构造请求
	request := &push.PushMsgToSingleDeviceRequest{ChannelId: "your channel_id", MsgType: 0, Message: "测试消息"}

	// 推送消息到指定客户端
	response, err := client.PushMsgToSingleDevice(*request)
	if err == nil {
		fmt.Println(response.MsgId)
	} else {
		fmt.Println(err)
	}
}
推送系统通知到客户端
package main

import (
	"encoding/json"
	"fmt"
	"github.com/ChangjunZhao/BaiduPushSDK-golang"
)

func main() {
	// 新建客户端
	client := push.NewClient("Your API Key","Your Secret Key")
	// 推送通知到指定客户端
	notification := &push.AndroidNotification{Title: "测试通知", Description: "测试通知描述", NotificationBuilderId: 0, NotificationBasicStyle: 7, OpenType: 1, Url: "http://www.tsuru.cn"}
	message, _ := json.Marshal(notification)
	request := &push.PushMsgToSingleDeviceRequest{ChannelId: "your channel_id", MsgType: 1, Message: string(message)}
	response, err := client.PushMsgToSingleDevice(*request)
	if err == nil {
		fmt.Println(response.MsgId)
	} else {
		fmt.Println(err)
	}
}

如使用中发现问题,请通过github提交,我们会尽快完善修复,或直接pull requests

Documentation

Overview

Copyright 2015 Beijing Venusource Tech.Co.Ltd. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

一些常量

Copyright 2015 Beijing Venusource Tech.Co.Ltd. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

封装了http调用相关的一些方法

Copyright 2015 Beijing Venusource Tech.Co.Ltd. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

百度云推送 SDK go语言版本

Copyright 2015 Beijing Venusource Tech.Co.Ltd. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Rest Api请求参数构造

Copyright 2015 Beijing Venusource Tech.Co.Ltd. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Rest Api返回值封装

Index

Constants

View Source
const (
	API_SERVER = "http://api.tuisong.baidu.com/rest/3.0/"
)

Variables

This section is empty.

Functions

func CallApiServer

func CallApiServer(httpMethod string, server string, class string, method string, params *OrderedParams, secretkey string, i interface{}) error

调用API

Types

type AddDevicesToTagJSONResponse

type AddDevicesToTagJSONResponse struct {
	RequestId               int                     `json:"request_id"`
	AddDevicesToTagResponse AddDevicesToTagResponse `json:"response_params"`
}

type AddDevicesToTagRequest

type AddDevicesToTagRequest struct {
	TagName    string
	ChannelIds string
}

func (*AddDevicesToTagRequest) AddToParams

func (r *AddDevicesToTagRequest) AddToParams(params *OrderedParams) *OrderedParams

type AddDevicesToTagResponse

type AddDevicesToTagResponse struct {
	DevicesInfoAfterAdded []DeviceInfo `json:"devices"`
}

type AndroidNotification

type AndroidNotification struct {
	Title                  string `json:"title"`                    //通知标题,可以为空;如果为空则设为appid对应的应用名;
	Description            string `json:"description"`              //通知文本内容,不能为空;
	NotificationBuilderId  int    `json:"notification_builder_id"`  //android客户端自定义通知样式,如果没有设置默认为0;
	NotificationBasicStyle int    `json:"notification_basic_style"` //只有notification_builder_id为0时有效,可以设置通知的基本样式包括(响铃:0x04;振动:0x02;可清除:0x01;),这是一个flag整形,每一位代表一种样式;
	OpenType               int    `json:"open_type"`                //点击通知后的行为(1:打开Url; 2:自定义行为;3:默认打开应用;)
	Url                    string `json:"url"`                      //需要打开的Url地址,open_type为1时才有效;
	//open_type为2时才有效,Android端SDK会把pkg_content字符串转换成Android Intent,
	//通过该Intent打开对应app组件,所以pkg_content字符串格式必须遵循Intent uri格式,最简单的方法可以通过Intent方法toURI()获取
	PkgContent    string                 `json:"pkg_content"`
	CustomContent map[string]interface{} `json:"custom_content"` //自定义内容,键值对,Json对象形式(可选);在android客户端,这些键值对将以Intent中的extra进行传递。
}

Android通知消息,详见:http://push.baidu.com/doc/restapi/msg_struct

type BaiduPushClient

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

调用API的Client

func NewClient

func NewClient(apikey string, secretKey string) *BaiduPushClient

创建新的客户端

使用方法:

c = NewClient("API Key","Secret Key")

func (*BaiduPushClient) AddDevicesToTag

func (c *BaiduPushClient) AddDevicesToTag(request AddDevicesToTagRequest) (*AddDevicesToTagResponse, error)

添加设备到标签组

func (*BaiduPushClient) CancelTimerJob

func (c *BaiduPushClient) CancelTimerJob(timerId string) (*CancelTimerJobResponse, error)

取消定时任务

func (*BaiduPushClient) CreateTag

func (c *BaiduPushClient) CreateTag(request CreateTagRequest) (*CreateTagResponse, error)

创建标签组

func (*BaiduPushClient) Debug

func (c *BaiduPushClient) Debug(enabled bool)

func (*BaiduPushClient) DeleteDevicesFromTag

将设备从标签组中移除

func (*BaiduPushClient) DeleteTag

func (c *BaiduPushClient) DeleteTag(request DeleteTagRequest) (*DeleteTagResponse, error)

删除标签组

func (*BaiduPushClient) PushBatchUniMsg

func (c *BaiduPushClient) PushBatchUniMsg(request PushBatchUniMsgRequest) (*PushBatchUniMsgResponse, error)

推送消息到给定的一组设备(批量单播)

func (*BaiduPushClient) PushMsgToAllDevice

func (c *BaiduPushClient) PushMsgToAllDevice(request PushMsgToAllRequest) (*PushMsgToAllResponse, error)

推送广播消息

func (*BaiduPushClient) PushMsgToSingleDevice

推送消息到单台设备

func (*BaiduPushClient) PushMsgToTag

func (c *BaiduPushClient) PushMsgToTag(request PushMsgToTagRequest) (*PushMsgToTagResponse, error)

推送组播消息

func (*BaiduPushClient) QueryDeviceNumInTag

查询标签组设备数量

func (*BaiduPushClient) QueryMsgStatus

func (c *BaiduPushClient) QueryMsgStatus(request QueryMsgStatusRequest) (*QueryMsgStatusResponse, error)

查询消息的发送状态

func (*BaiduPushClient) QueryStatisticDevice

func (c *BaiduPushClient) QueryStatisticDevice() (*QueryStatisticDeviceResponse, error)

当前应用的设备统计信息

func (*BaiduPushClient) QueryStatisticTopic

查询分类主题统计信息

func (*BaiduPushClient) QueryTags

func (c *BaiduPushClient) QueryTags(request QueryTagsRequest) (*QueryTagsResponse, error)

查询标签组列表

func (*BaiduPushClient) QueryTimerList

func (c *BaiduPushClient) QueryTimerList(request QueryTimerListRequest) (*QueryTimerListResponse, error)

查询定时任务列表

func (*BaiduPushClient) QueryTimerRecords

func (c *BaiduPushClient) QueryTimerRecords(request QueryTimerRecordsRequest) (*QueryTimerRecordsResponse, error)

查询定时消息的发送记录

func (*BaiduPushClient) QueryTopicList

func (c *BaiduPushClient) QueryTopicList(request QueryTopicListRequest) (*QueryTopicListResponse, error)

查询分类主题列表

func (*BaiduPushClient) QueryTopicRecords

func (c *BaiduPushClient) QueryTopicRecords(request QueryTopicRecordsRequest) (*QueryTopicRecordsResponse, error)

查询指定分类主题的发送记录

type CancelTimerJobResponse

type CancelTimerJobResponse struct {
	RequestId int `json:"request_id"`
}

type CreateTagJSONResponse

type CreateTagJSONResponse struct {
	RequestId         int               `json:"request_id"`
	CreateTagResponse CreateTagResponse `json:"response_params"`
}

type CreateTagRequest

type CreateTagRequest struct {
	TagName string
}

func (*CreateTagRequest) AddToParams

func (r *CreateTagRequest) AddToParams(params *OrderedParams) *OrderedParams

type CreateTagResponse

type CreateTagResponse struct {
	TagName string `json:"tag"`
	Result  int    `json:"result"`
}

type DeleteDevicesFromTagJSONResponse

type DeleteDevicesFromTagJSONResponse struct {
	RequestId                    int                          `json:"request_id"`
	DeleteDevicesFromTagResponse DeleteDevicesFromTagResponse `json:"response_params"`
}

type DeleteDevicesFromTagRequest

type DeleteDevicesFromTagRequest struct {
	TagName    string
	ChannelIds string
}

func (*DeleteDevicesFromTagRequest) AddToParams

func (r *DeleteDevicesFromTagRequest) AddToParams(params *OrderedParams) *OrderedParams

type DeleteDevicesFromTagResponse

type DeleteDevicesFromTagResponse struct {
	DevicesInfoAfterDel []DeviceInfo `json:"devices"`
}

type DeleteTagJSONResponse

type DeleteTagJSONResponse struct {
	RequestId         int               `json:"request_id"`
	DeleteTagResponse DeleteTagResponse `json:"response_params"`
}

type DeleteTagRequest

type DeleteTagRequest struct {
	TagName string
}

func (*DeleteTagRequest) AddToParams

func (r *DeleteTagRequest) AddToParams(params *OrderedParams) *OrderedParams

type DeleteTagResponse

type DeleteTagResponse struct {
	TagName string `json:"tag"`
	Result  int    `json:"result"`
}

type DeviceInfo

type DeviceInfo struct {
	ChannelId string `json:"channel_id"`
	Result    int    `json:"result"`
}

type DeviceStatUnit

type DeviceStatUnit struct {
	NewTerm    int `json:"new_term"`
	DelTerm    int `json:"del_term"`
	OnlineTerm int `json:"online_term"`
	AddupTerm  int `json:"addup_term"`
	TotalTerm  int `json:"total_term"`
}

type ErrorResponse

type ErrorResponse struct {
	RequestId int    `json:"request_id"` //请求ID
	Code      int    `json:"error_code"` //服务端错误码
	Message   string `json:"error_msg"`  //错误消息
}

服务器端错误返回信息

详见:http://push.baidu.com/doc/restapi/error_code

type MsgSendInfo

type MsgSendInfo struct {
	MsgId        string `json:"msg_id"`
	MsgStatus    int    `json:"status"`
	SendTime     int64  `json:"send_time"`
	SuccessCount int    `json:"success"`
}

type OrderedParams

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

排序后的参数列表

func NewOrderedParams

func NewOrderedParams() *OrderedParams

func (*OrderedParams) Add

func (o *OrderedParams) Add(key, value string)

func (*OrderedParams) AddUnescaped

func (o *OrderedParams) AddUnescaped(key, value string)

func (*OrderedParams) Clone

func (o *OrderedParams) Clone() *OrderedParams

func (*OrderedParams) Get

func (o *OrderedParams) Get(key string) string

func (*OrderedParams) Keys

func (o *OrderedParams) Keys() []string

func (*OrderedParams) Len

func (o *OrderedParams) Len() int

func (*OrderedParams) Less

func (o *OrderedParams) Less(i int, j int) bool

func (*OrderedParams) Swap

func (o *OrderedParams) Swap(i int, j int)

type PushBatchUniMsgJSONResponse

type PushBatchUniMsgJSONResponse struct {
	RequestId               int                     `json:"request_id"`
	PushBatchUniMsgResponse PushBatchUniMsgResponse `json:"response_params"`
}

type PushBatchUniMsgRequest

type PushBatchUniMsgRequest struct {
	ChannelIds string //一组channel_id(最多为一万个)组成的json数组字符串
	MsgType    int    //消息类型 0:消息;1:通知
	Message    string //消息内容,json格式, http://push.baidu.com/doc/restapi/msg_struct
	MsgExpires int    //相对于当前时间的消息过期时间,单位为秒 默认为5小时(18000秒)
	TopicId    string //分类主题名称 字母、数字及下划线组成,长度限制为1~128
}

func (*PushBatchUniMsgRequest) AddToParams

func (r *PushBatchUniMsgRequest) AddToParams(params *OrderedParams) *OrderedParams

type PushBatchUniMsgResponse

type PushBatchUniMsgResponse struct {
	MsgId    string `json:"msg_id"`
	SendTime int64  `json:"send_time"`
}

type PushMsgToAllJSONResponse

type PushMsgToAllJSONResponse struct {
	RequestId            int                  `json:"request_id"`
	PushMsgToAllResponse PushMsgToAllResponse `json:"response_params"`
}

type PushMsgToAllRequest

type PushMsgToAllRequest struct {
	MsgType      int    //消息类型 0:消息;1:通知
	Message      string //消息内容,json格式, http://push.baidu.com/doc/restapi/msg_struct
	MsgExpires   int    //相对于当前时间的消息过期时间,单位为秒 默认为5小时(18000秒)
	DeployStatus int    //设置iOS应用的部署状态,仅iOS应用推送时使用 1:开发状态;2:生产状态; 若不指定,则默认设置为生产状态。
	SendTime     int64  //定时推送,用于指定的实际发送时间 必须在当前时间60s以外,1年以内
}

func (*PushMsgToAllRequest) AddToParams

func (r *PushMsgToAllRequest) AddToParams(params *OrderedParams) *OrderedParams

type PushMsgToAllResponse

type PushMsgToAllResponse struct {
	MsgId    string
	TimerId  string
	SendTime int64
}

type PushMsgToSingleDeviceJSONResponse

type PushMsgToSingleDeviceJSONResponse struct {
	RequestId                     int                           `json:"request_id"`
	PushMsgToSingleDeviceResponse PushMsgToSingleDeviceResponse `json:"response_params"`
}

type PushMsgToSingleDeviceRequest

type PushMsgToSingleDeviceRequest struct {
	ChannelId    string //唯一对应一台设备
	MsgType      int    //消息类型 0:消息;1:通知
	Message      string //消息内容,json格式, http://push.baidu.com/doc/restapi/msg_struct
	MsgExpires   int64  //相对于当前时间的消息过期时间,单位为秒 默认为5小时(18000秒)
	DeployStatus int    //设置iOS应用的部署状态,仅iOS应用推送时使用 1:开发状态;2:生产状态; 若不指定,则默认设置为生产状态。
}

func (*PushMsgToSingleDeviceRequest) AddToParams

func (r *PushMsgToSingleDeviceRequest) AddToParams(params *OrderedParams) *OrderedParams

type PushMsgToSingleDeviceResponse

type PushMsgToSingleDeviceResponse struct {
	MsgId    string `json:"msg_id"`
	SendTime int64  `json:"send_time"`
}

type PushMsgToTagJSONResponse

type PushMsgToTagJSONResponse struct {
	RequestId            int                  `json:"request_id"`
	PushMsgToTagResponse PushMsgToTagResponse `json:"response_params"`
}

type PushMsgToTagRequest

type PushMsgToTagRequest struct {
	TagName      string //标签名 必须是已创建的
	MsgType      int    //消息类型 0:消息;1:通知
	Message      string //消息内容,json格式, http://push.baidu.com/doc/restapi/msg_struct
	MsgExpires   int    //相对于当前时间的消息过期时间,单位为秒 默认为5小时(18000秒)
	DeployStatus int    //设置iOS应用的部署状态,仅iOS应用推送时使用 1:开发状态;2:生产状态; 若不指定,则默认设置为生产状态。
	SendTime     int64  //定时推送,用于指定的实际发送时间 必须在当前时间60s以外,1年以内
}

func (*PushMsgToTagRequest) AddToParams

func (r *PushMsgToTagRequest) AddToParams(params *OrderedParams) *OrderedParams

type PushMsgToTagResponse

type PushMsgToTagResponse struct {
	MsgId    string `json:"msg_id"`
	TimerId  string `json:"timer_id"`
	SendTime int64  `json:"send_time"`
}

type QueryDeviceNumInTagJSONResponse

type QueryDeviceNumInTagJSONResponse struct {
	RequestId                   int                         `json:"request_id"`
	QueryDeviceNumInTagResponse QueryDeviceNumInTagResponse `json:"response_params"`
}

type QueryDeviceNumInTagRequest

type QueryDeviceNumInTagRequest struct {
	TagName string
}

func (*QueryDeviceNumInTagRequest) AddToParams

func (r *QueryDeviceNumInTagRequest) AddToParams(params *OrderedParams) *OrderedParams

type QueryDeviceNumInTagResponse

type QueryDeviceNumInTagResponse struct {
	DeviceNum int `json:"device_num"`
}

type QueryMsgStatusJSONResponse

type QueryMsgStatusJSONResponse struct {
	RequestId              int                    `json:"request_id"`
	QueryMsgStatusResponse QueryMsgStatusResponse `json:"response_params"`
}

type QueryMsgStatusRequest

type QueryMsgStatusRequest struct {
	MsgId string
}

func (*QueryMsgStatusRequest) AddToParams

func (r *QueryMsgStatusRequest) AddToParams(params *OrderedParams) *OrderedParams

type QueryMsgStatusResponse

type QueryMsgStatusResponse struct {
	TotalNum     int           `json:"total_num"`
	MsgSendInfos []MsgSendInfo `json:"result"`
}

type QueryStatisticDeviceJSONResponse

type QueryStatisticDeviceJSONResponse struct {
	RequestId                    int                          `json:"request_id"`
	QueryStatisticDeviceResponse QueryStatisticDeviceResponse `json:"response_params"`
}

type QueryStatisticDeviceResponse

type QueryStatisticDeviceResponse struct {
	TotalNum int                       `json:"total_num"`
	Result   map[string]DeviceStatUnit `json:"result"`
}

type QueryStatisticTopicJSONResponse

type QueryStatisticTopicJSONResponse struct {
	RequestId                   int                         `json:"request_id"`
	QueryStatisticTopicResponse QueryStatisticTopicResponse `json:"response_params"`
}

type QueryStatisticTopicRequest

type QueryStatisticTopicRequest struct {
	TopicId string
}

func (*QueryStatisticTopicRequest) AddToParams

func (r *QueryStatisticTopicRequest) AddToParams(params *OrderedParams) *OrderedParams

type QueryStatisticTopicResponse

type QueryStatisticTopicResponse struct {
	TotalNum int                      `json:"total_num"`
	Result   map[string]TopicStatUnit `json:"result"`
}

type QueryTagsJSONResponse

type QueryTagsJSONResponse struct {
	RequestId         int               `json:"request_id"`
	QueryTagsResponse QueryTagsResponse `json:"response_params"`
}

type QueryTagsRequest

type QueryTagsRequest struct {
	TagName string
	Start   int
	Limit   int
}

func (*QueryTagsRequest) AddToParams

func (r *QueryTagsRequest) AddToParams(params *OrderedParams) *OrderedParams

type QueryTagsResponse

type QueryTagsResponse struct {
	TotalNum int       `json:"total_num"`
	TagsInfo []TagInfo `json:"tags"`
}

type QueryTimerListJSONResponse

type QueryTimerListJSONResponse struct {
	RequestId              int                    `json:"request_id"`
	QueryTimerListResponse QueryTimerListResponse `json:"response_params"`
}

type QueryTimerListRequest

type QueryTimerListRequest struct {
	TimerId string
	Start   int
	Limit   int
}

func (*QueryTimerListRequest) AddToParams

func (r *QueryTimerListRequest) AddToParams(params *OrderedParams) *OrderedParams

type QueryTimerListResponse

type QueryTimerListResponse struct {
	TotalNum         int               `json:"total_num"`
	TimerResultInfos []TimerResultInfo `json:"result"`
}

type QueryTimerRecordsJSONResponse

type QueryTimerRecordsJSONResponse struct {
	RequestId                 int                       `json:"request_id"`
	QueryTimerRecordsResponse QueryTimerRecordsResponse `json:"response_params"`
}

type QueryTimerRecordsRequest

type QueryTimerRecordsRequest struct {
	TimerId    string
	Start      int
	Limit      int
	RangeStart int64
	RangeEnd   int64
}

func (*QueryTimerRecordsRequest) AddToParams

func (r *QueryTimerRecordsRequest) AddToParams(params *OrderedParams) *OrderedParams

type QueryTimerRecordsResponse

type QueryTimerRecordsResponse struct {
	TimerId      string   `json:"timer_id"`
	TimerRecords []Record `json:"result"`
}

type QueryTopicListJSONResponse

type QueryTopicListJSONResponse struct {
	RequestId              int                    `json:"request_id"`
	QueryTopicListResponse QueryTopicListResponse `json:"response_params"`
}

type QueryTopicListRequest

type QueryTopicListRequest struct {
	Start int
	Limit int
}

func (*QueryTopicListRequest) AddToParams

func (r *QueryTopicListRequest) AddToParams(params *OrderedParams) *OrderedParams

type QueryTopicListResponse

type QueryTopicListResponse struct {
	TotalNum         int               `json:"total_num"`
	TopicResultInfos []TopicResultInfo `json:"topics"`
}

type QueryTopicRecordsJSONResponse

type QueryTopicRecordsJSONResponse struct {
	RequestId                 int                       `json:"request_id"`
	QueryTopicRecordsResponse QueryTopicRecordsResponse `json:"response_params"`
}

type QueryTopicRecordsRequest

type QueryTopicRecordsRequest struct {
	TopicId    string
	Start      int
	Limit      int
	RangeStart int64
	RangeEnd   int64
}

func (*QueryTopicRecordsRequest) AddToParams

func (r *QueryTopicRecordsRequest) AddToParams(params *OrderedParams) *OrderedParams

type QueryTopicRecordsResponse

type QueryTopicRecordsResponse struct {
	TopicId      string   `json:"topic_id"`
	TopicRecords []Record `json:"result"`
}

type Record

type Record struct {
	MsgId    string `json:"msg_id"`
	Status   int    `json:"status"`
	SendTime int64  `json:"send_time"`
}

type TagInfo

type TagInfo struct {
	TagId      string `json:"tid"`
	TagName    string `json:"tag"`
	Info       string `json:"info"`
	CreateTime int64  `json:"createtime"`
}

type TimerResultInfo

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

type TopicResultInfo

type TopicResultInfo struct {
	TopicId          string `json:"topic_id"`
	FirstPushTime    int64  `json:"ctime"`
	LastPushTime     int64  `json:"mtime"`
	TotalPushDevsNum int    `json:"push_cnt"`
	TotalAckDevsNum  int    `json:"ack_cnt"`
}

type TopicStatUnit

type TopicStatUnit struct {
	Ack int `json:"ack"`
}

Jump to

Keyboard shortcuts

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