0

I have implemented Push notification feature in my iOS Application. Push notification message will be pushed from the backend side.

I am using Zend framework on backend side.

Now If I do online tests with push notification it works. So its sure that .pem file created correctly & on iOS side it received push messages correctly.

But while sending push message from backend from zend framework its not working. Its showing the error message like this :

Warning: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure in /home/virtual/site71/fst/var/www/html/application/configs/functions.php on line 316

Warning: stream_socket_client(): Failed to enable crypto in /home/virtual/site71/fst/var/www/html/application/configs/functions.php on line 316

Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /home/virtual/site71/fst/var/www/html/application/configs/functions.php on line 316

Here is implementation :

function sendIOS($deviceToken){
    $passphrase = '12345678';
    // Put your alert message here:
    $message = 'New stock has been added by Dividend Stock!';

    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'pushcert_new.pem');
    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
    $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
    if (!$fp)
      exit("Failed to connect: $err $errstr" . PHP_EOL);
    echo 'Connected to APNS' . PHP_EOL;
    // Create the payload body
    $body['aps'] = array(
      'alert' => array(
            'body' => $message,
        'action-loc-key' => 'dinero App',
        ),
        'badge' => 1  
      );
    // Encode the payload as JSON
    $payload = json_encode($body);
    // Build the binary notification
    $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
    // Send it to the server
    $result = fwrite($fp, $msg, strlen($msg));

    if (!$result)
      echo 'Message not delivered' . PHP_EOL;
    else
      echo 'Message successfully delivered' . PHP_EOL;

    fclose($fp);
}

Any guidance or hint will be highly appreciated.

Mayur Prajapati
  • 5,454
  • 7
  • 41
  • 70
  • I think this link help you : https://stackoverflow.com/questions/28995197/apns-php-stream-socket-client-failed-to-enable-crypto/41201588#41201588 – Gary Houbre May 10 '19 at 05:50
  • @GaryHoubre tried but didn't worked. Is it possible to check if hosting server has 2195 port blocked – Mayur Prajapati May 10 '19 at 06:55

0 Answers0