0

我正在做服务器以更新通行证。现在我想向 APNS 发送通知,但它不起作用。这是来自 php_error.log 的错误: [10-Apr-2013 08:59:24 Europe/Berlin] PHP Warning: stream_socket_client(): Unable to set private key file `/Applications/MAMP/htdocs/passesWebserver/certificatePass.pem' in /Applications/MAMP/htdocs/passesWebserver/pushNotification.php on line 32
[10-Apr-2013 08:59:24 Europe/Berlin] PHP Warning: stream_socket_client(): failed to create an SSL handle in /Applications/MAMP/htdocs/passesWebserver/pushNotification.php on line 32
[10-Apr-2013 08:59:24 Europe/Berlin] PHP Warning: stream_socket_client(): Failed to enable crypto in /Applications/MAMP/htdocs/passesWebserver/pushNotification.php on line 32
[10-Apr-2013 08:59:24 Europe/Berlin] PHP Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /Applications/MAMP/htdocs/passesWebserver/pushNotification.php on line 32

//第 32 行: $tSocket = stream_socket_client('ssl://' . $tHost . ':' . $tPort, $error, $error_string, 2, STREAM_CLIENT_CONNECT, $tContext);

4

1 回答 1

0

使用您在评论中提供的代码,尝试:

$tToken = $row['pushToken']; 
$payload = json_encode (array("aps" => ""));
$tCert = '/path/to/combined/cert/and/key/file.pem';
$tPassword = 'your certificate password'; 

// Create the and config the socket context. 
$tContext = stream_context_create (); 
stream_context_set_option ($tContext, 'ssl', 'local_cert', $tCert);
if (strlen($tPassword))
    stream_context_set_option($tContext, 'ssl', 'passphrase', $tPassword);

// Compose and pack the push message
$apns_message = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $tToken)) . chr(0) . chr(mb_strlen($payload)) . $payload;

// Connect and write the push message to the connection
$ConnectAPNS = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $streamContext);
$success = fwrite($ConnectAPNS, $apns_message);

if ($success)
    error_log(date('d-m-Y hh:ii:ss', time()) . ': APNS Message successfully sent to device token' . $tToken, 0);
else
    error_log(date('d-m-Y hh:ii:ss', time()) . ': Push error:' . $err . ': ' . $errstr);
于 2013-04-10T11:05:25.057 回答