Php cURL无法使用客户端证书(未找到密钥或密码短语错误?)

Php cURL无法使用客户端证书(未找到密钥或密码短语错误?),php,ssl,curl,Php,Ssl,Curl,我在不同的帖子中阅读并尝试了数千种解决方案,但似乎没有一种适合我。这三个就是一个例子 我收到了一份.p12证书,我在中将其转换为.pem文件 密码是正确的,否则将无法转换 $xml = 'my xml here'; $url = 'https://qly.mbway.pt/Merchant/requestFinancialOperationWS'; $headers = array( 'Content-Type: text/xml; charset="utf-8"',

我在不同的帖子中阅读并尝试了数千种解决方案,但似乎没有一种适合我。这三个就是一个例子

我收到了一份
.p12
证书,我在中将其转换为
.pem
文件

密码是正确的,否则将无法转换

$xml = 'my xml here';
$url = 'https://qly.mbway.pt/Merchant/requestFinancialOperationWS';

$headers = array( 
    'Content-Type: text/xml; charset="utf-8"', 
    'Content-Length: ' . strlen($xml), 
    'Accept: text/xml', 
    'Cache-Control: no-cache', 
    'Pragma: no-cache'
); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSLCERT, base_url() . 'public/cert.pem');
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'my password here');
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); 

$data = curl_exec($ch); 

if(!$data)
    print_r('ERROR: ' . curl_error($ch));
else
    print_r('SUCCESS: ' . curl_error($ch));
我尝试过使用SoapUI应用程序,效果很好,但使用cURL时我收到了错误:

无法使用客户端证书(未找到密钥或密码短语错误?)

我尝试过但没有成功:

  • 禁用
    CURLOPT\u SSL\u VERIFYPEER
    和/或
    CURLOPT\u SSL\u VERIFYHOST
  • 添加
    CURLOPT\u SSLKEYTYPE
    和/或
    CURLOPT\u SSLKEY
    字段
  • 编辑1:

    除了cURL之外,我一直在尝试SOAPClient,似乎错误可能是头部

    print\r($soapClient)
    之后的标题如下:

    Host: qly.mbway.pt
    Connection: Keep-Alive
    User-Agent: PHP-SOAP/5.5.9-1ubuntu4.14
    Content-Type: application/soap+xml; charset=utf-8; action=""
    Content-Length: 1750
    
    我想知道如何删除
    操作=“”
    ?我试图扩展原始类,但在更改标题方面没有成功

    class MySoapClient extends SoapClient 
    {   
       public function __construct($wsdl, $options = array())
       {
         $ctx_opts = array('http' => array('header' => array('Content-Type' => 'application/soapyyyyyml')));
    
         $ctx = stream_context_create($ctx_opts);
    
         parent::__construct($wsdl, array('stream_context' => $ctx));
       }
    }
    

    用cURL解算

    问题是
    pem
    文件的路径

    我使用的是
    base\u url()public/cert.pem'
    ,但这是不可能的。相反,我需要使用相对路径,如
    /public/cert.pem