Ios push notification php sample code

I tried to send ios push notification in php sample code but getting error of Failed to connect: 111 Connection refused pls help me.
Deepak Sharma
Asked 14-03-2024
592

Answer (1)
  Hi try this php code... public function sendiOSNotification($registatoin_ids=null,$notification=null){             $deviceToken = '7eea2901746f503a94f8160d4932aa89e5091d5002ddc5a958c715d69a27e11a';           /*     ssl://gateway.sandbox.push.apple.com:2195 - development             ssl://gateway.push.apple.com:2195 - production. */                    $ctx = stream_context_create();         // ck.pem is your certificate file         stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');         stream_context_set_option($ctx, 'ssl', 'passphrase', 'testing');         // Open a connection to the APNS server         $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);         // Create the payload body         $body['aps'] = array(             'alert' => array(                 'title' =>'title',// $notification['Title'],                  'body' => 'body',//$notification['Body'],                 'type' => 'testing',//$notification['Type'],             ),             'sound' => 'default'         );         // 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));                      // Close the connection to the server         fclose($fp);                      if (!$result){                     return 'Message not delivered' . PHP_EOL;         }         else{        return 'Message successfully delivered' . PHP_EOL;          }     } Note : Give Correct path of ck.pem file for local_cert. Note : Give correct passphrase certificate password. Note : Production URL :  ssl://gateway.push.apple.com:2195 Note : Development URL : ssl://gateway.sandbox.push.apple.com:2195
Ankur Rajput
Asked 15-09-2018
45 Likes
Comments
Write comment

Submit your answer