我想向 APNS_SANDBOX 发送推送通知
var AWS = require('aws-sdk');
AWS.config.loadFromPath(__dirname + '/config.json');
我写了所有的凭证和地区。我确信它有效。
然后执行以下操作:
var sns = new AWS.SNS({endpoint:'https://s3.amazonaws.com'});
(实际上是错误的端点)
SNSMobilePush.prototype.pushIOS = function() {
var deviceToken = ""; // This is 64 hex characters.
var certificate = ""; // This should be in pem format with \n at the end of each line.
var privateKey = ""; // This should be in pem format with \n at the end of each line.
var applicationName = "Some app";
this.demoNotification(Platforms.APNS_SANDBOX, certificate, privateKey, deviceToken,
applicationName);
};
SNSMobilePush.prototype.demoNotification = function(platform, principal, credential, deviceToken, appName) {
var params = {
Name: appName,
Platform: platform,
Attributes: {
PlatformPrincipal: principal,
PlatformCredential: credential
}
};
sns.createPlatformApplication(params, function(err, data) {
if (err) console.log(err);
else console.log(data);
});
};
exports.pushExample = function() {
var sample = new SNSMobilePush();
sample.pushIOS('asd');
};
然后我做了以下路线:
app.get('/a', function(req, res) {
snspush.pushExample();
res.send('asd');
});
当我转到 localhost:3000/a 时,我得到以下响应:
{ [UnsignedContentSHA256NotAllowed: The provided 'x-amz-content-sha256' header must be a valid SHA256.]
message: 'The provided \'x-amz-content-sha256\' header must be a valid SHA256.',
code: 'UnsignedContentSHA256NotAllowed',
time: Sat Dec 28 2013 14:51:24 GMT+0600 (ALMT),
statusCode: 400,
retryable: false }
我的标题有什么问题?
不幸的是,节点 js 中根本没有 SNS 的工作示例。