Я попытался с приведенным ниже кодом для отправки push-уведомлений ios для нескольких устройств (это работает для одного устройства, если я использую без цикла).
$devices = array();// Minimum 2k device ids
$ctx = stream_context_create();
// ck.pem is your certificate file
stream_context_set_option($ctx, 'ssl', 'local_cert', $_SERVER['DOCUMENT_ROOT']."/assets/ck.pem");
//stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', 'key');
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
/* $fp = stream_socket_client(
'ssl://gateway.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); */
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
// Create the payload body
$body['aps'] = array(
'alert' => array(
'title' => $msg1['title'],
'body' => $msg1['message']
),
'vibrate' => 0,
'sound' => 'sound'
);
$results = array();
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
foreach($devices as $device){
if(strlen($device) == 64) {
$msg = chr(0) . pack('n', 32) . pack('H*', $device) . pack('n', strlen($payload)) . $payload;
try {
$results[] = fwrite($fp, $msg, strlen($msg));
}catch (Exception $ex) {
// try once again for socket busy error (fwrite(): SSL operation failed with code 1.
// OpenSSL Error messages:\nerror:1409F07F:SSL routines:SSL3_WRITE_PENDING)
sleep(5); //sleep for 5 seconds
$results[] = fwrite($fp, $msg, strlen($msg));
}
}
}
// Close the connection to the server
fclose($fp);if (empty($results))
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
Но это возвращает ниже ошибки, пожалуйста, помогите кому-нибудь, чтобы добиться успеха от этого
A PHP Error was encountered
Severity: Warning
Message: fwrite(): SSL: An existing connection was forcibly closed by the remote host.
Filename: controllers/C_booking.php
Line Number: 265
A PHP Error was encountered
Severity: Warning
Message: fwrite(): SSL operation failed with code 1. OpenSSL Error messages: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry
Filename: controllers/C_booking.php
Line Number: 265
A PHP Error was encountered
Severity: Warning
Message: fwrite(): SSL: An established connection was aborted by the software in your host machine.
Filename: controllers/C_booking.php
Line Number: 265
Задача ещё не решена.
Других решений пока нет …