iOS推送通知不适用于PHP服务器
我打开了端口,并在服务器中创建和存储了证书。我使用以下代码:iOS推送通知不适用于PHP服务器,php,ios,push-notification,Php,Ios,Push Notification,我打开了端口,并在服务器中创建和存储了证书。我使用以下代码: public function send_mobile_notification_request() { // Put your device token here (without spaces): $deviceToken = '0A01703BDB53E5852F65D0B651BC79003ADDB6B3497D456EF63B6402E07C0475'; // Put you
public function send_mobile_notification_request()
{
// Put your device token here (without spaces):
$deviceToken = '0A01703BDB53E5852F65D0B651BC79003ADDB6B3497D456EF63B6402E07C0475';
// Put your private key's passphrase here:
$passphrase = '';
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'pushcert.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// 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);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'content-available' => '1',
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
// Close the connection to the server
fclose($fp);
}
我得到的是“消息成功传递”的消息,因此它显然有效,但我没有收到任何消息。我还使用一些push notifications sender程序检查证书是否正常工作,并在那里收到通知。最糟糕的是,我没有得到任何错误,所以我不知道该怎么解决它 您正在连接到
gateway.sandbox.push.apple.com
您确定使用的是开发证书和产品吗?我可以向您推荐我使用的这个APN库:它有格式良好的异常处理程序,将帮助您找出错误。我使用gateway.sandbox.push.apple.com和gateway.push.apple.com进行了测试,以防万一,但我创建了一个开发证书。您可以在最后执行echo$result吗?“连接到APNS 97”是我对$result进行回显时得到的结果。您连接到gateway.sandbox.push.apple.com
您确定吗您正在使用开发证书和产品?我可以向您推荐我使用的APN库:它具有格式良好的异常处理程序,将帮助您找出问题所在。我使用gateway.sandbox.push.apple.com和gateway.push.apple.com进行了测试,以防万一,但我创建了一个开发证书。您可以在最后执行echo$result吗?“连接到APNS 97”是我对$result进行echo时得到的结果