Push notifications (iPhone) give "111 Connection failed"

When I try to send push notifications, I get this error: "Connection rejected", but I don’t know why ... I loaded my apns-dev.pem in the same directory, but this will not work either.

<?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 delete a passphrase and do not send it, it also does not work ...

+5
source share
3 answers

, .pem . ( verify_peer). , , $apnsCert - , .

, , .

+2

, 2195 . .

+6

, , : STREAM_CLIENT_ASYNC_CONNECT | STREAM_CLIENT_CONNECT

, , . , Dev- , ,

numbers numbers numbers numbers numbers numbers numbers numbers.

Spaces are deleted on this line: $ apnsMessage = chr (0). chr (0). chr (32). pack ('H *', str_replace ('', '', $ deviceToken)). chr (0). chr (strlen ($ payload)). $ Payload;

Edit: I created a problem: My server refuses the outgoing port, just sent an email, hoping that it could activate it ...

0
source

All Articles