我已经阅读并尝试了不同帖子中数千种解决方案,但似乎都没有对我有效。以下是其中三个示例。
php openssl_get_publickey()和curl - 无法使用客户端证书(未找到密钥或密码错误?)
从curl获取(58)无法使用客户端证书(未找到密钥或密码错误?)
我收到了一个.p12
证书,我将其转换为.pem
文件在https://www.sslshopper.com/ssl-converter.html
密码正确,否则它就无法转换。
$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_SSL_VERIFYPEER
和/或CURLOPT_SSL_VERIFYHOST
- 添加
CURLOPT_SSLKEYTYPE
和/或CURLOPT_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
我想知道如何删除
action=""
?我试图扩展原始类,但未能成功更改标题。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));
}
}