使用Node JS的AWS SNS推送通知

时间:2017-01-18 05:29:45

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

我搜索过AWS文档并浪费了几个小时但却找不到使用Node JS发送推送通知的API和代码。 任何人都可以帮助在Android和iOS设备上使用Node JS发送AWS SNS推送通知吗?

2 个答案:

答案 0 :(得分:3)

使用 sns-mobile

以下示例为由PlatformApplicationArn

标识的Android应用程序创建SNS实例
var SNS = require('sns-mobile'),


 EVENTS = SNS.EVENTS;

var SNS_KEY_ID = process.env['SNS_KEY_ID'],
  SNS_ACCESS_KEY = process.env['SNS_ACCESS_KEY'],
  ANDROID_ARN = process.env['SNS_ANDROID_ARN'];

var androidApp = new SNS({
  platform: SNS.SUPPORTED_PLATFORMS.ANDROID,
  region: 'eu-west-1',
  apiVersion: '2010-03-31',
  accessKeyId: SNS_ACCESS_KEY,
  secretAccessKey: SNS_KEY_ID,
  platformApplicationArn: ANDROID_ARN,
  //sandbox: true (This is required for targetting (iOS) APNS_SANDBOX only) 
});

// Add a user, the endpointArn is their unique id 
// endpointArn is required to send messages to the device 
androidApp.addUser('some_fake_deviceid_that_i_made_up', JSON.stringify({
  some: 'extra data'
}), function(err, endpointArn) {
  if(err) {
    throw err;
  }

  // Send a simple String or data to the client 
  androidApp.sendMessage(enpointArn, 'Hi There!', function(err, messageId) {
    if(err) {
      throw err;
    }

    console.log('Message sent, ID was: ' + messageId);
  });
});

For more detail see documentation

答案 1 :(得分:2)

得到了答案。

application.properties