[英]Push notifications (iPhone) give “111 Connection refused”
When I try to send Push Notifications I get this error: "Connection refused", but I don't know why... I've uploaded my apns-dev.pem in the same directory as well in the root-directory but that won't work either. 当我尝试发送推送通知时,我收到此错误:“连接被拒绝”,但我不知道为什么...我已将我的apns-dev.pem上传到根目录中的同一目录中但是也不行。
<?php
$payload['aps'] = array('alert' => 'This is the alert text', 'badge' => 1, 'sound' => 'default');
$payload = json_encode($payload);
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apns-dev.pem';
$apnsPass = 'secret';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
stream_context_set_option($streamContext, 'ssl', 'passphrase', $apnsPass);
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 60, STREAM_CLIENT_CONNECT, $streamContext);
if (!$apns) {
echo "Error: $errorString ($error)";
}
// Do this for each
$deviceToken = '00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000';
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;
fwrite($apns, $apnsMessage);
// End do
socket_close($apns);
fclose($apns);
?>
Does anyone know what I'm doing wrong? 有谁知道我做错了什么? When I remove the passphrase and don't send it it doesn't work either...
当我删除密码并且不发送密码时它也不起作用......
确保传出端口2195已打开。这将在您的防火墙配置中。
You don't want a passphrase unless your .pem file requires one. 除非.pem文件需要密码,否则您不需要密码。 The connection requires peer verification (option verify_peer) turned on.
连接需要打开对等验证(选项verify_peer)。 Also, make sure $apnsCert is the valid path to the certificate, you can use an absolute path as a sanity check.
另外,确保$ apnsCert是证书的有效路径,您可以使用绝对路径作为完整性检查。
Lastly, this shouldn't effect your ability to connect, but your device token needs to be valid. 最后,这不应影响您的连接能力,但您的设备令牌必须有效。
I've know fixed that error by adding this: STREAM_CLIENT_ASYNC_CONNECT|STREAM_CLIENT_CONNECT 我已经知道修复了这个错误:STREAM_CLIENT_ASYNC_CONNECT | STREAM_CLIENT_CONNECT
Know I'm not getting any errors, but I don't receive any notification. 知道我没有收到任何错误,但我没有收到任何通知。 I think the Dev-token is not valid know, so, this is how it look like
我认为Dev-token无效,所以,这就是它的样子
numbers numbers numbers numbers numbers numbers numbers numbers. 数字数字数字数字数字数字。
The spaces are removed in this line: $apnsMessage = chr(0) . 这行中删除了空格:$ apnsMessage = chr(0)。 chr(0) .
chr(0)。 chr(32) .
chr(32)。 pack('H*', str_replace(' ', '', $deviceToken)) .
pack('H *',str_replace('','',$ deviceToken))。 chr(0) .
chr(0)。 chr(strlen($payload)) .
chr(strlen($ payload))。 $payload;
$有效载荷;
Edit: I founded the problem: My server is refusing the outgoing port, just sent a mail, hoping they can activate it... 编辑:我创建了问题:我的服务器拒绝传出端口,只是发送邮件,希望他们可以激活它...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.