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

标签 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(): 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/

相关文章:

php - 将索引的数据添加到php中同一数组的另一个索引

php - div 溢出滚动 block 内的表格

php - Laravel 5.1 上的中间件中的 View 功能不起作用

rest - 为什么即使在使用 SSL 时也要签署 REST 查询?

php - 在 PHP 中处理 Soap 超时

php - 带 printf 的千位分隔符

firefox - 如何验证和获取众所周知的 ssl 证书?

ssl - tomcat 8.5 Centos 7 Nginx - 如何更改 War Web 应用程序的起始文件夹

java - 如何为 WebService 创建端点?

c# - 有哪些免费/公共(public)的流行网络服务?