티스토리 뷰

모바일 프로그래밍

Android FCM Node.js 발송 예제

두덕리온라인 2018. 6. 15. 16:54
728x90
반응형
var request = require('request');

var url = 'https://fcm.googleapis.com/fcm/send';
var apikey = 'AAAA3WrrgCQ:APA91bHQnxgfAP4hurrF3OyBGla-oU3IO3cU9L6BmAvlmm1Ifbm130tTCqttTU2nJiOI4Q5_0-mdz5ht-d_6hLTW9XqvE1TDfIHTYOhsHipFNjwDNnKNRoKl7gnztok2_ZJC45j2k???';

//fcm
var token = 'dJvWJi4Kwss:APA91bGyIma2jGAXvAGV75zlEhY9fo8ev0QFUevFy5tIY6aazHQIImHUdOkuMdzWESGUgjULB2Swy-o4Q07k_37PqZ8-9WXqE1gwko4Z2v3Mw55PjR1qBghd0JCEPFMWnikkAQp7_???';

var options = {
    method: 'POST',
    url: url,
    headers: {
        'Content-Type': 'application/json',
        'Authorization': `key=${apikey}`
    },
    body: JSON.stringify({
        to: token,
        priority: 'high',
        notification: {
            body: 'Background message',
            title: 'BG title'
        },
        data: {
            title: 'FG title',
            message: 'Foreground message'
        }
    })
};

console.log(options);

request(options, function (err, res, body) {
    if (!err) {
        console.log(body);
        console.log(res.statusCode);
    } else {
        console.log(err);
    }
});


반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday