一个信号推送通知

时间:2017-01-07 14:43:39

标签: node.js push-notification onesignal

如何在节点js中创建推送通知时包含小图标和大图标网址,我知道我们需要在发送推送通知时发送图片网址,我需要节点js中的代码示例..我有这个代码..

sendNotificationToSpecific =function (token,messages) {
    var sendNotification = function (data) {
        var headers = {
            "Content-Type": "application/json; charset=utf-8",
            "Authorization": "Basic MDNlMTNjYWMTgy"
        };

        var options = {
            host: "onesignal.com",
            port: 443,
            path: "/api/v1/notifications",
            method: "POST",
            headers: headers
        };

        var https = require('https');
        var req = https.request(options, function (res) {
            res.on('data', function (data) {
                console.log("Response:");
                console.log(JSON.parse(data));
            });
        });

        req.on('error', function (e) {
            console.log("ERROR:");
            console.log(e);
        });

        req.write(JSON.stringify(data));
        req.end();
    };

    var message = {
        app_id: "awer342-d744-4787-b59a-f55c6215c491",
        contents: {"en": messages},
        include_player_ids: [token],
    };

    sendNotification(message);
};

1 个答案:

答案 0 :(得分:4)

正如您在文档https://documentation.onesignal.com/reference#section-appearance中看到的那样,您可以简单地扩展您的消息对象,如

<?php

include 'dbconn.php';
require 'PHPMailerAutoload.php';

if(isset($_POST['submit'])) {

$username=$_POST['username'];
$email=$_POST['email'];

$resultSet = $con->query("INSERT INTO `contact` (`username`,`email`) 
VALUES ('$username','$email')");

$message='Variable username:'.$username.', variable email: '.$email;   
$mail = new PHPMailer;
$mail->CharSet = 'UTF-8';
$mail->addAddress($to);
$mail->Subject = 'Subject';
$mail->msgHTML($message);
$mail->WordWrap = 50;
$mail->send();

}

?>