Skip to content

Commit

Permalink
fetch url pix
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardokum committed Jan 3, 2024
1 parent d906b48 commit afd1649
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,11 @@ public static function gerarPixCopiaECola($pix, $valor, $id, Pessoa $beneficiari
};

$gui = $line('00', 'br.gov.bcb.pix');
$key = $line('01', $pix);
if (filter_var($pix, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED) || filter_var('https://' . $pix, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)) {
$key = $line('25', preg_replace('/^https?:\/\//', '', $pix));
} else {
$key = $line('01', $pix);
}
$txId = $line('05', $id);
$payload = $line('00', '01');
$payload .= $line('01', '12');
Expand All @@ -1284,6 +1288,30 @@ public static function gerarPixCopiaECola($pix, $valor, $id, Pessoa $beneficiari
return $payload . $crc16($payload);
}

/**
* @param $location
* @return array
*/
public static function fetchPixLocation($location)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_URL, $location);
$data = curl_exec($curl);
curl_close($curl);
$datas = explode('.', $data);
if (count($datas) !== 3) {
return [];
}

return [
'fetch' => $data,
'header' => json_decode(base64_decode($datas[0]), true),
'payload' => json_decode(base64_decode($datas[1]), true),
'signature' => $datas[2],
];
}

/**
* @param $pixCopiaECola
* @param null $parent
Expand Down

0 comments on commit afd1649

Please sign in to comment.