Skip to content

Commit

Permalink
* 更新api.md,增加厂商通道参数设置方法 & 新增查询设备在线状态的接口
Browse files Browse the repository at this point in the history
* 修复getReportStatus参数问题
  • Loading branch information
dengff committed Jul 6, 2020
1 parent a87b5d0 commit 4617e78
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 9 deletions.
12 changes: 12 additions & 0 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@
|value|object|||当 style = 1, 为大文本通知栏样式,类型为 string,内容会被通知栏以大文本的形式展示出来。支持 API 16 以上的 rom;<br>当 style = 2,为文本条目通知栏样式,类型为 json 对象,json 的每个 key 对应的 value 会被当作文本条目逐条展示。支持 API 16 以上的 rom;<br>当 style = 3,为大图片通知栏样式,类型为 string,可以是网络图片 url,或本地图片的 path,目前支持.jpg和.png后缀的图片。图片内容会被通知栏以大图片的形式展示出来。如果是 http/https 的url,会自动下载;如果要指定开发者准备的本地图片就填 sdcard 的相对路径。支持 API 16以上的 rom。|
|alertTYpe|int||-1|可选范围为 -1 ~ 7 ,对应 Notification.DEFAULT_ALL = -1 或者 Notification.DEFAULT_SOUND = 1, Notification.DEFAULT_VIBRATE = 2, Notification.DEFAULT_LIGHTS = 4 的任意 “or” 组合。默认按照 -1 处理。|

***注:对于Android notification 其他参数,比如:uri_activity,uri_action等,可使用如下方式添加:***
```
// 创建android notification对象
var androidObj = JPush.android('Hi,JPush', 'JPush Title', 1, {'key':'value'});
// 新增参数:uri_activity, uri_action
androidObj.android['uri_activity'] = 'xxx';
androidObj.android['uri_action'] = 'xxx';
```




**winphone(alert, title, openPage, extras)**

|参数|类型|必须|默认值|说明|
Expand Down
10 changes: 10 additions & 0 deletions examples/DeviceAsyncExamples.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ client.getDeviceTagAlias('0900e8d85ef')
}).catch(function(err) {
console.log(err)
})

async function getDeviceStatus() {
const resp = await client.getDeviceStatus(['171976fa8a8085fcdba']);
if (resp.err) {
console.log(resp.err.message)
} else {
console.log(resp.res);
}
}
getDeviceStatus();
13 changes: 13 additions & 0 deletions examples/DeviceExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,16 @@ client.deleteAlias('alias2', null, function (err, res) {
console.log('success')
}
})

/** 查询设备在线状态 */
client.getDeviceStatus(["160a3797c80b688c24b"], function(err, res) {
if (err) {
if (err instanceof JPush.APIConnectionError) {
console.log(err.message)
} else if (err instanceof JPush.APIRequestError) {
console.log(err.message)
}
} else {
console.log(res);
}
})
14 changes: 14 additions & 0 deletions examples/ReportAsyncExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var JPush = require("../index.js").JPushAsync;
var Conf = require("./Conf.js");

var client = JPush.buildClient(Conf.appKey, Conf.masterSecret);

async function getReportStatusMessage() {
const data = await client.getReportStatusMessage(23223422, ['24243242']);
if (data.err) {
console.log(data.err);
} else {
console.log(data.res);
}
}
getReportStatusMessage();
23 changes: 20 additions & 3 deletions lib/JPush/JPush.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ function getReportStatusMessage(msgId, registrationIds, date, callback) {
if (msgId == null) {
throw new JError.InvalidArgumentError('msgId is null!');
}
if (typeof(msgId) != 'number') {
throw new JError.InvalidArgumentError('msgId is not number type!');
}
// if (typeof(msgId) != 'number') {
// throw new JError.InvalidArgumentError('msgId is not number type!');
// }
if (registrationIds == null) {
throw new JError.InvalidArgumentError('registrationIds is null!');
}
Expand Down Expand Up @@ -363,6 +363,22 @@ function batchPush(url, singlePayloads, callback) {

// 定时任务 end

/**
* 获取用户在线状态(vip专属接口)
* https://docs.jiguang.cn//jpush/server/push/rest_api_v3_device/#vip
* @param {*} regIds 需要在线状态的用户 registration_id
* @param {*} callback
*/
function getDeviceStatus(regIds, callback) {
var json = {
"registration_ids": regIds
};

var url = HOST_NAME_SSL + DEVICE_PATH + '/status';
return _request(this, url, JSON.stringify(json), 'POST', callback);
}


// Proxy start

// Proxy end
Expand Down Expand Up @@ -447,6 +463,7 @@ JPushClient.prototype.addRemoveDevicesFromTag = addRemoveDevicesFromTag
JPushClient.prototype.deleteTag = deleteTag
JPushClient.prototype.getAliasDeviceList = getAliasDeviceList
JPushClient.prototype.deleteAlias = deleteAlias
JPushClient.prototype.getDeviceStatus = getDeviceStatus
JPushClient.prototype.validate = validate
JPushClient.prototype.getReportMessages = getReportMessages
JPushClient.prototype.getReportUsers = getReportUsers
Expand Down
29 changes: 23 additions & 6 deletions lib/JPush/JPushAsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,25 @@ async function getReportReceivedDetail(msgIds) {
return _request(this, url, null, 'GET')
}

async function getReportStatusMessage(msgId, registrationIds, date) {
function getReportStatusMessage(msgId, registrationIds, date) {
if (msgId == null) {
throw new JError.InvalidArgumentError('msgId is null!');
}
if (typeof(msgId) != 'number') {
throw new JError.InvalidArgumentError('msgId is not number type!');
}

if (registrationIds == null) {
throw new JError.InvalidArgumentError('registrationIds is null!');
}
var json = {
"msg_id": msgId,
"msg_id": msgId > Number.MAX_SAFE_INTEGER ? String(msgId) : msgId,
"registration_ids": registrationIds
};
if (date != null) {
json.date = date;
}
var url = REPORT_API_URL + REPORT_STATUS_MESSAGE;
return _request(this, url, JSON.stringify(json), 'POST');
return _request(this, url, json, 'POST')
.then(res => ({ res }))
.catch(error => ({ err: error }));
}

async function getReportMessages(msgIds) {
Expand Down Expand Up @@ -312,6 +312,22 @@ async function getScheduleMsgIds (scheduleId, callback) {

// Proxy end

/**
* 获取用户在线状态(vip专属接口)
* https://docs.jiguang.cn//jpush/server/push/rest_api_v3_device/#vip
* @param {*} regIds 需要在线状态的用户 registration_id
*/
function getDeviceStatus(regIds) {
var json = {
"registration_ids": regIds
};

var url = HOST_NAME_SSL + DEVICE_PATH + '/status';
return _request(this, url, json, 'POST')
.then(res => ({ res }))
.catch(error => ({ err: error }));
}

async function _request (client, url, body, method, times = 1) {
if (client.isDebug) {
debug('Push URL :' + url)
Expand Down Expand Up @@ -369,6 +385,7 @@ JPushClient.prototype.getDeviceTagAlias = getDeviceTagAlias
JPushClient.prototype.updateDeviceTagAlias = updateDeviceTagAlias
JPushClient.prototype.getTagList = getTagList
JPushClient.prototype.isDeviceInTag = isDeviceInTag
JPushClient.prototype.getDeviceStatus = getDeviceStatus
JPushClient.prototype.addRemoveDevicesFromTag = addRemoveDevicesFromTag
JPushClient.prototype.deleteTag = deleteTag
JPushClient.prototype.getAliasDeviceList = getAliasDeviceList
Expand Down

0 comments on commit 4617e78

Please sign in to comment.