setTimezone($timezone); $isVideo = ''; $body['aps'] = array( "content-available" => 1, "data" => array( "loc-key" => "Incoming Call from 1234", "call-id" => 'b17efaa8-bb64-4b0a-9055-c72c1ea48b10', "is_video" => $isVideo, "alert" => array( "items" => array( "peer_caller_id_name" => "Demo Test", "peer_caller_id_number" => 1234, "calldate" => $datetime->format('Y-m-d H:i:s') ) ) ), "alert" => array( "items" => array( "peer_caller_id_name" => "Demo Test", "peer_caller_id_number" => 1234, "datetime" => date("Y-m-d H:i:s") ) ), "sound" => "default" ); // Encode the payload as JSON $message = json_encode($body); // open connection if (!defined('CURL_HTTP_VERSION_2_0')) { define('CURL_HTTP_VERSION_2_0', 3); } $http2ch = curl_init(); // curl_setopt($http2ch, CURLOPT_SSL_VERIFYHOST, 0); // curl_setopt($http2ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($http2ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); $headers = array( "apns-topic: {$app_bundle_id}", "User-Agent: Test", "apns-push-type : voip", "apns-expiration: 0", "apns-priority : 10" ); $status = sendHTTP2Push($http2ch, $http2_server, $apple_cert, $app_bundle_id, $message, $token, $headers); echo "Response from apple -> {$status}\n"; curl_close($http2ch); if ($status) { return true; } else { return false; } } function sendHTTP2Push($http2ch, $http2_server, $apple_cert, $app_bundle_id, $message, $token, $headers) { $milliseconds = round(microtime(true) * 1000); $url = "{$http2_server}/3/device/{$token}"; // certificate $cert = realpath($apple_cert); // other curl options curl_setopt_array($http2ch, array( CURLOPT_URL => "{$url}", CURLOPT_HTTPHEADER => $headers, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $message, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 30, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSLCERT => $cert, CURLOPT_HEADER => 1 )); $result = curl_exec($http2ch); var_dump($result); // if ($result === false) { // throw new Exception('Curl failed with error: ' . curl_error($http2ch)); // } if ($result === FALSE) { // Handle the error gracefully without throwing an exception echo 'Curl failed with error: ' . curl_error($http2ch); // Close the curl session curl_close($http2ch); // Return an appropriate status (you might want to define your own error status) return 'Curl Error'; } $status = curl_getinfo($http2ch, CURLINFO_HTTP_CODE); $duration = round(microtime(true) * 1000) - $milliseconds; return $status; } ?>