Ir para conteúdo
Fórum Script Brasil
  • 0

Web Service + WSDL


Renato Penna

Pergunta

Boa tarde a todos. Eu estou tentando fazer um webservice com WSDL. Porém eu nunca fiz isso e não está funcionando. Alguém pode me ajudar ? Eu fiz estes arquivos:

Loja.php

<?php
class Loja
{
    private $proxy;
    private $sessionId;
    private $atributeSets;
    private $set;
    private $caracteristicas;
    
    function getProxy()
    {
        return $this->proxy;
    }
    function setProxy($value)
    {
        $this->proxy = $value;
    }
    
    function getSessionId()
    {
        return $this->sessionId;
    }
    function setSessionId($value)
    {
        $this->sessionId = $value;
    }
    
    function getAtributeSets()
    {
        return $this->atributeSets;
    }
    function setAtributeSets($value)
    {
        $this->atributeSets = $value;
    }
    
    function getSet()
    {
        return $this->set;
    }
    function setSet($value)
    {
        $this->set = $value;
    }
    
    function getCaracteristicas()
    {
        return $this->caracteristicas;
    }
    function setCaracteristicas($value)
    {
        $this->caracteristicas = $value;
    }
    
    function pegarDados()
    {
        $proxy = new SoapClient('http://manutencao.workcopy.lojasingular.com.br/api/soap/?wsdl');
        //$this->setProxy(new SoapClient('http://manutencao.workcopy.lojasingular.com.br/api/soap/?wsdl'));
        $sessionId = $proxy->login('jefersonsilva', '123456');
        //$this->setSessionId($this->getProxy()->login('jefersonsilva', '123456'));
        $atributeSets = $proxy->call($sessionId, 'product_attribute_set.list');
        //$this->setAtributeSets($this->getProxy()->call($sessionId, 'product_attribute_set.list'));
        $set = current($atributeSets);
        //$this->setSet(current($this->getAtributeSets()));
        $caracteristicas = $proxy->call($sessionId, 'sales_order.list', array(array('state'=>array('eq'=>'processing'))));
        //$this->setCaracteristicas($this->getProxy()->call($sessionId, 'sales_order.list', array(array('state'=>array('eq'=>'processing')))));
        
        for($i=0;$i<count($caracteristicas);$i++)
        {
            $dados_loja = $proxy->call($sessionId, 'sales_order.info',$caracteristicas[$i]["increment_id"]);
        }
        return $dados_loja;
        
        /*
        $vet_caracteristicas = $this->getCaracteristicas();
        for($i=0;$i<count($this->getCaracteristicas());$i++)
        {
            $dados_loja = $this->getProxy()->call($sessionId, 'sales_order.info',$vet_caracteristicas[$i]["increment_id"]);
        }
        return $vet_caracteristicas;
         */
    }
}
?>
Sog.php
<?php
class Sog
{
    private $username;
    private $password;
    private $customerType;
    private $customerIdentifier;
    private $customerExtraIdentifier;
    private $customerName;
    private $customerEmail;
    private $customerBillingAddress;
    private $customerShippingAddress;
    private $sogob;
    
    function getUsername()
    {
        return $this->username;
    }
    function setUsername($value)
    {
        $this->username = $value;
    }
    
    function getPassword()
    {
        return $this->password;
    }
    function setPassword($value)
    {
        $this->password = $value;
    }
    
    function getCustomerType()
    {
        return $this->customertype;
    }
    function setCustomerType($value)
    {
        $this->customerType = $value;
    }
    
    function getCustomerIdentifier()
    {
        return $this->customeridentifier;
    }
    function setCustomerIdentifier($value)
    {
        $this->customerIdentifier = $value;
    }
    
    function getCustomerExtraIdentifier()
    {
        return $this->customerExtraIdentifier;
    }
    function setCustomerExtraIdentifier($value)
    {
        $this->customerExtraIdentifier = $value;
    }
    
    function getCustomerName()
    {
        return $this->customerName;
    }
    function setCustomerName($value)
    {
        $this->customerName = $value;
    }
    
    function getEmail()
    {
        return $this->customerEmail;
    }
    function setEmail($value)
    {
        $this->customerEmail = $value;
    }
    
    function getCustomerBillingAddress()
    {
        return $this->customerBillingAddress;
    }
    function setCustomerBillingAddress($value)
    {
        $this->customerBillingAddress = $value;
    }
    
    function getCustomerShippingAddress()
    {
        return $this->customerShippingAddress;
    }
    function setCustomerShippingAddress($value)
    {
        $this->customerShippingAddress = $value;
    }
    
    function enviarDados($dl)
    {
        $this->sogob = new SoapClient("http://lajedo.singulardigital.com.br:6060/sog/services/orderWS?wsdl");
        $sessionId = $this->sogob->login($this->getUsername(),  $this->getPassword());

        $lines = NULL;
        foreach($dl as $item)
    {
            $lines[] = Array(
            "isbn" => $item["sku"],
            "quantity" => $item["qty_ordered"],
            "price" => $item["price"]
            );
    }
        
        $params = Array(
        "username" => $this->getUsername(),
    "password" => $this->getPassword(),
    "customerType" => $this->getCustomerType(),
    "customerIdentifier" => $this->getCustomerIdentifier(),
    "customerExtraIdentifier" => $this->getCustomerExtraIdentifier(),
    "customerName" => $this->getCustomerName(),
    "customerEmail" => $this->getEmail(),
    "customerBillingAddress" => (Object) $this->getCustomerBillingAddress(),
    "customerShippingAddress" => (Object) $this->getCustomerBillingAddress(),
    "partnerOrderId" => $dl->sku,
    "shippingPrice" => $dl->shipping_amount,
    "lines" => $lines);
        /*
        $params = Array(
    "username" => $this->username,
    "password" => $this->password,
    "customerType" => $this->customerType,
    "customerIdentifier" => $this->customerIdentifier,
    "customerExtraIdentifier" => $this->customerExtraIdentifier,
    "customerName" => $this->customerName,
    "customerEmail" => $this->customerEmail,
    "customerBillingAddress" => (Object) $this->customerBillingAddress,
    "customerShippingAddress" => (Object) $this->customerBillingAddress,
    "partnerOrderId" => $dados->numeroDoPedido,
    "shippingPrice" => $dados->frete,
    "lines" => $lines
    );        
        */
        $dados_envio = $this->sogob->catalogStoredOrder($params);
        return $dados_envio;
    }
}
?>
web_service.php
<?php
include("loja.php");
include("sog.php");

$loja = new Loja();
$sog = new Sog();

$dados_loja = $loja->pegarDados();
$sog->setUsername("aaaa");
$sog->setPassword("bbbb123456");
$sog->setCustomerType("1");
$sog->setCustomerIdentifier("09900243773");
$sog->setCustomerExtraIdentifier("123456");
$sog->setCustomerName("Teste");
$sog->setEmail("teste@teste.com.br");
$sog->setCustomerBillingAddress("Rua teste número 368");
$sog->setCustomerShippingAddress("Rua teste número 368");
var_dump($sog->enviarDados($dados_loja));
?>

Quando eu mando rodar o web_service.php, fica um tempão rodando e no fim não aparece nada na tela. Nem erro nem nada. O que está faltando ou errado ? Desde já agradeço.

Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

  • 0

Coloca no começo do seu script as seguintes funções:

set_time_limit(0);
error_reporting(E_ALL|E_STRICT);

Aparece algo agora?

SoapClient costuma ser um sofrimento. Fiz integrações com Java e .NET (VB.NET) a muito tempo atrás e lembro que foi muito difícil. Você não pode usar nuSoap?

Um abraço.

Link para o comentário
Compartilhar em outros sites

  • 0

Não posso porque estou usando integração com o webservice do Magento também e se eu usar o nuSoap ele pára de funcionar.

Eu coloquei essas duas linhas no webservice.php e deu a mesma coisa. Ficou rodando e depois parou e não apareceu nada na tela. O webservice.php ficou assim:

<?php
set_time_limit(0);
error_reporting(E_ALL|E_STRICT);
include("loja.php");
include("sog.php");

$loja = new Loja();
$sog = new Sog();

$dados_loja = $loja->pegarDados();
$sog->setUsername("josemando@singulardigital.com.br");
$sog->setPassword("josemando123");
$sog->setCustomerType("1");
$sog->setCustomerIdentifier("09900243773");
$sog->setCustomerExtraIdentifier("123456");
$sog->setCustomerName("Teste");
$sog->setEmail("teste@teste.com.br");
$sog->setCustomerBillingAddress("Rua teste número 368");
$sog->setCustomerShippingAddress("Rua teste número 368");
var_dump($sog->enviarDados($dados_loja));
?>

Editado por Renato Penna
Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...