Ich habe eine Fehlerbehebung, wenn ich versuche, mit den APNs eine Benachrichtigung an mein iPhone zu senden. Ich verwende einen PHP-Code, die ich immer und immer wieder im Internet halten zu sehen, so dass ich glaube nicht, das Problem dabei ist:Verbotener Zugriff beim Herstellen einer Verbindung zum Apple Push Notification-Dienst
<?php
// Put your device token here (without spaces):
$deviceToken = 'mytoken'; // Of course this is my correct token here
// Put your private key's passphrase here:
$passphrase = 'mypassphrase'; // Same here
$message = $argv[1];
$url = $argv[2];
if (!$message || !$url)
exit('Example Usage: $php newspush.php \'Breaking News!\' \'https://raywenderlich.com\'' . "\n");
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', __DIR__.'/cert.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'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(
'alert' => $message,
'sound' => 'default',
'link_url' => $url,
);
// 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;
stream_set_blocking($fp, 0);
// 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);
Ich habe den Ausgang „Nachricht erfolgreich zugestellt“, so dass die Verbindung erfolgreich war eingerichtet, idem für die gesendete Nachricht. Das Gerät erhält jedoch nichts.
verwendete ich die Feedback-Funktion zu wissen, um zu versuchen, was falsch ist, aber das Ergebnis ist leer (das Array ist buchstäblich leer):
<?php
function send_feedback_request() {
//connect to the APNS feedback servers
//make sure you're using the right dev/production server & cert combo!
$stream_context = stream_context_create();
stream_context_set_option($stream_context, 'ssl', 'local_cert', __DIR__.'/cert3.pem');
stream_context_set_option($stream_context, 'ssl', 'passphrase', 'meteor0405');
$apns = stream_socket_client('ssl://feedback.sandbox.push.apple.com:2196', $errcode, $errstr, 60, STREAM_CLIENT_CONNECT, $stream_context);
if(!$apns) {
echo "ERROR $errcode: $errstr\n";
return;
}
$feedback_tokens = array();
//and read the data on the connection:
while(!feof($apns)) {
$data = fread($apns, 38);
if(strlen($data)) {
$feedback_tokens[] = unpack("N1timestamp/n1length/H*devtoken", $data);
}
}
fclose($apns);
return $feedback_tokens;
}
var_dump(send_feedback_request());
Würden Sie haben keine Ahnung, was ich tun kann, um herauszufinden, was ist falsch? Kann es an dem Zertifikat liegen? Eine CER-Datei wurde von der Apple-Website generiert und in Keychain Access importiert, um eine .p12-Datei zu erstellen. Dann habe ich es dank eines openssl-Befehls in das .pem-Format konvertiert, und dieses ist das, das ich in den Dateien unten verwende.
Vielen Dank!
Es half tatsächlich, danke! Das Problem kam tatsächlich von der PEM-Datei. Ich habe die Antwort auf das Problem für jeden mit dem gleichen Problem veröffentlicht. –
Kudos zu dir .. :) – Aparna