$config = [
"certificado" => ($sandbox) ? $pathCertificateHomolog : $pathCertificateProd,
"client_id" => ($sandbox) ? $clientIdHomolog : $clientIdProd,
"client_secret" => ($sandbox) ? $clientSecretHomolog : $clientSecretProd,
"rotas" => ($sandbox) ? $rotasHomolog : $rotasProd
];
$autorizacao = base64_encode($config["client_id"] . ":" . $config["client_secret"]);
$curl = curl_init();
$fp = fopen($_SERVER['DOCUMENT_ROOT'] . '/errorlog.txt', 'w');
curl_setopt_array($curl, array(
CURLOPT_VERBOSE => true,
CURLOPT_STDERR => $fp,
CURLOPT_URL => $config['rotas'] . "/oauth/token", // Rota base, homologação ou produção
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => '{"grant_type": "client_credentials"}',
CURLOPT_SSLCERT => $config["certificado"], // Caminho do certificado
CURLOPT_SSLCERTPASSWD => "",
CURLOPT_HTTPHEADER => array(
"Authorization: Basic $autorizacao",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
echo '
';
var_dump($config, $response);
echo '
';
curl_close($curl);