带密码(PHP)的ssl证书的肥皂服务

时间:2016-05-04 08:11:08

标签: php ssl soap wsdl codeigniter-2

嗨,抱歉我的英语不好。

我需要使用受密码保护的证书来访问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():无法找到包装器“https” - 您是否忘记在配置PHP时启用它?

我在php.ini

中取消了“extension = php_openssl.dll”

我试过那些证书路线:

const LOCAL_CERT = 'certificados/Certificados.p12';
const LOCAL_CERT = 'Certificados.p12';
const LOCAL_CERT = './certificados/Certificados.p12';

任何人都知道我该怎么做。非常感谢你!

1 个答案:

答案 0 :(得分:1)

首先,您需要将.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();
}
相关问题