【问题标题】:Soap service with an ssl certificate with password (PHP)带有密码的 ssl 证书的 Soap 服务 (PHP)
【发布时间】:2016-08-29 13:18:15
【问题描述】:

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

有没有人知道我能做什么。非常感谢!

【问题讨论】:

    标签: php ssl soap wsdl codeigniter-2


    【解决方案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();
    }
    

    【讨论】:

    • 现在我有 Certificados.pem 在:Proyect Source Files application certificados Certificados.pem controllers Controller 用代码来访问服务这个路径是正确的吗? $options['local_cert'] = './certificados/Certificados.pem';我仍然有错误: 消息:SoapClient::SoapClient(): Unable to find the wrapper "https" - 您在配置 PHP 时是否忘记启用它?消息:SoapClient::SoapClient(): I/O 警告:未能加载外部实体“sedeapl.dgt.gob.es:8080/WS_IEST_COMP/…
    • @Noark 启用 php_openssl 后您是否重新启动了 Web 服务器?也尝试 file_get_contents(self::WSDL);
    • 是的,我在 XAAMP 服务器中重新启动了 Apache。使用 file_get_contents(self::WSDL);我有两个错误: 消息:file_get_contents(): Unable to find the wrapper "https" - 您在配置 PHP 时是否忘记启用它?消息:file_get_contents(sedeapl.dgt.gob.es:8080/WS_IEST_COMP/…):无法打开流:没有这样的文件或目录可能是 WSDL 不起作用?这里有官方文档:sedeapl.dgt.gob.es/IEST_INTER/MICRODATOS/webService/… 但是在西班牙语中......(它有 wsdl)
    • 所以,首先你必须解决这个问题。 openssl 尚未启用。阅读此stackoverflow.com/questions/5444249/…也许会对您有所帮助
    • 非常感谢,我会试试的。
    猜你喜欢
    • 1970-01-01
    • 2012-01-10
    • 2018-09-29
    • 2016-07-08
    • 2019-12-11
    • 2012-12-07
    • 2014-09-06
    • 2016-11-05
    • 1970-01-01
    相关资源
    最近更新 更多