1.0.1 • Published 11 years ago

baidu-push-sdk v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
11 years ago

BaiduPushNodejsServerSDK

百度推送node.js接口

感谢xiariqingquan,在其基础上补充了高级API接口和文档

安装

npm install baidu-push-sdk
npm install https://github.com/wangzheng422/BaiduPushNodejsServerSDK/tarball/master

基础API

1.queryBindList

功能:查询设备、应用、用户与百度Channel的绑定关系。

函数:

queryBindList(opt, callback)

参数:

opt Object , 属性如下表:

callback 回调函数,其中参数

result包含response_params,response_params属性是一个二级json,由n个包含key和value属性的对象组成。表示API返回的数据内容。

response_params中包含以下字段:

2.pushMsg

功能:推送消息,该接口可用于推送单个人、一群人、所有人以及固定设备的使用场景。

函数:

pushMsg(opt, callback)

参数:

opt Object , 属性如下表:

{ //android必选,ios可选 "title" : "hello" , “description: "hello world" //android特有字段,可选 "notification_builder_id": 0, "notification_basic_style": 7, "open_type":0, "net_support" : 1, "user_confirm": 0, "url": "http://developer.baidu.com", "pkg_content":"", "pkg_name" : "com.baidu.bccsclient", "pkg_version":"0.1", //android自定义字段 "custom_content": { "key1":"value1", "key2":"value2" }, //ios特有字段,可选 "aps": { "alert":"Message From Baidu Push", "Sound":"", "Badge":0 }, //ios的自定义字段 "key1":"value1", "key2":"value2" } 注意: 当description与alert同时存在时,ios推送以alert内容作为通知内容 当custom_content与 ios的自定义字段"key":"value"同时存在时,ios推送的自定义字段内容会将以上两个内容合并,但推送内容整体长度不能大于256B,否则有被截断的风险。 此格式兼容Android和ios原生通知格式的推送。

callback 回调函数,其中参数

示例

var baidu_push = require("baidu-push-sdk");

var client = new baidu_push({
	ak: 'your ak here',
	sk: 'your sk here'
});

client.pushMsg({
	user_id:"your user id here",
	channel_id:"your channel id here",
	push_type: 1,
	device_type:4,
	messages: JSON.stringify({title:'title',description:'description',aps:{alert:'aps message',sound:'',badge:0}}),
	msg_keys: JSON.stringify(["key0"]),
	message_type:1,
	deploy_status:1
}, function(err, result){
	console.log(result);
})
		

高级API

3.verifyBind

功能:判断设备、应用、用户与Channel的绑定关系是否存在。

函数:

verifyBind(opt, callback)

参数:

opt Object , 属性如下表:

4.fetchMsg

功能:查询离线消息。

函数:

fetchMsg(opt, callback)

参数:

opt Object , 属性如下表:

result包含response_params,response_params属性是一个二级json,由n个包含key和value属性的对象组成。表示API返回的数据内容。

response_params中包含以下字段:

5.fetchMsgCount

功能:查询离线消息的个数。

函数:

fetchMsgCount(opt, callback)

参数:

opt Object , 属性如下表:

result包含response_params,response_params属性是一个二级json,由n个包含key和value属性的对象组成。表示API返回的数据内容。

response_params中包含以下字段:

6.deleteMsg

功能:删除离线消息。

函数:

deleteMsg(opt, callback)

参数:

opt Object , 属性如下表:

result包含response_params,response_params属性是一个二级json,由n个包含key和value属性的对象组成。表示API返回的数据内容。

response_params中包含以下字段:

1:失败。

7.setTag

功能:服务器端设置用户标签。当该标签不存在时,服务端将会创建该标签。特别地,当user_id被提交时,服务端将会完成用户和tag的绑定操作。

函数:

setTag(opt, callback)

参数:

opt Object , 属性如下表:

8.fetchTag

功能:App Server查询应用标签。

函数:

fetchTag(opt, callback)

参数:

opt Object , 属性如下表:

callback 回调函数,其中参数

result包含response_params,response_params属性是一个二级json,由n个包含key和value属性的对象组成。表示API返回的数据内容。

response_params中包含以下字段:

9.deleteTag

功能:服务端删除用户标签。特别地,当user_id被提交时,服务端将只会完成解除该用户与tag绑定关系的操作。

注意:该操作不可恢复,请谨慎使用。

函数:

deleteTag(opt, callback)

参数:

opt Object , 属性如下表:

callback 回调函数,其中参数

10.queryUserTag

功能:App Server查询用户所属的标签列表。

函数:

queryUserTag(opt, callback)

参数:

opt Object , 属性如下表:

callback 回调函数,其中参数

result包含response_params,response_params属性是一个二级json,由n个包含key和value属性的对象组成。表示API返回的数据内容。

response_params中包含以下字段:

name:标签名称

info:标签信息

type:标签类型

create_time:标签创建时间

11.queryDeviceTag

功能:根据channel_id查询设备类型。

函数:

queryDeviceTag(opt, callback)

参数:

opt Object , 属性如下表:

callback 回调函数,其中参数

result包含response_params,response_params属性是一个二级json,由n个包含key和value属性的对象组成。表示API返回的数据内容。

response_params中包含以下字段: