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模块;

相关文章
相关标签/搜索