【发布时间】:2017-10-05 03:22:19
【问题描述】:
我正在尝试实现 iOS 推送通知。我的 PHP 版本停止工作,我无法让它再次工作。但是,我有一个使用 Apple 的新 Auth Key 完美运行的 node.js 脚本。我可以使用以下方法从 PHP 调用它:
chdir("../apns");
exec("node app.js &", $output);
但是,我希望能够将 deviceToken 和消息传递给它。有没有办法给脚本传参数?
这是我尝试运行的脚本 (app.js):
var apn = require('apn');
var apnProvider = new apn.Provider({
token: {
key: 'apns.p8', // Path to the key p8 file
keyId: '<my key id>', // The Key ID of the p8 file (available at https://developer.apple.com/account/ios/certificate/key)
teamId: '<my team id>', // The Team ID of your Apple Developer Account (available at https://developer.apple.com/account/#/membership/)
},
production: false // Set to true if sending a notification to a production iOS app
});
var deviceToken = '<my device token>';
var notification = new apn.Notification();
notification.topic = '<my app>';
notification.expiry = Math.floor(Date.now() / 1000) + 3600;
notification.badge = 3;
notification.sound = 'ping.aiff';
notification.alert = 'This is a test notification \u270C';
notification.payload = {id: 123};
apnProvider.send(notification, deviceToken).then(function(result) {
console.log(result);
process.exit(0)
});
【问题讨论】:
标签: javascript php ios node.js apple-push-notifications