-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex
executable file
·48 lines (41 loc) · 1.15 KB
/
index
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
47
48
#!/usr/bin/env node
'use strict';
var apn = require('apn');
var config = require('./config.json');
const TOKEN = config.devicetoken;
const BUNDLE_ID = config.bundle; // App Bundle Id
// 正式推送证书路径
const CERT = config.cert;
const KEY = config.key;
//推送环境
const PRODUCTION = config.production;
let options = { // 推送服务设置选项
cert: CERT,
key: KEY,
production: false, //推送环境 true 为正式 false 为测试
enhanced: true,
debug: true,
}
let service = new apn.Provider(options);
let note = new apn.Notification({
alert: 'test push, 收到了吗? by 高翔',
});
note.topic = BUNDLE_ID;
service.on('connected', function () {
console.log('ddd');
});
console.log(`Send: ${note.compile()} to ${TOKEN}`);
service.send(note, TOKEN).then( (result) => {
let sent = result.sent;
let failed = result.failed;
console.log('成功: ', result.sent.length);
console.log('失败: ', result.failed.length);
console.log(result.failed);
if(failed.length = 0) {
console.log('发送成功设备: ' + result.sent);
}else {
console.log('发送失败!');
console.log(result.failed);
}
});
service.shutdown();