Consume WSDL Web Service with Nusoap PHP

0

Regards, I am trying to consume a Web Service with the Nusoap library in PHP. I had worked it before but for this opportunity it is something different.

I have a Java program that is already working, but now I need to do it from the web, with php, if possible. Viewing the program in Java, I noticed that the ws requests some type of authentication, I have the user, password and token, but I do not know how to authenticate with this data using Nusoap. I hope you can help me.

This is the WS: Web Service

This is the code in PHP:

<?php
include ("lib/nusoap.php");
$wsdlIniciar = "https://dpfactura.com.co/wsFact_e/InterSoap?wsdl";

$clientIniciar=new nusoap_client($wsdlIniciar, 'wsdl');

$paramIniciar= array (
    'tokenempresa'=>'xxx',
    'usernamePt'=>'xxx',
    'passwordPt'=>'xxx',
);

$response = $clientIniciar->call('consultarEstadoFactura',$paramIniciar);

if ($clientIniciar->fault) { // si
   $error = $clientIniciar->getError();
if ($error) { // Hubo algun error
       echo 'Error:  ' . $clientIniciar->faultstring;
   }
}

echo '<hr>';
print_r($response);
echo '<hr>';
print_r($paramIniciar);

And this is the error output:

Array ( [return] => Array ( [aceptacion] => 0 [acuse] => 0 [consecutivo] => 0 [error] => Alerta! no se pudo verificar la autenticidad del cliente. [estado] => 0 [estadoAdquiriente] => 0 [estadodian] => 0 [idLote] => 0 [rechazo] => 0 ) )

This is a part of the Java code:

private static EnvioFacturaRespuestaDTO enviarFactura(co.com.dispapeles.wsdispapeles.soap.EBfelEncabezadofactura arg0) {
    co.com.dispapeles.wsdispapeles.soap.InterSoap_Service service = new co.com.dispapeles.wsdispapeles.soap.InterSoap_Service();
    co.com.dispapeles.wsdispapeles.soap.InterSoap port = service.getInterSoapPort();

    Map<String, Object> req_ctx = ((BindingProvider)port).getRequestContext();
    req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://dpfactura.com.co/wsFact_e/InterSoap?wsdl");
    Map<String, List<String>> headers = new HashMap<String, List<String>>();
    headers.put("username", Collections.singletonList("XXXXXX"));
    headers.put("password", Collections.singletonList("XXXXXX"));
    headers.put("token", Collections.singletonList("XXXXXXX"));
    req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, headers);        

    return port.enviarFactura(arg0);
}    

I appreciate if anyone has an idea how to do the authentication. Thanks!

    
asked by Jhohan Silva 06.06.2018 в 21:57
source

0 answers