Copy Code code as follows:
<?php
PHP needs to turn on SSL (OpenSSL) support
$apnsCert = "CK.PEM";//Certificate license file when connected to APNs, the certificate needs to be created as required
$pass = "123456";//Certificate Password
$SERVERURL = "ssl://gateway.sandbox.push.apple.com:2195";//push server, this is the development test server
$deviceToken = "a8fcd4aa8943b223d4ebcd54fe168a8b99b3f24c63dbc0612db25a8c0a588675";//ios device ID, no spaces in the middle, one ID per iOS device
$message = $_get [' message '] or $message = "hello!";
$badge = (int) $_get [' badge '] or $badge = 2;
$sound = $_get [' sound '] or $sound = "Default";
$body = Array (' APS ' => Array (' Alert ' => $message, ' badge ' => $badge, ' sound ' => $sound));
$streamContext = Stream_context_create ();
Stream_context_set_option ($streamContext, ' SSL ', ' Local_cert ', $apnsCert);
Stream_context_set_option ($streamContext, ' SSL ', ' passphrase ', $pass);
$apns = Stream_socket_client ($serverUrl, $error, $errorString, stream_client_connect| Stream_client_persistent, $streamContext);//Connect server
if ($apns) {
echo "Connection ok <br/>";
} else {
echo "Failed to connect $errorString";
Return
}
$payload = Json_encode ($body);
$msg = Chr (0). Pack (' n ', 32). Pack (' h* ', Str_replace (', ', ', $deviceToken)). Pack (' n ', strlen ($payload)). $payload;
$result = fwrite ($apns, $msg);//Send Message
Fclose ($apns);
if ($result)
echo "Sending message successfully:". $payload;
Else
Echo ' Not delivered ';
?>