2014-02-25 7 views
8

Ich bin ein iOS-App-Entwickler und weiß nicht viel über PHP. Ich folge raywenderlich push notification tutorial, um eine SSL-Zertifikate und einen privaten Schlüssel für Push-Benachrichtigungen zu generieren.iOS Push-Benachrichtigung senden Fehler

Ich folgte die Schritte 3-4 mal, aber es funktioniert nicht. Ich war vorher den gleichen Schritten gefolgt und es funktionierte.

Ich denke, das Problem ist in der Antwort, die ich bekomme, wenn ich die Verbindung zum APNS-Server mit SSL-Zertifikat testen. Ich komme unter Antwort.

CONNECTED(00000003) 
depth=1 /C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C 
verify error:num=20:unable to get local issuer certificate 
verify return:0 
--- 
Certificate chain 
0 s:/C=US/ST=California/L=Cupertino/O=Apple Inc./OU=iTMS Engineering/CN=gateway.sandbox.push.apple.com 
    i:/C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C 
1 s:/C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C 
    i:/O=Entrust.net/OU=www.entrust.net/CPS_2048 incorp. by ref. (limits liab.)/OU=(c) 1999 Entrust.net Limited/CN=Entrust.net Certification Authority (2048) 
--- 
Server certificate 
-----BEGIN CERTIFICATE----- 
MIIFGzCCBAOgAwIBAgIETBz90jANBgkqhkiG9w0BAQUFADCBsTELMAkGA1UEBhMC 
VVMxFjAUBgNVBAoTDUVudHJ1c3QsIEluYy4xOTA3BgNVBAsTMHd3dy5lbnRydXN0 
Lm5ldC9ycGEgaXMgaW5jb3Jwb3JhdGVkIGJ5IHJlZmVyZW5jZTEfMB0GA1UECxMW 
KGMpIDIwMDkgRW50cnVzdCwgSW5jLjEuMCwGA1UEAxMlRW50cnVzdCBDZXJ0aWZp 
Y2F0aW9uIEF1dGhvcml0eSAtI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37hR67hl8kyhNMB0GA1UdDgQWBBSgNiNR 
qtTShi8PuJ7UNUEbeE71STAJBgNVHRMEAjAAMA0GCSqGSIb3DQEBBQUAA4IBAQAS 
EDkUyBHVdRJnCLHY8w9ec92NWqBYqKiSGP0uVCvgpsJIWDBkCGIw1Olks6mQuS9+ 
R7VRJJFg7EhtufmoRIvjgntKpTe49sB/lrmiZVQGnhjd6YdyYm9+OBUWRvwketLM 
v0S+nxZD0qLLJ9foVUB8zP8LtutqFJ5IZw1xb9eSNzhpKkQ9ylj8MCd4tpXZxICL 
Gt327poTXwmjQ+31fz7HCQCowMHccP8kiKM5SeYC9q+nkmdaozHVvw4e1RsP+EWO 
vPtcH1x1BCkTJajmrO7JuRPLuBEnZGSPUVFRKWP9jy0a28VnJek+oA7rRMRD8irU 
fMGbLqkGn8YogdPqe5T1 
-----END CERTIFICATE----- 
subject=/C=US/ST=California/L=Cupertino/O=Apple Inc./OU=iTMS Engineering/CN=gateway.sandbox.push.apple.com 
issuer=/C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C 
--- 
No client certificate CA names sent 
--- 
SSL handshake has read 2731 bytes and written 2177 bytes 
--- 
New, TLSv1/SSLv3, Cipher is AES256-SHA 
Server public key is 2048 bit 
Secure Renegotiation IS supported 
Compression: NONE 
Expansion: NONE 
SSL-Session: 
    Protocol : TLSv1 
    Cipher : AES256-SHA 
    Session-ID: 
    Session-ID-ctx: 
    Master-Key: 0E813189A9AA0F93F3C996DB3D80240F742EB24656AEED9DC18043DCEDD854E9B1C4798098312EB7F6CAB23B10FF343C 
    Key-Arg : None 
    Start Time: 1393333259 
    Timeout : 300 (sec) 
    Verify return code: 0 (ok) 


Im Anfang Antwort gibt es Fehler verify error:num=20:unable to get local issuer certificate. Im späteren Teil der Antwort heißt es auch No client certificate CA names sent. Ich bin mir dieser Dinge nicht bewusst, aber ich vermute, dass das Problem mit diesen Fehlern ist.

EDIT: Fehler, den ich beim Senden von Benachrichtigungen mit Beispiel-PHP-Skript im Tutorial zur Verfügung gestellt bekommen.

Warning: stream_socket_client(): Unable to set private key file `/Users/akashpatel/Desktop/SimplePush/ck.pem' in /Users/akashpatel/Desktop/SimplePush/simplepush.php on line 25 

Warning: stream_socket_client(): failed to create an SSL handle in /Users/akashpatel/Desktop/SimplePush/simplepush.php on line 25 

Warning: stream_socket_client(): Failed to enable crypto in /Users/akashpatel/Desktop/SimplePush/simplepush.php on line 25 

Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /Users/akashpatel/Desktop/SimplePush/simplepush.php on line 25 
Failed to connect: 0 

EDIT: Mit diesem app (vorgeschlagen von Segev in seiner Antwort) Ich geprüft, ob ein Problem mit Zertifikat/privaten Schlüssel. Ich könnte eine Benachrichtigung erfolgreich erhalten. Also ich denke, Problem ist nicht mit Zertifikat/privaten Schlüssel.

PHP Script Ich verwende:

<?php 

$deviceToken = 'r34f34f5g45g5y56u76hj676elfjn4urno43f958gh945g8g7'; 

// Put your private key's passphrase here: 
$passphrase = ‘pasphrase’; 

// Put your alert message here: 
$message = 'Received push notification!'; 

//////////////////////////////////////////////////////////////////////////////// 

$ctx = stream_context_create(); 
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.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(
    'alert' => $message, 
    'sound' => 'default' 
    ); 

// 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); 

EDIT: Mein Skript funktioniert, wenn ich es in Produktionsserver verwenden. Aber ich werde diese Frage offen halten, da sie nicht auf dem lokalen Server funktioniert. Vorschläge könnten anderen helfen, für die es im Produktionsserver nicht funktioniert.

+0

Was ist Ihr ssl-Befehl? Haben Sie es versucht: openssl s_client -connect host: 443 -cert cert_and_key.pem -key cert_and_key.pem -status -debug – Radu

+0

@Radu cert_and_key.pem ist in Ihrem Befehl zweimal angegeben. Ist es richtig oder ein Fehler? Ich benutze den Befehl 'openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert Cert.pem -key Key.pem'. – Geek

+0

@Radu Ich habe versucht, den Port auf '443' zu ändern und habe einen Fehler bekommen. 'connect: Verbindung abgelehnt, connect: errno = 61'. – Geek

Antwort

1

Ich weiß nicht, was das Problem war, als ich mit PHP-Skript getestet von dem Tutorial bereitgestellt, das ich auf dem lokalen Server gefolgt bin. Aber als ich den Produktionsserver getestet habe, hat er Benachrichtigungen gesendet.

3

Es gibt so viele Dinge, die mit Push Notification schief gehen, dass Sie sie nacheinander angehen müssen.

Vergiss den PHP-Code für eine Sekunde. Gehen Sie und laden Sie die neueste Version herunter.

Dies ist eine großartige kleine App, die alle Server-Seite für Sie übernimmt und eine Push-Benachrichtigung an Ihr Gerät senden wird. Wenn das klappt, kannst du weitermachen und den PHP-Code implementieren, aber ich vermute, dass dein Problem in der App zertifikat \ key liegt.

+1

Ich habe die App heruntergeladen und eine Benachrichtigung mit demselben Zertifikat gesendet. Ich habe eine Benachrichtigung erhalten. Jetzt bedeutet es, dass Zertifikat und Schlüssel in Ordnung sind. Was können andere Probleme sein? BTW Danke und +1 für den Link zur App. Zumindest weiß ich, dass ich sie nicht neu erstellen muss, um zu sehen, ob ein Problem mit ihnen ist. – Geek

+0

Danke für tolle kleine App zum Testen der Einrichtung :) – Nitin

5

Siehe den Fehler:

CONNECTED(00000003) depth=1 /C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C verify error:num=20:unable to get local issuer certificate verify return:0

Sehen Sie, wie Sie den Kontext gesetzt angewendet Option zu streamen:

$ctx = stream_context_create(); 
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem'); 
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); 

ich das gleiche Tutorial, wie Sie, lesen Sie 3, um die Kugel # auf der troobleshooting Abschnitt verwendet

Unable to get local issuer certificate. This error means that the certificate from the server could not be verified. To fix this you need to download the Entrust CA root certificate. This can be done from the Terminal using the command: curl -O https://www.entrust.net/downloads/binary/entrust_2048_ca.cer You then also need to add stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');

Herunterladen entrust_2048_ca.cer

012.351.

Stellen Sie sicher, dass sich alle Zertifikate im selben Verzeichnis wie das PHP-Skript befinden.

Ihr Code wie folgt ändern:

//applying context to stream option 
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem'); 
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); 
stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer'); 

Sie sollten jetzt gut sein.

+0

Ich hätte in meiner Frage erwähnt werden sollen. Das habe ich schon probiert. Aber nicht funktioniert. – Geek

+0

sind Sie verfügbar für [Chat] (http://chat.stackoverflow.com/rooms/48430/discussion-between-geek-and-radu) – meda

+0

Ja, ich bin verfügbar. – Geek