离子推送的后端服务



我已经使用pushwoosh实现了离子推送通知。但在那里,我使用pushwoosh提供的仪表板发送推送通知。我想用我自己创建的后端发送推送通知。我该怎么做?

我正在ionic-framework上工作,还使用推送通知通过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;
})();

相关内容

  • 没有找到相关文章

最新更新