带有带密码的 ssl 证书的 Soap 服务 (PHP)

Soap service with an ssl certificate with password (PHP)

我需要使用受密码保护的证书访问 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));

我不知道如何添加密码。这些解决方案是我在 Whosebug 上找到的。在这两个示例中,我都得到了相同的错误:

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();
}