2015-06-27 25 views
13

Tôi sử dụng thông báo đẩy trong ứng dụng PHP Laravel của mình. Tôi đã tạo một tệp pem và thử nghiệm nó. Khi sử dụng nó trên máy dev của tôi, nó chính xác đẩy vào thiết bị di động. Khi tôi đẩy toàn bộ dự án vào máy chủ sản xuất của mình và bắt đầu cuộc gọi pushnotif, tôi nhận được lỗi: Failed to enable cryptoLỗi thông báo đẩy mã hóa

Tôi có cần tạo tệp pem đặc biệt khi đang ở trên máy chủ sản xuất không? Và tôi không nói về "giấy chứng nhận sản xuất" Tôi vẫn muốn sử dụng sandbox để thử nghiệm

<?php 

namespace App\Helpers; 
use Carbon\Carbon; 
use Illuminate\Support\Facades\Config; 

class PushNotificationHelper { 
    public function pushToResponder($deviceToken) { 
     // Set device token of mobile device and the passphrase for certification 
     $pushToken = $deviceToken; 
     $passphrase = Config::get('MFConfig.PushNotificationTest.passPhrase'); 
     $APNS = Config::get('MFConfig.PushNotificationTest.APNS'); 

     // Open new context for streaming and set certificate as well as passphrase 
     $ctx = stream_context_create(); 
     stream_context_set_option($ctx, 'ssl', 'local_cert', '../App/Certificates/ck.pem'); 
     stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); 
     stream_context_set_option($ctx, 'ssl', 'cafile', '../App/Certificates/entrust_2048_ca.cer'); 

     // Open connection to APNS 
     $fp = stream_socket_client($APNS, $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); 

     // If no connection could be made then fail with error, otherwise connect 
     if (!$fp) { 
      exit("Failed to connect: $err, $errstr" . PHP_EOL); 
     } 

     echo 'Connected to APNS' . PHP_EOL; 

     // Create the payload body 
     $body['aps'] = array(
      'alert' => "MEDIFAKTOR Einsatz", 
      'sound' => 'default' 
     ); 

     // Encode the payload as JSON 
     $payload = json_encode($body); 

     // Build the binary notification 
     $msg = chr(0) . pack('n', 32) . pack('H*', $pushToken) . pack('n', strlen($payload)) . $payload; 

     // Send to server 
     $result = fwrite($fp, $msg, strlen($msg)); 

     // If no result is available, the message was not delivered. 
     if(!$result) { 
      echo 'Message not delivered.' . PHP_EOL; 
     } else { 
      echo 'Message successfully delivered.' . PHP_EOL; 
     } 

     // Close connection 
     fclose($fp); 

    } 
} 

Tôi đã thử nghiệm liên quan đến:

openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert ck.pem -debug -showcerts -CAfile entrust_2048_ca.cer 

và nó sẽ trả về trạng thái 0 (ok) là tốt Tôi nghĩ? nhưng khi tôi gọi chức năng tôi nhận được: failed loading cafile stream

+0

https://github.com/immobiliare/ApnsPHP/ bạn đã kiểm tra kho lưu trữ này chưa. – Ugur

Trả lời

4

Không chắc chắn về điều này, nhưng nó có thể là cài đặt php của bạn trong môi trường dev.

cố gắng tìm tệp cacert.pem.

Nếu bạn đang sử dụng hệ thống Linux, bạn có thể thử sử dụng thiết bị đầu cuối locate cacert.pem.

Khi bạn tìm địa điểm tìm thấy các tập tin php.ini và tìm dòng này:

;openssl.cafile =

và thay đổi này để openssl.cafile= đường đi từ vị cacert.pem command hoặc vị trí .pem nào là thực sự nằm.

Báo cáo lại cách hoạt động.

Các vấn đề liên quan