2016-04-13 22 views
1

Ubuntu 15.10 x64 çalıştıran bir linux sunucusu kurdum. HTTP/2 kullanarak göndermek için birlikte çalışmak için php/openssl/curl kurdum. Test ettiğim PHP betiği aşağıda. Temel olarak, Apple tarafından önerildiği şekilde bağlantıyı açık tutmak için, aynı tutamları kullanarak iki itme mesajı gönderiyorum. İlk mesaj geçiyor ve cihazımda iyi görünüyor, ancak ikincisini göndermeye çalıştığında "SSL'den sonra" api.development.push.apple.com:443 bağlantısında "Bilinmeyen SSL protokol hatası" hatası alıyorum oturum kimliğini yeniden kullanma ". Neyin yanlış olabileceği konusunda herhangi bir önerisi var mı? Birisi senaryoyu deneyebilir ve aynı şeyi yaşıyorlarsa bana haber verebilir mi?APNs Sağlayıcı API HTTP/2 php kullanarak, curl birden fazla push bildirimi üzerinde hataya neden oluyor

Aşağıda sunucumdan sürüm çıktılar şunlardır:

PHP

PHP 7.0.5-2+deb.sury.org~wily+1 (cli) (NTS) 
Copyright (c) 1997-2016 The PHP Group 
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies 
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies 

OpenSSL

OpenSSL 1.0.2d 9 Jul 2015 

bukle

curl 7.48.0 (x86_64-pc-linux-gnu) libcurl/7.48.0 OpenSSL/1.0.2d zlib/1.2.8 libidn/1.28 nghttp2/1.10.0-DEV librtmp/2.3 
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp 
Features: IDN IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets 

PHP KODU:

(XXXXX ile değiştirilir kişisel eşyaları) bukle ayrıntılı kullanarak yukarıdaki senaryoyu çalışmasını
<?php 
$ch = curl_init(); 
$device_token = 'TOKEN HERE'; 
$pem_file  = 'YOURFILE.pem'; 
$pem_secret  = 'PEM PASS'; 
$apns_topic  = 'com.YOURTOPIC'; 

//curl_setopt($ch, CURLOPT_SSLVERSION, 6); 
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array("apns-topic: $apns_topic")); 
curl_setopt($ch, CURLOPT_SSLCERT, $pem_file); 
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $pem_secret); 
curl_setopt($ch, CURLOPT_VERBOSE , true); 

echo "Try 1 ================================================" . PHP_EOL; 

//setup and send first push message 
$url = "https://api.development.push.apple.com/3/device/$device_token"; 
curl_setopt($ch, CURLOPT_URL, "{$url}"); 
$sample_alert = '{"aps":{"alert":"hi #1","sound":"default"}}'; 
curl_setopt($ch, CURLOPT_POSTFIELDS, $sample_alert); 

$response = curl_exec($ch); 
$httpcode = curl_getinfo($ch); 
//var_dump($response); 
//var_dump($httpcode); 

echo "Try 2 ================================================" . PHP_EOL; 

//setup and send second push message 
$url = "https://api.development.push.apple.com/3/device/$device_token"; 
curl_setopt($ch, CURLOPT_URL, "{$url}"); 
$sample_alert = '{"aps":{"alert":"hi #2","sound":"default"}}'; 
curl_setopt($ch, CURLOPT_POSTFIELDS, $sample_alert); 

$response = curl_exec($ch); 
$httpcode = curl_getinfo($ch); 
//var_dump($response); 
//var_dump($httpcode); 

curl_close($ch); 

Çıktı:

Try 1 ================================================ 
* Trying 17.110.227.100... 
* Connected to api.development.push.apple.com (17.110.227.100) port 443 (#0) 
* ALPN, offering h2 
* ALPN, offering http/1.1 
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH 
* successfully set certificate verify locations: 
* CAfile: /etc/ssl/certs/ca-certificates.crt 
    CApath: none 
* SSL connection using TLSv1.2/XXXXXXXXXXXXXXXXXXXXXXXXXXX 
* ALPN, server accepted to use h2 
* Server certificate: 
* subject: CN=api.development.push.apple.com; OU=management:idms.group.533599; O=Apple Inc.; ST=California; C=US 
* start date: Jun 19 01:49:43 2015 GMT 
* expire date: Jul 18 01:49:43 2017 GMT 
* subjectAltName: host "api.development.push.apple.com" matched cert's "api.development.push.apple.com" 
* issuer: CN=Apple IST CA 2 - G1; OU=Certification Authority; O=Apple Inc.; C=US 
* SSL certificate verify ok. 
* Using HTTP2, server supports multi-use 
* Connection state changed (HTTP/2 confirmed) 
* TCP_NODELAY set 
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0 
* Using Stream ID: 1 (easy handle 0x555e84417f80) 
> POST /3/device/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 
HTTP/1.1 
Host: api.development.push.apple.com 
Accept: */* 
apns-topic: com.XXXXXXX.XXXXXXXXXXXXXXXXXX 
Content-Length: 43 
Content-Type: application/x-www-form-urlencoded 

* Connection state changed (MAX_CONCURRENT_STREAMS updated)! 
* We are completely uploaded and fine 
< HTTP/2.0 200 
< apns-id:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 
< 
* Connection #0 to host api.development.push.apple.com left intact 
Try 2 ================================================ 
* Found bundle for host api.development.push.apple.com: 0x555e8442afb0 [can multiplex] 
* Hostname api.development.push.apple.com was found in DNS cache 
* Trying 17.110.227.100... 
* Connected to api.development.push.apple.com (17.110.227.100) port 443 (#1) 
* ALPN, offering h2 
* ALPN, offering http/1.1 
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH 
* successfully set certificate verify locations: 
* CAfile: /etc/ssl/certs/ca-certificates.crt 
    CApath: none 
* SSL re-using session ID 
* Unknown SSL protocol error in connection to api.development.push.apple.com:443 
* Closing connection 1 
+0

SOLVED: Bunun nasıl düzeltildiğini merak eden herkes için, 7.47.1'e düşürmek zorunda kaldım: - Kabul edilen yanıtta aşağıdaki yorum konusuna bakın – casmang

cevap

2

Ben kodunuzu çalıştı ve benim makinede doğru çalışır. Yine de, ayrıntılı günlüklerimiz arasında bazı farklılıklar görüyorum. Bu benim, log 1 özdeştir deneyin ama Try 2 günlük bazı farklılıklar vardır: "bağlantısını mevcut Yeniden kullanarak"

... 
Try 2 ================================================ 
* Found bundle for host api.development.push.apple.com: 0x7fe1b380e730 [can multiplex] 
* Re-using existing connection! (#0) with host api.development.push.apple.com 
* Connected to api.development.push.apple.com (17.172.238.203) port 443 (#0) 
* Using Stream ID: 3 (easy handle 0x7fe1b305da00) 
> POST /3/device/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX HTTP/1.1 
Host: api.development.push.apple.com 
Accept: */* 
apns-topic: it.XXX.XXXXX 
Content-Length: 43 
Content-Type: application/x-www-form-urlencoded 

* We are completely uploaded and fine 
< HTTP/2.0 200 
< apns-id:XXXXXXXXXXXXXXXXX 
< 
* Connection #0 to host api.development.push.apple.com left intact 

Metin Günlüğünüzde görmüyorum ...

DÜZENLEME

çözüm 7.47.1

+0

Benim için test ettiğiniz için teşekkür ederiz! "Mevcut bağlantıyı yeniden kullanma" sorununu inceleyeceğim. Muhtemelen sunucumda yanlış yapılandırılmış bir şey var ama başka birinin aynı kodu denediğini ve farklı bir çıktı almasını görmeye gerçekten yardımcı oluyor! Teşekkür ederim! – casmang

+1

7.47.1'i kıstırmak için sürüm düşürmeyi denediniz mi? – valfer

+0

Bunu bir daha deneyeceğim. – casmang

1

Had aynı probleme curl bozmak gibi görünüyor. Kodu kazarken github paketinde bu çözümü buldum, benim için çalıştı. https://github.com/nfilin/apns-http2.

Bunu seçenekler kıvrımınıza ekleyin ve tekrar deneyin. Kabul cevap söylediği gibi

curl_setopt($ch, CURLOPT_SSLKEY, $pem_file); 
curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM'); 
0

, tüm mesajlar bir HTTP 200 kodu döndürebilir gönderilen yalnızca ama ... cur-7.47.1 sürümüne indirmek çalışır. örneğin, ikinci mesajı (ve beklendiği gibi, bir HTTP 4xx yanıt alınırsa), geçersiz veri yükü veya aygıt belirteci içeriyorsa

, üçüncü iletide api.development ile bağlantılı olarak "Bilinmeyen SSL protokol hatası elde .push.apple.com: 443" .

Beklenen davranış, ikinci iletide bir 4xx almak, ancak bağlantıyı kesmek değil.

Alt standart bir çalışma yaklaşık 200 almıyorsa kesilecek ve tekrar bağlanacaktır. Ama sanırım birçok bağlantı kesildikten/yeniden bağlantı döngüsünden sonra elma sunucusundan yasaklanacağız.

İlgili konular