Apple 推送通知反馈服务的 PHP 脚本每次都会超时,
大家好! 我目前正在为苹果推送通知实现反馈服务。我已经完成了推送部分,并在沙箱和分发应用程序上工作。然而反馈服务似乎不起作用..每次我尝试使用我的功能..页面很好..只是超时。
我按照这个答案来实现我的功能: PHP 技术查询 APNs 反馈服务器
这是我的完整功能代码:
function checkFeedbackServer($appBundle,$useDev = TRUE)
{
$apnsPort = 2195;
$apnsCert = keyForApp($appBundle,$useDev);
if($useDev)
{
echo 'FEEDBACK in DEVELOPER MODE <br/>';
$apnsHost = 'feedback.sandbox.push.apple.com';
}
else
{
echo 'FEEDBACK in DISTRIBUTION MODE <br/>';
$apnsHost = 'feedback.push.apple.com';
}
$finalPath = 'ssl://' . $apnsHost . ':' . $apnsPort;
echo 'OPENING STREAM TO -> ' . $finalPath . '<br/>';
echo 'USING CERT : ' . $apnsCert . "<br/>";
$stream_context = stream_context_create();
stream_context_set_option($stream_context, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client($finalPath, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $stream_context);
if(!$apns)
{
echo "ERROR $errcode: $errstr\n";
return;
}
else echo 'APNS FEEDBACK CONNECTION ESTABLISHED...<br/>';
$feedback_tokens = array();
$count = 0;
echo 'error= ' . $error . '<br/>';
echo 'errorString= ' . $errorString . '<br/>';
if(!feof($apns))
echo 'APNS NOT FINISHED <br/>';
else
echo 'APNS FINISHED? <br/>';
$result = fread($apns, 38);
echo 'result= ' . $result;
fclose($apns);
}
我注意到,如果我删除这些行:
$result = fread($apns, 38);
echo 'result= ' . $result;
该功能就可以正常工作。因此,在 nuthsell 中,我能够打开与生产和开发人员的反馈服务的连接,但一旦我尝试从服务器获取任何数据,我的脚本就会超时。
还有函数 keyForApp($appBundle, $useDev)
只是一个简单的包装器,用于对我的数据库进行查询,以获取正确的证书。我保证它可以工作,因为我在向设备推送消息时也在使用它。
Greetings everyone!
I'm currently implementing the Feedback service for Apples Push notifications. I've got the pushing part all done and working both on sandbox and on distribution apps. However the feedback service seems to not work.. Each time i try to use my function.. the page well.. just gets a timeout.
I followed this answer to make my function : PHP technique to query the APNs Feedback Server
Here is my full function code :
function checkFeedbackServer($appBundle,$useDev = TRUE)
{
$apnsPort = 2195;
$apnsCert = keyForApp($appBundle,$useDev);
if($useDev)
{
echo 'FEEDBACK in DEVELOPER MODE <br/>';
$apnsHost = 'feedback.sandbox.push.apple.com';
}
else
{
echo 'FEEDBACK in DISTRIBUTION MODE <br/>';
$apnsHost = 'feedback.push.apple.com';
}
$finalPath = 'ssl://' . $apnsHost . ':' . $apnsPort;
echo 'OPENING STREAM TO -> ' . $finalPath . '<br/>';
echo 'USING CERT : ' . $apnsCert . "<br/>";
$stream_context = stream_context_create();
stream_context_set_option($stream_context, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client($finalPath, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $stream_context);
if(!$apns)
{
echo "ERROR $errcode: $errstr\n";
return;
}
else echo 'APNS FEEDBACK CONNECTION ESTABLISHED...<br/>';
$feedback_tokens = array();
$count = 0;
echo 'error= ' . $error . '<br/>';
echo 'errorString= ' . $errorString . '<br/>';
if(!feof($apns))
echo 'APNS NOT FINISHED <br/>';
else
echo 'APNS FINISHED? <br/>';
$result = fread($apns, 38);
echo 'result= ' . $result;
fclose($apns);
}
I noticed that if i remove the lines :
$result = fread($apns, 38);
echo 'result= ' . $result;
The function then works properly. So in a nuthsell I am able to open a connection to the feedback service both production and developer but as soon as I try to get any data from the server my script just times out..
also the function keyForApp($appBundle,$useDev)
is just a simple wrapper around a query to my database that fetches the correct certificate. I guarante it works since I am also using it while pushing messages to the device.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了..原来我的端口错误。
澄清一下:
我的不好......;)我将两者混合在一起并在端口2195上连接到反馈服务器而不是 2196
Solved it.. Turns out I had the wrong port.
To clarify :
my bad..;) I mixed the two together and was connecting to the feedback server on port 2195 instead of 2196