Repository navigation
Expand file tree
/
Copy pathpush.js
More file actions
59 lines (57 loc) · 1.72 KB
/
Copy pathpush.js
File metadata and controls
59 lines (57 loc) · 1.72 KB
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
49
50
51
52
53
54
55
56
57
58
59
var User = require('../proxy/user');
var Message = require('../proxy/message');
var JPush = require("jpush-sdk");
var eventproxy = require('eventproxy');
var config = require('../config');
var client = null;
if (config.jpush && config.jpush.masterSecret !== 'YourSecretKeyyyyyyyyyyyyy') {
client = JPush.buildClient(config.jpush);
}
/**
* 通过极光推送发生消息通知
* @param {String} type 消息类型
* @param {String} author_id 消息作者ID
* @param {String} master_id 被通知者ID
* @param {String} topic_id 相关主题ID
*/
exports.send = function (type, author_id, master_id, topic_id) {
if (client !== null) {
var ep = new eventproxy();
User.getUserById(author_id, ep.done('author'));
Message.getMessagesCount(master_id, ep.done('count'));
ep.all('author', 'count', function (author, count) {
var msg = author.loginname + ' ';
var extras = {
topicId: topic_id
};
switch (type) {
case 'at':
msg += '@了你';
break;
case 'reply':
msg += '回复了你的主题';
break;
default:
break;
}
client.push()
.setPlatform(JPush.ALL)
.setAudience(JPush.alias(master_id.toString()))
.setNotification(msg,
JPush.ios(msg, null, count, null, extras),
JPush.android(msg, null, null, extras)
)
.setOptions(null, null, null, !config.debug)
.send(function (err, res) {
if (config.debug) {
if (err) {
console.log(err.message);
} else {
console.log('Sendno: ' + res.sendno);
console.log('Msg_id: ' + res.msg_id);
}
}
});
})
}
};