2017-08-04 95 views
0

我从来没有住过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 +++ 
+1

你在安全模式下运行php吗?也许检查这个答案从'shell_exec'手册:http://php.net/manual/en/function.shell-exec.php#118495 – Edwin

+0

感谢提问@Edwin,我做了一个检查,安全模式是100 %折扣。 –

+1

所以从你的编辑,似乎'shell_exec'部分工作,只有你有js..right问题? – Edwin

回答

0

此错误与授予Web用户的权限有关。我能够完全执行文件中其余代码的唯一方法就是授予root访问权限,或高于Web用户级权限。

由于这不是一个选项,我准备使用,而是取消了节点脚本,并重写了整个推送发送通知系统在PHP中,使用这三个链接,我在这里找到SO作为我的资源(incase其他人需要服务器端发送协助)。

Sending multiple iphone push notifications + APNS + PHP + Tutorial

Generate .pem file Used to setup Apple PUSH Notification

APNS PHP JSON Payload structure

我现在可以自动通过我的应用程序通过访问一个PHP脚本发送推送通知。通过这种方式,通过一些额外的PHP,用户现在可以在应用程序或Web平台上通过苹果推送通知相互交互。

Regards,

贾斯汀。