-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathPushExample.js
46 lines (42 loc) · 1.51 KB
/
PushExample.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var JPush = require("../index.js").JPush;
var Conf = require("./Conf.js");
var client = JPush.buildClient(Conf.appKey, Conf.masterSecret);
// 使用 proxy
// var client = JPush.buildClient(Conf.appKey, Conf.masterSecret, null, null, null,'http://192.168.8.236:3128')
// easy push.
client.push().setPlatform(JPush.ALL)
.setAudience(JPush.ALL)
.setNotification('Hi, JPush', JPush.ios('ios alert', 'happy', 5))
.send(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('Sendno: ' + res.sendno)
console.log('Msg_id: ' + res.msg_id)
}
})
// full push.
client.push().setPlatform('ios', 'android')
.setAudience(JPush.tag('555', '666'), JPush.alias('666,777'))
.setNotification('Hi, JPush', JPush.ios('ios alert'), JPush.android('android alert', null, 1))
.setMessage('msg content')
.setOptions(null, 60)
.send(function (err, res) {
if (err) {
if (err instanceof JPush.APIConnectionError) {
console.log(err.message)
// Response Timeout means your request to the server may have already received,
// please check whether or not to push
console.log(err.isResponseTimeout)
} else if (err instanceof JPush.APIRequestError) {
console.log(err.message)
}
} else {
console.log('Sendno: ' + res.sendno)
console.log('Msg_id: ' + res.msg_id)
}
})