代码之家  ›  专栏  ›  技术社区  ›  Biranchi

服务器脚本中的APN错误

  •  0
  • Biranchi  · 技术社区  · 16 年前

    在发送有效负载数据时,我在php脚本中得到了这个错误。

    Warning: stream_socket_client() [function.stream-socket-client]:
    Unable to set private key file `/Applications/XAMPP/xamppfiles/htdocs/test/apn/apns-dev.pem'
    in /Applications/XAMPP/xamppfiles/htdocs/test/apn/push.php on line 42
    
    Warning: stream_socket_client() [function.stream-socket-client]:
    failed to create an SSL handle
    in /Applications/XAMPP/xamppfiles/htdocs/test/apn/push.php on line 42
    
    Warning: stream_socket_client() [function.stream-socket-client]:
    Failed to enable crypto
    in /Applications/XAMPP/xamppfiles/htdocs/test/apn/push.php on line 42
    
    Warning: stream_socket_client() [function.stream-socket-client]:
    unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error)
    in /Applications/XAMPP/xamppfiles/htdocs/test/apn/push.php on line 42
    

    原因是什么?我需要更改任何设置吗? 我还在服务器中安装了.pem文件。

    谢谢

    3 回复  |  直到 10 年前
        1
  •  4
  •   Sangraal    16 年前

    你能发布你用来连接APN的PHP代码吗?

    黑暗中的一些镜头:
    -该.pem文件中是否同时包含证书和私钥?
    -是从私钥文件中删除了密码,还是在PHP代码中正确设置了密码?
    -运行脚本的用户是否具有访问/读取证书/密钥文件的适当Unix权限?
    -你能从你的机器上访问苹果的服务器吗?您可以通过运行telnet进行测试。

    telnet gateway.sandbox.push.apple.com 2195
    
        2
  •  4
  •   Ali Nadalizadeh    15 年前

    我遇到了这个问题,密钥生成过程就是问题所在,证书和密钥文件有两个不同的openssl命令,而我对这两个命令都使用相同的命令。以下是我如何生成证书并从私钥文件中删除密码(假设您已导出.p12文件):

    openssl pkcs12 -clcerts -nokeys -out aps-dev-cert.pem -in aps-dev-cert.p12
    openssl pkcs12 -nocerts -out aps-dev-key.pem -in aps-dev-key.p12
    openssl rsa -in aps-dev-key.pem -out aps-dev-key.unencrypted.pem
    cat aps-dev-cert.pem aps-dev-key.unencrypted.pem > aps-dev.pem
    

    注意前两个openssl命令的区别。

        3
  •  0
  •   Riesling    10 年前

    我也有这个问题。对于我来说,它在删除了ssl选项中“cipher”的显式设置后起作用:

    $context_options = [ 
        'ssl' => [ 
            'local_cert' => ..., 
            'passphrase' => ..., 
            'ciphers' => 'DES-CBC3-SHA'
        ] 
    ]; 
    stream_context_set_option($stream_context, $context_options);
    

    因此,在删除行“ciphers”=>“des-cbc3-sha”后,它起作用了。

    推荐文章