我需要使用受密码保护的证书访问 SOAP 服务。我是 PHP 新手(CodeIgniter 2 中的 PHP 5.4),并且尝试了一些对我不起作用的选项。
我有以下常量:
const WSDL = 'https://sedeapl.dgt.gob.es:8080/WS_IEST_COMP/descargaArchivoMicrodatosService?wsdl';
const XMLNS = 'https://sedeapl.dgt.gob.es:8080/WS_IEST_COMP/descargaArchivoMicrodatosService';
const LOCAL_CERT_PASSWD = 'HERE I HAVE THE PASS OF THE CERT';
const LOCAL_CERT = './certificados/Certificados.p12';
private $client;
我尝试过以下选项:
选项A
$this->client = new SoapClient(self::WSDL, array(
"trace" => 1,
"exceptions" => true,
"local_cert" => self::LOCAL_CERT,
"uri" => "urn:xmethods-delayed-quotes",
"style" => SOAP_RPC,
"use" => SOAP_ENCODED,
"soap_version" => SOAP_1_2 ,
"location" => self::XMLNS
)
);
选项B
$this->$client = new SoapClient(self::WSDL, array('local_cert' => self::LOCAL_CERT));
我不知道如何添加密码。这些解决方案是我在 StackOverflow 上找到的。在这两个示例中我都得到相同的错误:
SoapClient::SoapClient(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?
我取消了 php.ini 中“extension=php_openssl.dll”的注释
我尝试过这些证书路线:
const LOCAL_CERT = 'certificados/Certificados.p12';
const LOCAL_CERT = 'Certificados.p12';
const LOCAL_CERT = './certificados/Certificados.p12';
有人知道我能做什么吗?非常感谢!
最佳答案
首先您需要将 .p12 转换为 .pem
在Linux中你可以使用以下命令来完成
openssl pkcs12 -in Certificados.p12 -out Certificados.pem -clcerts
然后尝试以下操作:
$options = array();
$options['trace'] = true;
$options['exceptions'] = true;
$options['local_cert'] = 'path to your .pem file';
$options['passphrase'] = self::LOCAL_CERT_PASSWD;
try {
$soapClient = new SoapClient(self::WSDL, $options);
echo '<pre>';
// wsdl methods
print_r($soapClient->__getFunctions());
echo '</pre>';
}
catch (Exception $e)
{
echo $e->getMessage(), '<br />', $e->getTraceAsString();
}
关于php - 带有 ssl 证书和密码的 Soap 服务 (PHP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37022017/