<?php require 'vendor/autoload.php'; use JansenFelipe\CnpjGratis\CnpjGratis; use JansenFelipe\Utils\Utils; use JansenFelipe\Utils\Mask; try { if (!isset($_POST['cnpj']) || !isset($_POST['captcha']) || !isset($_POST['cookie'])) { throw new Exception('Informe todos os campos', 99); } $return = CnpjGratis::consulta($_POST['cnpj'], $_POST['captcha'], $_POST['cookie']); $return['cep'] = Utils::mask($return['cep'], Mask::CEP); $return['code'] = 0; } catch (Exception $e) { $return = array('code' => $e->getCode(), 'message' => $e->getMessage()); } header('Content-Type: application/json'); echo json_encode($return);
<?php require 'vendor/autoload.php'; if (isset($_POST['cnpj'])) { var_dump(\JansenFelipe\CnpjGratis\CnpjGratis::consulta($_POST['cnpj'], $_POST['captcha'], $_POST['cookie'])); die; } $cnpj = '45543915000858'; $params = \JansenFelipe\CnpjGratis\CnpjGratis::getParams(); ?> <img src="<?php echo $params['captchaBase64']; ?> " /><br /> <form action="" method="POST"> <input type="text" name="cnpj" value="<?php echo $cnpj; ?> " /> <input type="text" name="captcha" /> <input type="text" name="cookie" value="<?php echo $params['cookie']; ?> " /> <input type="submit" /> </form>