SOAP error after changing php from 5.3 to 5.5

0

Good afternoon, I ran a php upgrade on my server and one of my scripts stopped working. Error presented is this:

  thrown in /home/brewhead/public_html/catalog/model/shipping/jadlog5.php on line 65
[07-Dec-2016 21:13:08 America/Sao_Paulo] PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://jadlog.com.br/JadlogEdiWs/services/ValorFreteBean?wsdl' : failed to load external entity "http://jadlog.com.br/JadlogEdiWs/services/ValorFreteBean?wsdl"
 in /home/brewhead/public_html/catalog/model/shipping/jadlog5.php on line 65
[07-Dec-2016 21:13:08 America/Sao_Paulo] PHP Fatal error:  Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://jadlog.com.br/JadlogEdiWs/services/ValorFreteBean?wsdl' : failed to load external entity "http://jadlog.com.br/JadlogEdiWs/services/ValorFreteBean?wsdl"
 in /home/brewhead/public_html/catalog/model/shipping/jadlog5.php:65
Stack trace:
#0 /home/brewhead/public_html/catalog/model/shipping/jadlog5.php(65): SoapClient->SoapClient('http://jadlog.c...')
#1 /home/brewhead/public_html/catalog/controller/checkout/shipping.php(143): ModelShippingJadlog5->getQuote(Array)
#2 [internal function]: ControllerCheckoutShipping->quote(Array)
#3 /home/brewhead/public_html/system/modification/system/engine/action.php(65): call_user_func(Array, Array)
#4 /home/brewhead/public_html/system/engine/front.php(34): Action->execute(Object(Registry))
#5 /home/brewhead/public_html/system/engine/front.php(29): Front->execute(Object(Action))
#6 /home/brewhead/public_html/index.php(265): Front->dispatch(Object(Action), Object(Action))
#7 {main}
  thrown in /home/brewhead/public_html/catalog/model/shipping/jadlog5.php on line 65

I tried to change the script several times but could not solve the problem.

Follow my script that does the soap request:

    $cost = 0;

    //dados do carrinho e calcula as medidas
    $pais = $address['iso_code_2'];

    $tiposFrete = array('Expresso'=>0,'Package'=>3,'Rodoviario'=>4,'Economico'=>5,'DOC'=>6,'Corporate'=>7,'.COM'=>9,'Cargo'=>12);

    $soapClient = new SoapClient("http://jadlog.com.br/JadlogEdiWs/services/ValorFreteBean?wsdl");

    foreach($tiposFrete AS $k=>$v){
        $tipos = $this->config->get('jadlog5_tipos');
        if((!empty($tipos) && in_array($v,$tipos))){

            $peso_cubado = $this->pesoCubado($v);
            $fator_cubagem = $this->vCubagem[$v];
            if($fator_cubagem=='6000'){
                $prazo = $this->config->get('jadlog5_prazoa');
            }else{
                $prazo = $this->config->get('jadlog5_prazo');
            }

        //regra do maior peso
            $weight = number_format($this->cart->getWeight()/1000, 2, '.', '');
        //echo $peso_cubado." | ".$weight;
            if($weight>$peso_cubado){
                $peso_cubado=$weight;
            }

        //if($weight>$peso_cubado){
            //$peso_cubado = $weight/1000;
        //}
        //print("$peso_cubado | $weight");

            $default = array('cep_origem' => preg_replace('/\D/', '', $this->config->get('jadlog5_cep')),
                'cep_destino' => preg_replace('/\D/', '', $address['postcode']),
                'peso' => number_format($peso_cubado, 2, ',', ''),
                'valor' => number_format($this->cart->getSubTotal(), 2, ',', ''),
                'modalidade' => $v,
                'cnpj' => trim($this->config->get('jadlog5_user')),
                'password' => trim($this->config->get('jadlog5_senha')),
                'seguro' => 'S',
                'coleta' => number_format($this->config->get('jadlog5_coleta'), 2, ',', ''),
                'acobrar' => ($this->config->get('jadlog5_frete')==0?'N':'S'),
                'entrega' => ($this->config->get('jadlog5_entrega')==0?'D':'R'));

            $consulta['vModalidade']          =    $default['modalidade'];
            $consulta['Password']             =    $default['password'];
            $consulta['vSeguro']              =    $default['seguro'];
            $consulta['vVlDec']               =    $default['valor'];
            $consulta['vVlColeta']            =    $default['coleta'];
            $consulta['vCepOrig']             =    $default['cep_origem'];
            $consulta['vCepDest']             =    $default['cep_destino'];
            $consulta['vPeso']                =    $default['peso'];
            $consulta['vFrap']                =    $default['acobrar'];
            $consulta['vEntrega']             =    $default['entrega'];
            $consulta['vCnpj']                =    $default['cnpj'];
        //echo "<pre>";
        //print_r($consulta);
        //echo "</pre>";
            try { 
                $info = $soapClient->__call("valorar", array($consulta)); 
                $calculo = json_decode(json_encode(@simplexml_load_string($info->valorarReturn)),true); 
                if(isset($calculo['Jadlog_Valor_Frete']['Retorno'])){
                    if($calculo['Jadlog_Valor_Frete']['Retorno']<=0){
                        $this->log->write("Erro jadlog ".$k.": " . $calculo['Jadlog_Valor_Frete']['Mensagem']); 
                    }else{

                        $cost = str_replace('.','',$calculo['Jadlog_Valor_Frete']['Retorno']);
                        $cost = str_replace(',','.',$cost);
                        $cost = ($cost+$this->config->get('jadlog5_taxa'));

                        $code = $v;
                        $quote_data[$code] = array(
                            'code'         => 'jadlog5.' . $code,
                            'title'        => '<img src="https://brewheadshop.com.br/img_pagamento/jadlog.png">'.$k.''.$prazo.'<br>EntregasparatodooBrasilcomprazosaproximadosparacadaRegiãoaseguir:<br>RegiãoSul:de4à7diasúteis<br>RegiãoSudeste:de3à5diasúteis<br>RegiãoCentro-Oeste:de4à10diasúteis<br>RegiãoNordeste:de8à19diasúteis<br>RegiãoNorte:de20à25diasúteis<br><spanstyle="font-size:16px;font-weight:bold">Valor de Entrega</span>',
                            'cost'         => $this->tax->calculate($cost, $this->config->get('jadlog5_tax_class_id'), $this->config->get('config_tax')),
                            'tax_class_id' => $this->config->get('jadlog5_tax_class_id'),
                            'text'         => $this->formatar($this->tax->calculate($cost, $this->config->get('jadlog5_tax_class_id'), $this->config->get('config_tax')))
                            );

                    }
                }
            } catch (SoapFault $fault) { 
            //print_r($fault->faultstring); 
                $this->log->write("Erro de acesso a api jadlog, verificar se o mesmo esta online e o firewall esta com a porta 8080 liberada!");    
            }

        }

Could someone please indicate a way to solve this problem?

Thank you very much

    
asked by anonymous 08.12.2016 / 18:17

2 answers

1

Make sure that SoapClient is sending user-agent , the error so read is PARSE and not connection, see:

  

SOAP-ERROR: WSDL parsing : Could not load

Then try this:

$opts = array(
        'http' => array( 'user_agent' => 'PHPSoapClient' )
    );

$context = stream_context_create($opts);
$soapContext = array(
                  'stream_context' => $context,
                  'cache_wsdl' => WSDL_CACHE_NONE
               );

$soapClient = new SoapClient("http://jadlog.com.br/JadlogEdiWs/services/ValorFreteBean?wsdl", $soapContext);
  

You can try to change PHPSoapClient by the desired user-agent

If you fail you can try 'trace' => true :

$opts = array(
        'trace' => true,
        'http' => array( 'user_agent' => 'PHPSoapClient' )
    );

$context = stream_context_create($opts);
$soapContext = array(
                  'trace' => true,
                  'stream_context' => $context,
                  'cache_wsdl' => WSDL_CACHE_NONE
               );

$soapClient = new SoapClient("http://jadlog.com.br/JadlogEdiWs/services/ValorFreteBean?wsdl", $soapContext);

It can also be missing from header called Accepets , you can send it like this:

$opts = array(
        'trace' => true,
        'http' => "User-agent: PHPSoapClient\r\n" .
                  "Accept: application/xhtml+xml,application/xml"
    );

This is because as of version 5.5 some things started to change in how PHP does HTTP access and in 5.6 the HTTPS also changed, a lot of things should be used the stream_ functions to adjust.

  

Note: I had a similar problem migrating to php5.6

     
    
08.12.2016 / 18:27
0

Boy, do the following:

Modify the line:

$soapClient = new SoapClient("http://jadlog.com.br/JadlogEdiWs/services/ValorFreteBean?wsdl");

To:

// options for ssl in php 5.6.5
$opts = array(
    'ssl' => array('ciphers'=>'RC4-SHA', 'verify_peer'=>false, 'verify_peer_name'=>false)
);

// SOAP 1.2 client
$params = array ('encoding' => 'UTF-8', 'verifypeer' => false, 'verifyhost' => false, 'soap_version' => SOAP_1_2, 'trace' => 1, 'exceptions' => 1, "connection_timeout" => 180, 'stream_context' => stream_context_create($opts) );

$url_webservice="http://jadlog.com.br/JadlogEdiWs/services/ValorFreteBean";
$soapClient = new SoapClient($url_webservice."?wsdl",$params );    

//var_dump($soapClient);
    
08.12.2016 / 19:17