道路环境监测node后端和java后台代码
wangrong
2022-12-08 89cb05f837c76b001208770cb62c7ad840449c0a
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
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);
                });
        })
    }
}