Patrick PHP多线程 PHP-CURL携带证书请求HTTPS

PHP-CURL携带证书请求HTTPS

  
  php中的curl请求只支持pem、der、eng格式的证书,所以如果证书不是以上几种格式的话,就需要转换格式了。

1
2
3
4
openssl pkcs12 -nocerts -nodes -in yunyin.p12 -out yunyin_private.pem 
openssl pkcs12 -clcerts -nokeys -in yunyin.p12 -out cert_public.pem //公钥
//合并公钥私钥
openssl pkcs12 -in yunyin.p12 -out yunyin.pem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$url = 'https://frmmo1.my4399.com/f2_admin/index.php';
define("CERT", './yunyin.pem');
function _postCert($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSLCERT, CERT);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, '1234');
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM');
//curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$response = curl_exec($ch);
if(!$response){
echo curl_error($ch);
}
return $response;
}

var_dump(_postCert($url));