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

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

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

    若是你不肯定,又出現了錯誤,請先向你的服務器商詢問一下,並開啓;github

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

   在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"服務器

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

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

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

   在這裏推薦幾個我測試成功的 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:檢查你的服務器與推送程序的環境配置是否相匹配;ui

    好比個人服務器使用Apache ,程序用php 那麼 就要確認服務器 支持php 的 socket鏈接 openSSL模塊;

相關文章
相關標籤/搜索