I would like your help in the following errors, the first one is in pac, it returns the value, so everything is fine, but it also brings:
Fatal error: Uncaught exception 'Exception' with message 'Serialization of' SimpleXMLElement 'is not allowed' in [no active file]
Returns the correct value of the transaction but also returns this fatal error and I do not understand why.
In Sedex it always brings me the error -5, I looked in the API of the mails and as for the service codes, well ... they are the same, I can not understand why I get this error -5. I tried google but I did not find anything about this error.
My form
<form method="POST" action="carrinhoo.php" enctype="">
<select name="frete" class="form-control">
<option value="">Selecione...</option>
<option value="carta">Carta Registrada</option>
<option value="pac">Pac</option>
<option value="sedex">Sedex</option>
</select>
Digite seu cep:<br>
<input type="text" class="form-control" name="cep"><br>
<input type="hidden" class="form-control" name="acao" value="calcular">
<input type="submit" value="Calcular" class="btn btn-success">
Valor frete: <?php echo ($_SESSION['valor_frete'] == '6.00') ? number_format($_SESSION['valor_frete'],2,',','.') : $_SESSION['valor_frete'];?>
</form>
Here is the requisition:
if(isset($_POST['acao']) && $_POST['acao'] == 'calcular'){
$frete = $_POST['frete'];
$cep = strip_tags(filter_input(INPUT_POST, 'cep'));
switch ($frete){
case 'carta':
$valor = '6.00';
$_SESSION['valor_frete'] = '6.00';
break;
case 'pac':
$valor = '41106';
$prod = new Produto();
$_SESSION['valor_frete'] = $prod->CalculaFrete($valor, 45350000, $cep, '0.50');
break;
case 'sedex':
$valor = '40010';
$prod = new Produto();
$_SESSION['valor_frete'] = $prod->CalculaFrete($valor, 45350000, $cep, '0.50');
var_dump($_SESSION['valor_frete']);
break;
}
}
Here my method with the Post Office API
public function CalculaFrete($cod_servico, $cep_origem, $cep_destino, $peso, $altura = '2', $largura = '11', $comprimento = '16', $valor_declarado = '0.50'){
$correios = "http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?"."nCdEmpresa=&sDsSenha=&sCepOrigem=".$cep_origem.
"&sCepDestino=".$cep_destino."&nVlPeso=".$peso."&nCdFormato=1&nVlComprimento=".$comprimento."&nVlAltura=".$altura.
"&nVlLargura=".$largura."&sCdMaoPropria=n"."&nVlValorDeclarado=".$valor_declarado."&sCdAvisoRecebimento=n".
"&nCdServico=".$cod_servico."&nVlDiametro=0&StrRetorno=xml";
$xml = simplexml_load_string(file_get_contents($correios));
if($xml->cServico->Erro == '0'){
return $xml->cServico->Valor;
}else{
var_dump($xml);
return false;
}
}