Zero de experiência com soap/wsdl e preciso de consumir um web service através de php e soap/wsdl com certificado e chave privada.
Pesquisando, encontrei este código:
$local_cert = "../cert.pem";
$local_priv = "../private.key";
$wsdl = "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl";
// editado
$location = "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo";
$options = array(
'keep_alive' => true,
'trace' => true,
'location' => $location, // editado
'local_cert' => $local_cert,
'local_priv' => $local_priv,
'passphrase' => '1234567',
'cache_wsdl' => WSDL_CACHE_NONE
);
try {
$soapClient = new SoapClient($wsdl, $options);
} catch(Exception $e) {
var_dump($e);
}
Ao conectar, apresenta o seguinte erro:
object(SoapFault)#2 (9) { ["message":protected]=> string(240) "SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl' : failed to load external entity "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl" " ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(65) "/home/storage/a/7f/23/openselos/public_html/soap/teste/client.php" ["line":protected]=> int(50) ["trace":"Exception":private]=> array(1) { [0]=> array(6) { ["file"]=> string(65) "/home/storage/a/7f/23/openselos/public_html/soap/teste/client.php" ["line"]=> int(50) ["function"]=> string(10) "SoapClient" ["class"]=> string(10) "SoapClient" ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> string(78) "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl" [1]=> array(6) { ["keep_alive"]=> bool(true) ["trace"]=> bool(true) ["local_cert"]=> string(11) "../cert.pem" ["local_priv"]=> string(14) "../private.key" ["passphrase"]=> string(7) "1234567" ["cache_wsdl"]=> int(0) } } } } ["previous":"Exception":private]=> NULL ["faultstring"]=> string(240) "SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl' : failed to load external entity "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl" " ["faultcode"]=> string(4) "WSDL" }
Erro após o editado:
object(SoapFault)#2 (9) { ["message":protected]=> string(240) "SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl' : failed to load external entity "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl" " ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(65) "/home/storage/a/7f/23/openselos/public_html/soap/teste/client.php" ["line":protected]=> int(52) ["trace":"Exception":private]=> array(1) { [0]=> array(6) { ["file"]=> string(65) "/home/storage/a/7f/23/openselos/public_html/soap/teste/client.php" ["line"]=> int(52) ["function"]=> string(10) "SoapClient" ["class"]=> string(10) "SoapClient" ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> string(78) "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl" [1]=> array(7) { ["keep_alive"]=> bool(true) ["trace"]=> bool(true) ["location"]=> string(73) "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo" ["local_cert"]=> string(11) "../cert.pem" ["local_priv"]=> string(14) "../private.key" ["passphrase"]=> string(7) "1234567" ["cache_wsdl"]=> int(0) } } } } ["previous":"Exception":private]=> NULL ["faultstring"]=> string(240) "SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl' : failed to load external entity "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl" " ["faultcode"]=> string(4) "WSDL" }
O certificado usado anteriormente estava com algum tipo de problema, pois deu erro no SoapUI e após usar outro certificado, tudo funcionou. Este novo certificado, foi convertido para .pem com chave privada incluída, mas mesmo assim continua com erro.
// link wsdl
$wsdl = "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl";
// certificado
$cert = "Opensystem_A1.pem";
$cert_senha = 'senha';
$param = array(
'keep_alive' => true,
'trace' => true,
'local_cert' => $cert,
'passphrase' => $cert_senha,
'cache_wsdl' => WSDL_CACHE_NONE
);
try {
$soapClient = new SoapClient($wsdl, $param);
} catch(Exception $e) {
var_dump($e);
}
O erro:
object(SoapFault)#3 (9) { ["message":protected]=> string(240) "SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl' : failed to load external entity "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl" " ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(65) "/home/storage/a/7f/23/openselos/public_html/soap/teste/client.php" ["line":protected]=> int(52) ["trace":"Exception":private]=> array(1) { [0]=> array(6) { ["file"]=> string(65) "/home/storage/a/7f/23/openselos/public_html/soap/teste/client.php" ["line"]=> int(52) ["function"]=> string(10) "SoapClient" ["class"]=> string(10) "SoapClient" ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> string(78) "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl" [1]=> array(5) { ["keep_alive"]=> bool(true) ["trace"]=> bool(true) ["local_cert"]=> string(17) "Opensystem_A1.pem" ["passphrase"]=> string(5) "senha" ["cache_wsdl"]=> int(0) } } } } ["previous":"Exception":private]=> NULL ["faultstring"]=> string(240) "SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl' : failed to load external entity "https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl" " ["faultcode"]=> string(4) "WSDL" }