Copy code The code is as follows:
//php needs to enable ssl (OpenSSL) support
$ apnsCert = "ck.pem";//Certificate permission file when connecting 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 and test server
$deviceToken = "a8fcd4aa8943b223d4ebcd54fe168a8b99b3f24c63dbc0612db25a8c0a588675";//ios device id, there can be no spaces in the middle, each ios Device ID
$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, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $streamContext);//Connect to the server
if ($apns) {
echo "Connection OK
";
} 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 'Message not delivered';
?>
http://www.bkjia.com/PHPjc/327979.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327979.htmlTechArticleCopy the code as follows: ?php //php needs to enable ssl (OpenSSL) support $apnsCert = "ck.pem ";//Certificate permission file when connecting to APNS, the certificate needs to be created as required $pass = "123456";/...