var JPush = require("jpush-async").JPushAsync
|
var client = JPush.buildClient('4d8537a365e460b36ee67582', 'aa157259813574ee87a17fbb')
|
module.exports = {
|
pushAll(msg) {
|
return new Promise((resolve, reject) => {
|
client.push().setPlatform(JPush.ALL)
|
.setAudience(JPush.ALL)
|
.setMessage(msg)
|
.send()
|
.then(function (result) {
|
resolve(result)
|
}).catch(function (err) {
|
reject(err);
|
});
|
})
|
},
|
/**
|
* 命令下发接口
|
* @param {String} alias 设备号,逗号分割
|
* @param {String} msg "scan","record","reboot"
|
* @param {JSON} extra 相应的命令参数
|
*/
|
pushWithAlias(rids, msg, extra) {
|
return new Promise((resolve, reject) => {
|
client.push().setPlatform('android')
|
.setAudience(JPush.registration_id(rids))
|
.setMessage('title', msg, 'string', extra)
|
.send()
|
.then(function (result) {
|
// let sql = 'INSERT INTO t_fm_jpush(msg_id,android_id,msg,send_time) VALUES '
|
// if (typeof alias=="object") {
|
// sql += `('${result.msg_id}','${alias[0]}','${msg}',NOW())`
|
// for (let i = 1; i < alias.length; i++) {
|
// const element = alias[i];
|
// sql += `,('${result.msg_id}','${alias[i]}','${msg}',NOW())`
|
// }
|
// } else {
|
// sql += `('${result.msg_id}','${alias}','${msg}',NOW())`
|
// }
|
//mysql_db.query(sql);
|
resolve(result)
|
}).catch(function (err) {
|
reject(err);
|
});
|
})
|
}
|
}
|