@@ -16,8 +16,11 @@ var GROUP_API_URL = 'https://api.jpush.cn/v3/grouppush'
16
16
var REPORT_API_URL = 'https://report.jpush.cn/v3'
17
17
var SCHEDULE_API_URL = 'https://api.jpush.cn/v3/schedules' // 定时任务
18
18
var REPORT_RECEIVED = '/received'
19
+ var REPORT_RECEIVED_DETAIL = '/received/detail'
20
+ var REPORT_STATUS_MESSAGE = '/status/message'
19
21
var REPORT_USER = '/users'
20
22
var REPORT_MESSAGE = '/messages'
23
+ var REPORT_MESSAGE_DETAIL = '/messages/detail'
21
24
var HOST_NAME_SSL = 'https://device.jpush.cn'
22
25
var DEVICE_PATH = '/v3/devices'
23
26
var TAG_PATH = '/v3/tags'
@@ -96,7 +99,7 @@ function sendPush (payload, callback) {
96
99
return _request ( this , this . isGroup === true ? GROUP_API_URL : PUSH_API_URL , payload , 'POST' , callback )
97
100
}
98
101
99
- function getReportReceiveds ( msgIds , callback ) {
102
+ function getReportReceiveds ( msgIds , callback ) {
100
103
if ( MSG_IDS_PATTERNS . test ( msgIds ) ) {
101
104
throw new JError . InvalidArgumentError (
102
105
'Invalid msg_ids, msg_ids should be composed with alphabet and comma.' )
@@ -105,7 +108,37 @@ function getReportReceiveds (msgIds, callback) {
105
108
return _request ( this , url , null , 'GET' , callback )
106
109
}
107
110
108
- function getReportMessages ( msgIds , callback ) {
111
+ function getReportReceivedDetail ( msgIds , callback ) {
112
+ if ( MSG_IDS_PATTERNS . test ( msgIds ) ) {
113
+ throw new JError . InvalidArgumentError (
114
+ 'Invalid msg_ids, msg_ids should be composed with alphabet and comma.' )
115
+ }
116
+ var url = REPORT_API_URL + REPORT_RECEIVED_DETAIL + '?msg_ids=' + msgIds
117
+ return _request ( this , url , null , 'GET' , callback )
118
+ }
119
+
120
+ function getReportStatusMessage ( msgId , registrationIds , date , callback ) {
121
+ if ( msgId == null ) {
122
+ throw new JError . InvalidArgumentError ( 'msgId is null!' ) ;
123
+ }
124
+ if ( typeof ( msgId ) != 'number' ) {
125
+ throw new JError . InvalidArgumentError ( 'msgId is not number type!' ) ;
126
+ }
127
+ if ( registrationIds == null ) {
128
+ throw new JError . InvalidArgumentError ( 'registrationIds is null!' ) ;
129
+ }
130
+ var json = {
131
+ "msg_id" : msgId ,
132
+ "registration_ids" : registrationIds
133
+ } ;
134
+ if ( date ) {
135
+ json . date = date ;
136
+ }
137
+ var url = REPORT_API_URL + REPORT_STATUS_MESSAGE ;
138
+ return _request ( this , url , JSON . stringify ( json ) , 'POST' , callback ) ;
139
+ }
140
+
141
+ function getReportMessages ( msgIds , callback ) {
109
142
if ( MSG_IDS_PATTERNS . test ( msgIds ) ) {
110
143
throw new JError . InvalidArgumentError (
111
144
'Invalid msg_ids, msg_ids should be composed with alphabet and comma.' )
@@ -114,6 +147,15 @@ function getReportMessages (msgIds, callback) {
114
147
return _request ( this , url , null , 'GET' , callback )
115
148
}
116
149
150
+ function getReportMessagesDetail ( msgIds , callback ) {
151
+ if ( MSG_IDS_PATTERNS . test ( msgIds ) ) {
152
+ throw new JError . InvalidArgumentError (
153
+ 'Invalid msg_ids, msg_ids should be composed with alphabet and comma.' )
154
+ }
155
+ var url = REPORT_API_URL + REPORT_MESSAGE_DETAIL + '?msg_ids=' + msgIds
156
+ return _request ( this , url , null , 'GET' , callback )
157
+ }
158
+
117
159
function getReportUsers ( timeUnit , start , duration , callback ) {
118
160
var url = REPORT_API_URL + REPORT_USER + '?time_unit=' + timeUnit + '&start=' + start + '&duration=' + duration
119
161
return _request ( this , url , null , 'GET' , callback )
@@ -265,6 +307,60 @@ function getScheduleMsgIds (scheduleId, callback) {
265
307
return _request ( this , url , null , 'GET' , callback )
266
308
}
267
309
310
+ /**
311
+ * 获取推送唯一标识符
312
+ * http://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#cid
313
+ * @param {* } count 可选参数。数值类型,不传则默认为 1。范围为 [1, 1000]
314
+ * @param {* } type 可选参数。CID 类型。取值:push(默认),schedule
315
+ * @param {* } callback
316
+ */
317
+ function getCid ( count , type , callback ) {
318
+ if ( ! count ) {
319
+ count = 1 ;
320
+ }
321
+ if ( ! type ) {
322
+ type = 'push' ;
323
+ }
324
+ var url = PUSH_API_URL + '/cid?count=' + count + '&type=' + type ;
325
+ return _request ( this , url , null , 'GET' , callback ) ;
326
+ }
327
+
328
+ /**
329
+ * 针对RegID方式批量单推(VIP专属接口)
330
+ * http://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#vip
331
+ * @param {* } singlePayloads 单推payload数组
332
+ * @param {* } callback
333
+ */
334
+ function batchPushByRegid ( singlePayloads , callback ) {
335
+ var url = PUSH_API_URL + '/batch/regid/single' ;
336
+ return batchPush . call ( this , url , singlePayloads , callback ) ;
337
+ }
338
+
339
+ /**
340
+ * 针对Alias方式批量单推(VIP专属接口)s
341
+ * http://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#vip
342
+ * @param {* } singlePayloads 单推payload数组
343
+ * @param {* } callback
344
+ */
345
+ function batchPushByAlias ( singlePayloads , callback ) {
346
+ var url = PUSH_API_URL + '/batch/alias/single' ;
347
+ return batchPush . call ( this , url , singlePayloads , callback ) ;
348
+ }
349
+
350
+ function batchPush ( url , singlePayloads , callback ) {
351
+ var client = this ;
352
+ return getCid . call ( client , singlePayloads . length , 'push' , function ( err , res ) {
353
+ if ( err ) {
354
+ return callback ( err ) ;
355
+ }
356
+ var body = { "pushlist" :{ } } ;
357
+ for ( var i = 0 ; i < singlePayloads . length ; i ++ ) {
358
+ body . pushlist [ res . cidlist [ i ] ] = singlePayloads [ i ] ;
359
+ }
360
+ return _request ( client , url , JSON . stringify ( body ) , 'POST' , callback ) ;
361
+ } ) ;
362
+ }
363
+
268
364
// 定时任务 end
269
365
270
366
// Proxy start
@@ -324,7 +420,6 @@ function _request (client, url, body, method, callback, times = 1) {
324
420
callback ( new JError . APIRequestError ( res . statusCode , body ) )
325
421
}
326
422
}
327
-
328
423
Request [ method . toLowerCase ( ) ] ( {
329
424
url : url ,
330
425
body : body ,
@@ -339,6 +434,9 @@ function _request (client, url, body, method, callback, times = 1) {
339
434
340
435
JPushClient . prototype . sendPush = sendPush
341
436
JPushClient . prototype . getReportReceiveds = getReportReceiveds
437
+ JPushClient . prototype . getReportReceivedDetail = getReportReceivedDetail
438
+ JPushClient . prototype . getReportStatusMessage = getReportStatusMessage
439
+ JPushClient . prototype . getReportMessagesDetail = getReportMessagesDetail
342
440
JPushClient . prototype . push = push
343
441
JPushClient . prototype . setMobile = setMobile
344
442
JPushClient . prototype . getDeviceTagAlias = getDeviceTagAlias
@@ -357,6 +455,9 @@ JPushClient.prototype.getSchedule = getSchedule
357
455
JPushClient . prototype . delSchedule = delSchedule
358
456
JPushClient . prototype . setSchedule = setSchedule
359
457
JPushClient . prototype . updateSchedule = updateSchedule
458
+ JPushClient . prototype . getCid = getCid
459
+ JPushClient . prototype . batchPushByRegid = batchPushByRegid
460
+ JPushClient . prototype . batchPushByAlias = batchPushByAlias
360
461
361
462
// exports constants and methods
362
463
exports . ALL = JModel . ALL
0 commit comments