progam ini adalah contoh simpel untuk meng CURL tagihan listrik bulanan.
dalam program ini ada 3 parameter yaitu:
$mode = jabar (http://www.pln-jabar.co.id) /infobiling (http://202.162.217.251/info_billing/index.php)
$bulan = bulan tagihan listrik
$tahun = tahun tagihan listrik
* untuk pln-jabar.co.id hanya dapat menarik tagihan listrik 3 bulan terakhir saja.
<?php
if (!function_exists("curl_init"))
{
die('CURL tidak ada');
}
$chp = curl_init();
//variable for cookies access
curl_setopt($chp, CURLOPT_COOKIEJAR, $cookiesjar);
//variable for cookies store , same as previous line
curl_setopt($chp, CURLOPT_COOKIEFILE, $cookiesjar);
//simulating user agent - shadow
curl_setopt($chp, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
//skipping SSL_CERT for host
curl_setopt($chp, CURLOPT_SSL_VERIFYHOST, 0);
//skipping SSL_CERT
curl_setopt($chp, CURLOPT_SSL_VERIFYPEER, 0);
//ingroring server redirect
curl_setopt($chp, CURLOPT_FOLLOWLOCATION, 1);
//accepting returns from server
curl_setopt($chp, CURLOPT_RETURNTRANSFER, 1);
//our target url
$bulan="01";
$tahun="2010";
$idpel="xxx";
$mode="infobilling";
switch (strtolower($mode))
{
case "jabar":
{
$bulan = str_pad($bulan, 2,'0',STR_PAD_LEFT);
$url = "http://www.pln-jabar.co.id/infotag_meter_new.php?idpel=$idpel&bln=$bulan&thn=$tahun";
curl_setopt($chp, CURLOPT_URL, $url);
//open the url with our mentioned variables
$content = curl_exec($chp);
//echo($content);
if (preg_match(%KEDUDUKAN METER.*?AKHIR.*?<td.*?>(.*?)</td>.*?LALU.*?<td.*?>(.*?)</td>.*?TOTAL TAGIHAN.*?<table.*?>.*?<td.*?<strong>Rp (.*?)</strong>%si', $content, $match)) {
echo("Akhir : $match[1]<br />");
echo("Lalu : $match[2]<br />");
echo("Tagihan Listrik Rp. : $match[3]<br />");
} else {
die('tidak dapat membaca tagihan listrik, atau tagihan listrik belum ada.');
}
break;
}
case "infobilling":
{
$url = "http://202.162.217.251/info_billing/index.php?mod=login";
$params = "idpel=$idpel&action=login&button=Cek+Tagihan";
curl_setopt($chp, CURLOPT_REFERER, "http://202.162.217.251/info_billing/index.php");
curl_setopt($chp, CURLOPT_POSTFIELDS,$params);
curl_setopt($chp, CURLOPT_URL, $url);
//open the url with our mentioned variables
$content = curl_exec($chp);
if (preg_match('%MAIN MENU%si', $content, $match)) {
$url = "http://202.162.217.251/info_billing/index.php?mod=tagihan.bulan";
$params = "action=search&idpel=&bulan=$bulan&tahun=$tahun";
curl_setopt($chp, CURLOPT_POSTFIELDS,$params);
curl_setopt($chp, CURLOPT_URL, $url);
$content = curl_exec($chp);
if (preg_match('%Info Rekening.*?<table.*?Tagihan anda.*?<span.*?>Rp. (.*?) ,-</span>%si', $content, $match)) {
echo("Tagihan Listrik Rp. : $match[1]<br />");
}
else
{
die('tidak dapat membaca tagihan listrik, atau tagihan listrik belum ada.');
}
}
break;
}
}
curl_close($chp);
?>
Kamis, 13 Januari 2011
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar