Last active
April 5, 2020 11:21
-
-
Save kopiro/5720439 to your computer and use it in GitHub Desktop.
Check Postepay money via PHP & CURL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
/* | |
To install, just run this command: | |
sudo curl https://gist.github.com/kopiro/5720439/raw -o /usr/local/bin/postepay && sudo chmod +x /usr/local/bin/postepay | |
And, edit with: | |
sudo nano /usr/local/bin/postepay | |
*/ | |
define('USERNAME', ''); | |
define('PASSWORD', ''); | |
define('CARD_NUMBER', ''); | |
function curl_call($url, $post=array(), $headers=array()) { | |
global $cookie; | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); | |
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36"); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
if (count($post)) { | |
curl_setopt($ch, CURLOPT_POST, count($post)); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); | |
} | |
if (count($headers)) { | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
} | |
$r = curl_exec($ch); | |
curl_close($ch); | |
return $r; | |
} | |
if (!USERNAME || !PASSWORD || !CARD_NUMBER) { | |
die("Please configure this script with: nano /usr/local/bin/postepay"); | |
} | |
$cookie = tempnam("/tmp", "CURLCOOKIE"); | |
curl_call("https://bancopostaonline.poste.it/bpol/bancoposta/logon.fcc", array( | |
"USER"=>USERNAME, | |
"PASSWORD"=>PASSWORD, | |
"submitButton"=>"accedi", | |
"target"=>"/bpol/bancoposta/entry/RedirectionGateway.ashx?type=SMACCESS", | |
"device_id"=>"[[[INACCESSIBLE]]]]" | |
)); | |
$cart_select = curl_call("https://bancopostaonline.poste.it/bpol/cartepre/servizi/cartapostepay/cartapostepay.aspx?pnlstart=listamovimenti"); | |
if (!preg_match('/name\="__VIEWSTATE"\s*value\="([^"]*)/', $cart_select, $match)) { | |
die("Error: __VIEWSTATE Unreachable"); | |
} | |
$viewstate = $match[1]; | |
$money = curl_call("https://bancopostaonline.poste.it/bpol/cartepre/servizi/cartapostepay/cartapostepay.aspx?pnlstart=listamovimenti", array( | |
"__VIEWSTATE"=>$viewstate, | |
"CartaPostePaySelezionaCarta1:txtNrCartaPre"=>CARD_NUMBER, | |
"__EVENTTARGET"=>"CartaPostePaySelezionaCarta1:btnEsegui", | |
"__EVENTARGUMENT"=>"" | |
), array( | |
"Referer"=>"https://bancopostaonline.poste.it/bpol/cartepre/servizi/cartapostepay/cartapostepay.aspx?pnlstart=listamovimenti", | |
"Origin"=>"https://bancopostaonline.poste.it" | |
)); | |
if (!preg_match('/CartaPostePayListaMovimenti1_lblSaldoDisponibile">([^<]*)/', $money, $moneymatch)) { | |
die("Error: Money Unreachable"); | |
} | |
echo "SALDO DISPONIBILE: ".$moneymatch[1]; | |
@unlink($cookie); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
and what is the comands ?