zoukankan      html  css  js  c++  java
  • 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 . "
      ";
      fwrite($fp, $msg);
      fclose($fp);
      
      ?>
      

        

    4:检查你的服务器与推送程序的环境配置是否相匹配;

        比如我的服务器使用Apache ,程序用php 那么 就要确认服务器 支持php 的 socket连接 openSSL模块;

  • 相关阅读:
    day54
    day53
    CAS客户端整合(四)-- Cacti
    不重新编译安装php模块的方法
    CAS客户端整合(三) Otrs
    CAS客户端整合(二) Zabbix
    CAS客户端整合(一) Discuz!
    [Django笔记] Apache + mod-wsgi 环境部署所遇到的各种问题总结
    Baidu
    Scrapy框架初探
  • 原文地址:https://www.cnblogs.com/cocoajin/p/3470673.html
Copyright © 2011-2022 走看看