public function testMask() { $this->assertEquals('732.584.423-98', Utils::mask('73258442398', Mask::DOCUMENTO)); $this->assertEquals('732.584.423-98', Utils::mask('73258442398', Mask::CPF)); $this->assertEquals('13.779.426/0001-37', Utils::mask('13779426000137', Mask::DOCUMENTO)); $this->assertEquals('13.779.426/0001-37', Utils::mask('13779426000137', Mask::CNPJ)); $this->assertEquals('31.030-080', Utils::mask('31030080', Mask::CEP)); $this->assertEquals('(31)3072-7066', Utils::mask('3130727066', Mask::TELEFONE)); $this->assertEquals('(31)99503-7066', Utils::mask('31995037066', Mask::TELEFONE)); }
<?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);