0
Good morning! I am breaking my head to recover the Class that generates JSON, I have the following class name apiBusca.php
public function enviarRequisicao() {
$url = 'API';
$json = new StdClass();
$json->Chave = $this->Chave;
$json->Senha = $this->Senha;
$json->TipoViagem = $this->TipoViagem;
$json->Companhias = $this->Companhias;
$json->Adultos = $this->Adultos;
$json->Criancas = $this->Criancas;
$json->Bebes = $this->Bebes;
$json->Trechos = $this->Trechos;
$data = json_encode($json);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
In the api.php data display file I put it as follows:
$chave = "MINHA_CHAVE";
$senha = "MINHA_SENHA";
$tipoviagem = 1;
$companhias = array("GOL");
$adultos = 1;
$criancas = 0;
$bebes = 0;
$trechos = array(array("Origem" => "$Origem", "Destino" => "$LugarDestino", "DataIda" => "$DataIda", "DataVolta" => "$dataVolta"));
$objeto = new apibuscamilhas($chave, $senha, $tipoviagem, $companhias, $adultos, $criancas, $bebes, $trechos);
$ida = new apibuscamilhas();
$ida->Chave = "MINHA_CHAVE";
$ida->Senha = "MINHA_SENHA";
$ida->TipoViagem = 0;
$ida->Companhias = array("GOL");
$ida->Adultos = 1;
$ida->Criancas = 0;
$ida->Bebes = 0;
$ida->Trechos = array(array("Origem" => "$Origem", "Destino" => "$LugarDestino", "DataIda" => "$DataIda"));
Doubt I can’t display it except through var_dump($ida->send());
Could someone help me?
Thank you
Utilize
CURLOPT_RETURNTRANSFER
astrue
to return the data and give aecho json_encode($ida);
in theapi.php
– Valdeir Psr
I added the CURLOPT_RETURNTRANSFER thus curl_setopt($ch, CURLOPT_RETURNTRANSFER, $data); and in the api.php file it returned me only {}
– Cristiano Facirolli
Added the
echo json_encode....
too? The fileapi.php
have to print a value for then, the fileapiBusca.php
recover.– Valdeir Psr
Yes I did and you didn’t call me back!
– Cristiano Facirolli