【问题标题】:Push Notification Using Amazon SNS (Node)使用 Amazon SNS(节点)的推送通知
【发布时间】:2019-08-20 04:59:00
【问题描述】:

我正在尝试在 Node.js 中使用 Amazon SNS 实施推送通知。我创建了一个主题并使用以下代码发布了一条消息

创建主题

var createTopicPromise = new AWS.SNS({apiVersion: '2010-03-31'}).createTopic({Name: "TOPIC_NAME"}).promise();

// Handle promise's fulfilled/rejected states
createTopicPromise.then(
  function(data) {
    console.log("Topic ARN is " + data.TopicArn);
  }).catch(
    function(err) {
    console.error(err, err.stack);
  });

我有一个TopicArn 类似这样的arn:aws:sns:us-east-1:xxxxxxxxxx:TOPIC_NAME

发布

// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set region
AWS.config.update({region: 'REGION'});

// Create publish parameters
var params = {
  Message: 'You Got Message!! Hello....', /* required */
  TopicArn: 'arn:aws:sns:us-east-1:xxxxxxxxxx:TOPIC_NAME'
};

// Create promise and SNS service object
var publishTextPromise = new AWS.SNS({apiVersion: '2010-03-31'}).publish(params).promise();

// Handle promise's fulfilled/rejected states
publishTextPromise.then(
  function(data) {
    console.log("Message ${params.Message} send sent to the topic ${params.TopicArn}");
    console.log("MessageID is " + data.MessageId);
  }).catch(
    function(err) {
    console.error(err, err.stack);
  });

现在消息已经发布,我需要在手机上查看。所以我使用了这样的订阅代码

    var params = {
      Protocol: 'application', /* required */
      TopicArn: 'arn:aws:sns:us-east-1:xxxxxxxxxx:TOPIC_NAME', /* required */
      Endpoint: 'MOBILE_ENDPOINT_ARN'
    };

    // Create promise and SNS service object
    var subscribePromise = new AWS.SNS({ apiVersion: '2010-03-31' }).subscribe(params).promise();

    req;
    res;
    // Handle promise's fulfilled/rejected states
    subscribePromise.then(
      function (data) {
        console.log("Subscription ARN is " + data.SubscriptionArn);
      }).catch(
        function (err) {
          console.error(err, err.stack);
        });
  }

我的问题是订阅参数中的Endpoint 是什么。我应该从哪里得到这个?到目前为止我是对的吗?请帮帮我。

【问题讨论】:

    标签: javascript node.js amazon-web-services push-notification amazon-sns


    【解决方案1】:

    此处的端点是您需要向 AWS 注册的移动应用程序的 ARN。这是官方文档中的sn-p

    为了让 Amazon SNS 向移动终端节点发送通知消息, 无论是直接订阅还是订阅某个主题,您首先需要 向 AWS 注册应用程序。

    来源:https://docs.aws.amazon.com/sns/latest/dg/mobile-push-send-register.html

    【讨论】:

    • 我不能没有 GCM 或 APNS 吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-16
    相关资源
    最近更新 更多