Я знаю, что это уже эксплуатируемая тема на SO, но я борюсь с конкретной конфигурацией.Отправить push-уведомление через PHP
Я использую выделенный сервер для отправки push-уведомлений на устройства ios. С этого сервера я могу успешно соединиться через Telnet к шлюзу APNS:
[[email protected] luca]# telnet gateway.sandbox.push.apple.com 2195
Trying 17.110.227.35...
Connected to gateway.sandbox.push.apple.com.
Escape character is '^]'.
Я правильно сгенерировал сертификат ЦС и комбинированную сертификат и ключ от яблока, и я могу проверить соединение с OpenSSL, используя их правильно:
Я также могу использовать Mac Os X Pusher для успешной отправки push-уведомлений с использованием этих сертификатов из моей коробки разработки.
Я пытался использовать ApnsPHP, используя модифицированную версию своего образца кода:
<?php
// Adjust to your timezone
date_default_timezone_set('Europe/Rome');
// Report all PHP errors
error_reporting(-1);
// Using Autoload all classes are loaded on-demand
require_once 'ApnsPHP/ApnsPHP/Autoload.php';
// Instantiate a new ApnsPHP_Push object
$push = new ApnsPHP_Push(
ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
/*'server_certificates_bundle_sandbox.pem'*/
'server_certificates_bundle_sandbox.pem'
);
// Set the Provider Certificate passphrase
$push->setRootCertificationAuthority('entrust_2048_ca.cer');
// Connect to the Apple Push Notification Service
$push->connect();
// Instantiate a new Message with a single recipient
$message = new ApnsPHP_Message('5ad1fafb8efdec85fc3e51ea0075d342d18bad9e56cf3e014b56ea9fc4f184bd');
// Set a custom identifier. To get back this identifier use the getCustomIdentifier() method
// over a ApnsPHP_Message object retrieved with the getErrors() message.
$message->setCustomIdentifier("Message-Badge-3");
// Set badge icon to "3"
$message->setBadge(3);
// Set a simple welcome text
$message->setText('Hello APNs-enabled device!');
// Play the default sound
$message->setSound();
// Set a custom property
$message->setCustomProperty('acme2', array('bang', 'whiz'));
// Set another custom property
$message->setCustomProperty('acme3', array('bing', 'bong'));
// Set the expiry value to 30 seconds
$message->setExpiry(30);
// Add the message to the message queue
$push->add($message);
// Send all messages in the message queue
$push->send();
// Disconnect from the Apple Push Notification Service
$push->disconnect();
// Examine the error message container
$aErrorQueue = $push->getErrors();
if (!empty($aErrorQueue)) {
var_dump($aErrorQueue);
}
?>
Это приводит к ошибке при вызове из консоли:
[[email protected] luca]# php index.php
Wed, 22 Jul 2015 13:30:47 +0200 ApnsPHP[19972]: INFO: Trying tls://gateway.sandbox.push.apple.com:2195...
Wed, 22 Jul 2015 13:30:47 +0200 ApnsPHP[19972]: ERROR: Unable to connect to 'tls://gateway.sandbox.push.apple.com:2195': (0)
Wed, 22 Jul 2015 13:30:47 +0200 ApnsPHP[19972]: INFO: Retry to connect (1/3)...
Wed, 22 Jul 2015 13:30:48 +0200 ApnsPHP[19972]: INFO: Trying tls://gateway.sandbox.push.apple.com:2195...
Wed, 22 Jul 2015 13:30:49 +0200 ApnsPHP[19972]: ERROR: Unable to connect to 'tls://gateway.sandbox.push.apple.com:2195': (0)
Wed, 22 Jul 2015 13:30:49 +0200 ApnsPHP[19972]: INFO: Retry to connect (2/3)...
Wed, 22 Jul 2015 13:30:50 +0200 ApnsPHP[19972]: INFO: Trying tls://gateway.sandbox.push.apple.com:2195...
Wed, 22 Jul 2015 13:30:50 +0200 ApnsPHP[19972]: ERROR: Unable to connect to 'tls://gateway.sandbox.push.apple.com:2195': (0)
Wed, 22 Jul 2015 13:30:50 +0200 ApnsPHP[19972]: INFO: Retry to connect (3/3)...
Wed, 22 Jul 2015 13:30:51 +0200 ApnsPHP[19972]: INFO: Trying tls://gateway.sandbox.push.apple.com:2195...
Wed, 22 Jul 2015 13:30:52 +0200 ApnsPHP[19972]: ERROR: Unable to connect to 'tls://gateway.sandbox.push.apple.com:2195': (0)
Это довольно странно, я попробовал несколько незначительных исправлений, в том числе в разделе verify_peer в Abstract.php, но никто не работал. Я что-то упустил, есть ли у вас какая-нибудь идея о том, как это исправить?
Я отправил push-уведомление от Java и Python некоторое время, поэтому я вполне уверен в этом процессе. В любом случае, это мой первый раз с PHP.
Поддерживает ли ваш PHP поддержку SSL и TLS? – Hedam
http://elbuild.com/luca/info.php Я считаю, что это так. Я прав? – elbuild
Да, у него есть поддержка TLS и SSL. – Hedam