我从来没有住过node.js,但我现在不得不为了能够在我的iPhone应用程序中实现推送通知。如何通过PHP调用我的Apple推送通知节点脚本? (已经在ssh中工作)
我已成功创建了一个节点脚本,该脚本已成功将苹果通知推送到移动设备。
我可以通过SSH运行脚本,它工作正常。
我创建了下面的代码PHP脚本...
<?php
$output = shell_exec("/home1/devjustin/nodejs/bin/node /home1/devjustin/apns/index.js 2>&1");
print_r ($output);
?>
现在,这里是我的问题...
如果我运行通过我的浏览器,PHP脚本,我没有得到一个通知弹出在我的手机上。 php脚本实际上与节点脚本进行交互,但它似乎无法向节点脚本的最后部分发送,而没有任何解释,没有显示任何错误。
如果我通过php mobile-push.php
在ssh中运行php脚本,它就像我希望的那样工作,并且我的手机上弹出通知。
所以,过了几天,我的意思是几天,我一直没有找到解决办法。
我想知道如果也许它是我的主人。我目前通过hostgator运行共享服务器,虽然它看起来像我需要的所有权限,都在那里并且处于活动状态。
任何帮助将超级赞赏。如果你想让我举例,我很高兴。
我需要在我的应用程序中使用此功能,以便在执行操作并上载到我的服务器时,我可以向上传数据影响的用户触发推送通知。
PS:我创建了我的节点脚本一些的console.log线,他们都出现在我的浏览器中运行PHP脚本的时候,除了我周围的节点脚本的以下一段控制台打印:
// index.js
// Actually send the notification
apnProvider.send(notification, deviceToken).then(function(result) {
console.log(result);
});
Regards,
贾斯汀。
关于下面的讨论与埃德温:
console - starting
console - tokens set...
console - second last stage
console for apnProvider - EventEmitter {
client:
Client {
config:
{ token: [Object],
ca: null,
passphrase: null,
production: false,
address: 'api.development.push.apple.com',
port: 443,
rejectUnauthorized: true,
connectionRetryLimit: 10,
heartBeat: 60000 },
endpointManager:
EventEmitter {
domain: null,
_events: [Object],
_eventsCount: 2,
_maxListeners: undefined,
_endpoints: [],
_endpointIndex: 0,
_config: [Object],
_connectionFailures: 0 },
queue: [] },
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined }
//notification console output
{ encoding: 'utf8',
payload: { id: 123 },
compiled: false,
aps:
{ badge: 3,
sound: 'ping.aiff',
alert:
{ body: '[Cancelled] Friday, 4th of August at 3:00PM.',
title: 'Business Name' } },
expiry: 1501839082,
priority: 10,
topic: 'com.mybundleid.mybundleid' }
我已经跑了通过PHP脚本的strace的,这是破发点。有人能帮我理解吗?
console - tokens set...
console - second last stage
open("/proc/meminfo", O_RDONLY|O_CLOEXEC) = 10 --- SIGABRT {si_signo=SIGABRT, si_code=SI_TKILL, si_pid=26871, si_uid=638} --- +++ killed by SIGABRT +++
你在安全模式下运行php吗?也许检查这个答案从'shell_exec'手册:http://php.net/manual/en/function.shell-exec.php#118495 – Edwin
感谢提问@Edwin,我做了一个检查,安全模式是100 %折扣。 –
所以从你的编辑,似乎'shell_exec'部分工作,只有你有js..right问题? – Edwin