1
<?php
$message = 'Hello';
$badge = 3;
$sound = 'default';
$development = false;

$payload = array();
$payload['aps'] = array('alert' => $message, 'badge' => intval($badge), 'sound' => $sound);
$payload = json_encode($payload);

$apns_url = NULL;
$apns_cert = NULL;
$apns_port = 2195;

if($development)
{
    $apns_url = 'gateway.sandbox.push.apple.com';
    $apns_cert = 'pushcert.pem';
}
else
{
    $apns_url = 'gateway.push.apple.com';
    $apns_cert = 'pushcert.pem';
}

$stream_context = stream_context_create();
stream_context_set_option($stream_context, 'ssl', 'local_cert', $apns_cert);

$apns = stream_socket_client('ssl://' . $apns_url . ':' . $apns_port, $error, $error_string, 2, STREAM_CLIENT_CONNECT, $stream_context);

echo $error;
echo $error_string;
//  You will need to put your device tokens into the $device_tokens array yourself
$device_tokens = array();

foreach($device_tokens as $device_token)
{
    $apns_message = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $device_token)) . chr(0) . chr(strlen($payload)) . $payload;
    fwrite($apns, $apns_message);
}

@socket_close($apns);
@fclose($apns);
?

Errors:

Warning: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /opt/lampp/htdocs/conductexam/admin/includes/PushTest/iospush1.php on line 29

Warning: stream_socket_client(): Failed to enable crypto in /opt/lampp/htdocs/conductexam/admin/includes/PushTest/iospush1.php on line 29

Warning: stream_socket_client(): unable to connect to ssl://gateway.push.apple.com:2195 (Unknown error) in /opt/lampp/htdocs/conductexam/admin/includes/PushTest/iospush1.php on line 29 0

Community
  • 1
  • 1

0 Answers0