Primeiro você deve autenticar na API e obter o access_token.
php
$curl = curl_init();
$authorization = base64_encode("$client_id:$client_secret");
curl_setopt_array($curl, array(
CURLOPT_URL => "
https://api-pix-h.gerencianet.com.br/oauth/token", // Rota base, desenvolvimento 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 => $arq_certificado, // Caminho do certificado
CURLOPT_SSLCERTPASSWD => "",
CURLOPT_HTTPHEADER => array(
"Authorization: Basic $authorization",
"Content-Type: application/json"
),
));
$auth = json_decode(curl_exec($curl), true);
curl_close($curl);
$tokenType = $auth['token_type'];
$accessToken = $auth['access_token'];
Depois emitir o pix
php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "
https://api-pix-h.gerencianet.com.br/v2/cob/$txID",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_SSLCERT => $arq_certificado, // Caminho do certificado
CURLOPT_SSLCERTPASSWD => "",
CURLOPT_POSTFIELDS => '{
"calendario": {
"expiracao": 3600
},
"devedor": {
"cpf": "02279112312",
"nome": "Maria apareciada monteiro"
},
"valor": {
"original": "10.21"
},
"chave": "",
"solicitacaoPagador": "Mensaldiade Monteiro Sistemas"
}',
CURLOPT_HTTPHEADER => array(
"authorization: $tokenType $accessToken",
"Content-Type: application/json"
),
));
$dadosPix = json_decode(curl_exec($curl), true);
curl_close($curl);
return $dadosPix;