离子推送的后端服务

时间:2016-04-20 12:48:58

标签: ionic-framework backend pushwoosh

我使用pushwoosh实现了离子推送通知。但是我使用pushwoosh提供的仪表板来发送推送通知。我想使用由我自己创建的后端发送推送通知。我该怎么做?

1 个答案:

答案 0 :(得分:1)

我正在研究离子框架,并使用推送通知通过 REST API 发送通知,使用node-gcm工作正常。 示例代码

(function() {
function execute(rqst, q, fwk) {
    var gcm = require('node-gcm');

    var message = new gcm.Message();
    message.timeToLive = 3000;
    message.addData({
        title: 'Push Notification Sample',
        body: 'Abnormal data access',
        icon: 'ic_launcher',
        message: '"\u270C Peace, Love \u2764 and PhoneGap \u2706!'
    });
    message.addNotification({
        title: 'Push Notification Sample',
        body: 'Abnormal data access',
        icon: 'ic_launcher',
        message: 'hey , how are you?'
    });


    /* message.addData('message', "\u270C Peace, Love \u2764 and PhoneGap \u2706!");

     message.addData('title', 'Push Notification Sample');

     message.addData('msgcnt', '3');*/
    // Duration in seconds to hold in GCM and retry before timing out. Default 4 weeks (2,419,200 seconds) if not specified.

    // Set up the sender with you API key
    var sender = new gcm.Sender('xxxxxxxxxxxxxxxxx-hK5wE');

    // Add the registration IDs of the devices you want to send to

    var registrationIds = [];
    registrationIds.push('APA91bEWB6-xcrfrfrffr-LqyMohLP4T-XuydQgt44Q6Acw5kmVDWvAaOsm1CriASm02SyBceZ2NBWF4FIES7grcPeY5v4fLQme2UqhRteeWRdD_Ma25QMGESOGAyw_Uhgg_EjkTl-');


    // Send the message
    // ... trying only once sendNoRetry

    sender.send(message, {
        registrationIds: registrationIds
    }, function(err, result) {
        if (err) {
            console.error(err);
            q.resolve({
                status: 200,
                data: {
                    data: err,
                    code: 1
                }
            });
        } else {
            console.log(result);
            q.resolve({
                status: 200,
                data: result
            });
        }
    });

}
return exports.execute = execute;
})();