我该怎么做用PHP的SSL连接 [英] How can I do an SSL connection with PHP

查看:195
本文介绍了我该怎么做用PHP的SSL连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要开发一个PHP类,以便做推送通知(APNS)与苹果服务器进行通信。我有证书(质子交换膜),我试图按照互联网上找到各种教程,但我仍然得到错误试图连接到SSL://gateway.sandbox.push.apple.com:2195与流套接字:

I need to develop a PHP class to communicate with Apple servers in order to do Push notification (APNS). I have the certificate (.pem) and I tried to follow various tutorials found on Internet but I'm still getting error trying to connect to ssl://gateway.sandbox.push.apple.com:2195 with stream socket :

$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apns-dev.pem';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://'.$apnsHost.':'.$apnsPort, $error, $errorString, 2,
STREAM_CLIENT_CONNECT, $streamContext);

在此URL一个telnet工程,以便端口2195打开。
OpenSSL是PHP的激活,因为我得到注册的视频流套接字的Transport:TCP,UDP,SSL,SSLv3的,SSLV2,TLS用phpinfo()函数。
我的证书是博览群书(PHP is_readable(certif.pem)上的文件返回true)

A telnet on this URL works so port 2195 is opened. Openssl is activated on PHP since I get "Registered Stream Socket Transports : tcp, udp, ssl, sslv3, sslv2, tls" with a phpinfo(). My certificate is well read (PHP is_readable(certif.pem) returns true on the file)

还有其它在Apache或PHP来激活任何事情来得到它的工作?

Is there anything else to activate in Apache or PHP to get it work ?

推荐答案

找到了!问题是与该证书。由于我没有创造它自己我并没有调查,但我错了...

Found it ! Problem was with the certificate. Since I did not create it myself I wasn't investigating it but I was wrong...

我决定去重新创造它自己正常以下说明:<一href=\"http://stackoverflow.com/questions/809682/error-using-ssl-cert-with-php\">http://stackoverflow.com/questions/809682/error-using-ssl-cert-with-php和它的作品!

I decided to regenerate it myself properly following these instructions : http://stackoverflow.com/questions/809682/error-using-ssl-cert-with-php and it works !

感谢您的帮助:)

这篇关于我该怎么做用PHP的SSL连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆