尝试使用此php脚本,确保.pem证书在运行时以与该php脚本相同的路径退出,并获得正确的设备令牌
<?php $apnsServer = 'ssl://gateway.sandbox.push.apple.com:2195'; $privateKeyPassword = '1234'; $message = 'Welcome to iOS 7 Push Notifications'; $deviceToken = '05924634A8EB6B84437A1E8CE02E6BE6683DEC83FB38680A7DFD6A04C6CC586E'; $pushCertAndKeyPemFile = 'PushCertificateAndKey.pem'; $stream = stream_context_create(); stream_context_set_option($stream, 'ssl', 'passphrase', $privateKeyPassword); stream_context_set_option($stream, 'ssl', 'local_cert', $pushCertAndKeyPemFile); $connectionTimeout = 20; $connectionType = STREAM_CLIENT_ConNECT | STREAM_CLIENT_PERSISTENT; $connection = stream_socket_client($apnsServer, $errorNumber, $errorString, $connectionTimeout, $connectionType, $stream); if (!$connection){ echo "Failed to connect to the APNS server. Error no = $errorNumber<br/>"; exit; } else { echo "Successfully connected to the APNS. Processing...</br>"; } $messageBody['aps'] = array('alert' => $message, 'sound' => 'default', 'badge' => 2, ); $payload = json_enpre($messageBody); $notification = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload; $wroteSuccessfully = fwrite($connection, $notification, strlen($notification)); if (!$wroteSuccessfully){ echo "Could not send the message<br/>"; } else { echo "Successfully sent the message<br/>"; } fclose($connection); ?>


