unable to connect to ssl://gateway.sandbox.push.apple.com:2195 錯誤


使用APNS 搭建蘋果推送服務器錯誤:unable to connect to ssl://gateway.sandbox.push.apple.com:2195 錯誤

1:檢查你的服務器的端口 2195是否已經開啟,是否被關閉了或是防火牆阻止了!這點很重要;

    如果你不確定,又出現了錯誤,請先向你的服務器商詢問一下,並開啟;

2:確認你的證書沒有問題:

   在mac下執行 openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert apns-dev-cert.pem -key apns-dev-key-noenc.pem -debug -showcerts -CAfile "apns-dev.pem"

   在上面進程執行完之后;可以隨便輸入一些字符串,如果關閉了,這時是正常的!如果沒有關閉,會有錯誤信息打印;說明證書有問題;

  證書生成:https://blog.serverdensity.com/how-to-build-an-apple-push-notification-provider-server-tutorial/

3:檢查你的 推送程序是否有問題; 

   在這里推薦幾個我測試成功的 php推送程序;

  •  https://github.com/blommegard/APNS-Pusher
  • https://github.com/duccio/ApnsPHP
  • https://github.com/manifestinteractive/easyapns
  • 其他:
    <?php
    
    //接收到設備發來的token,這里我手動填上。
    $deviceToken = "c9d15180ff117c6540e0f21f8c13edae6a5a437e517acbac7bb740fd33b9b069";
    //構造消息體
    $body = array("aps" => array("alert" => 'this is test from push.cocoajin.org/p.php', "badge" => 1, "sound" => 'received5.caf'));
    $ctx = stream_context_create();
    stream_context_set_option($ctx, "ssl", "local_cert", "apns-dev.pem");
    //建立socket連接
    $fp = stream_socket_client("ssl://gateway.sandbox.push.apple.com:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
    if (!$fp) { print "Failed to connect $err $errstrn"; return; }
    print "Connection OK";
    $payload = json_encode($body);
    $msg = chr(0) . pack("n",32) . pack("H*", $deviceToken) . pack("n",strlen($payload)) . $payload;
    print "sending message :" . $payload . "\n";
    fwrite($fp, $msg);
    fclose($fp);
    
    ?>
    

      

4:檢查你的服務器與推送程序的環境配置是否相匹配;

    比如我的服務器使用Apache ,程序用php 那么 就要確認服務器 支持php 的 socket連接 openSSL模塊;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM