是否有人将Node.js与Amazon SNS和Apple Push Notifications一起使用? [英] Anyone using Node.js with Amazon SNS and Apple Push Notifications?

查看:94
本文介绍了是否有人将Node.js与Amazon SNS和Apple Push Notifications一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找将node.js与Amazon SNS和Apple APN推送通知一起使用的示例.我们使用Amazon进行托管,而我之前使用过SNS,这非常简单.但是他们具有推送通知的示例是针对Java的,而没有Node的示例.像往常一样,这使他们感到困惑,我希望减少我的研究并减少时间.没那么难.我还想知道它们如何处理错误,以及沙箱和生产之间的差异.苹果在两种环境之间的反应不同,在沙盒中不会像在生产中那样失败.

I'm looking for examples of using node.js with Amazon SNS and Apple APN push notifications. We use Amazon for our hosting, and I have used SNS before, it's pretty simple. But the examples they have for push notifications are for java, and there is no examples for Node. It's confusing, as usual with them, and I'm hoping to cut my research and time spent short. It can't be that hard. I'm also wondering how they deal with errors, and the differences between the sandbox and production. Apple reacts differently between the two environments, not failing in the sandbox as they do in production.

推荐答案

最终并没有那么困难,只是弄清楚文档是不愉快的.到目前为止,您需要在控制台中为SNS主题创建主端点,这是最简单的方法,包括证书的加载.然后,您使用createPlatformEnpoint为每个设备ID创建一个端点.这将返回另一个特定于该设备的SNS主题,然后您可以使用该主题发送消息.

It ends up not being that hard, just figuring out the documentation was unpleasant. You need to create the main endpoint for the SNS topic in the console, by far the easiest way, including the loading of the certificate. You then used createPlatformEnpoint to create an endpoint for each device id. That returns another SNS topic, specific fo that device, that you then use to send the message.

因此,以下工作可将单个消息发送到单个客户端.如果您想大量发送邮件,则不确定是否可以发送.同样不确定您如何处理Apple的反馈,应该检查发送是否失败.

So, the following works to send a single message to a single client. If you want send something en masse, not sure you can do that. Also not sure how you deal with Apple's feedback, which you are supposed to check for failed sends.

config = require("./config.js").config;

var token = "1234567898123456789";

var AWS = require('aws-sdk');

AWS.config.update({accessKeyId: config.AWSAccessKeyId, secretAccessKey: config.AWSSecretKey});
AWS.config.update({region: config.AWSRegion});

var sns = new AWS.SNS();

var params = {'PlatformApplicationArn':config["AWSTargetARN"],'Token':token};

var message = 'Test';
var subject = 'Stuff';

sns.createPlatformEndpoint(params,function(err,EndPointResult)
{
    var client_arn = EndPointResult["EndpointArn"];

    sns.publish({
    TargetArn: client_arn,
    Message: message,
    Subject: subject},
        function(err,data){
        if (err)
        {
            console.log("Error sending a message "+err);
        }
        else
        {
            console.log("Sent message: "+data.MessageId);

        }
    });
});

这篇关于是否有人将Node.js与Amazon SNS和Apple Push Notifications一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆