From 12bc3d93d40d23c81a16306a8e847592b86c5c98 Mon Sep 17 00:00:00 2001 From: Adhidarma Hadiwinoto <gua@adhisimon.org> Date: Wed, 8 Jul 2015 16:53:54 +0700 Subject: [PATCH] source_page, fp, dan balance --- KiselScrap.php | 56 +++++++++++++++++++++++++++++++++++--------------------- scrap_kisel.php | 15 ++++++++------- 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/KiselScrap.php b/KiselScrap.php index 3da5a92..61b95d4 100644 --- a/KiselScrap.php +++ b/KiselScrap.php @@ -11,7 +11,9 @@ Class KiselScrap { var $session_status = 1; var $resp_str = ''; var $resp_target = ''; - var $resp_xml = ''; + var $resp_xml = ''; + var $source_page = ''; + var $fp = ''; function setRandomUserAgent() { @@ -67,9 +69,9 @@ Class KiselScrap { $log = "[$date] error" . curl_errno($ch)."\n"; } - #$fd = fopen("scrapper_kisel.log", "a+"); - #fwrite($fd, $log); - #fclose($fd); + $fd = fopen("scrapper_kisel.log", "a+"); + fwrite($fd, $log); + fclose($fd); curl_close($ch); @@ -134,6 +136,7 @@ Class KiselScrap { $arr_resp = explode("|", $resp_value); if($type == 1) { + $strBal = $this->balance(); if (preg_match("/TRANSAKSI SUKSES/i", $this->resp_str)) { if(count($arr_resp) > 14){ $xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; @@ -143,6 +146,7 @@ Class KiselScrap { $xml_str .= "<harga>$arr_resp[11]</harga>"; $xml_str .= "<ref_num>$arr_resp[3]</ref_num>"; $xml_str .= "<kode_voucher>$arr_resp[13]</kode_voucher>"; + $xml_str .= "<stock>$strBal</stock>"; $xml_str .= "<info>$arr_resp[14]</info>"; $xml_str .= "</trx_response>"; } @@ -174,6 +178,13 @@ Class KiselScrap { # hit response transaksi ke ST24 #$this->send_form($this->resp_target, '', $arr_resp); } + else { + preg_match("/name=\"_sourcePage\" value=\"(\\S+)\"/s", $this->resp_str, $matches); + $this->source_page = $matches[1]; + + preg_match("/name=\"__fp\" value=\"(\\S+)\"/s", $this->resp_str, $matches2); + $this->fp = $matches2[1]; + } } } @@ -201,21 +212,25 @@ Class KiselScrap { } } $resp_value = ltrim(rtrim($resp_value)); - print $resp_value."\n"; + + #print $resp_value."\n"; # Stock Anda Saat ini : ; 10K = 1; 20K = 1; 25K = 0; 50K = 1; 100K = 1; 150K = 1; 200K = 1; 300K = 1; 500K = 1 - preg_match("/^Stock Anda Saat ini : ; (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+)/s", $resp_value, $matches); + #preg_match("/^Stock Anda Saat ini : ; (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+); (\\S+) = (\\S+)/s", $resp_value, $matches); #print_r($matches); - $arr_stk = array(); - $arr_stk[$matches[1]] = $matches[2]; - $arr_stk[$matches[3]] = $matches[4]; - $arr_stk[$matches[5]] = $matches[6]; - $arr_stk[$matches[7]] = $matches[8]; - $arr_stk[$matches[9]] = $matches[10]; - $arr_stk[$matches[11]] = $matches[12]; - $arr_stk[$matches[13]] = $matches[14]; - $arr_stk[$matches[15]] = $matches[16]; - $arr_stk[$matches[17]] = $matches[18]; - return $arr_stk; + #$arr_stk = array(); + #$arr_stk[$matches[1]] = $matches[2]; + #$arr_stk[$matches[3]] = $matches[4]; + #$arr_stk[$matches[5]] = $matches[6]; + #$arr_stk[$matches[7]] = $matches[8]; + #$arr_stk[$matches[9]] = $matches[10]; + #$arr_stk[$matches[11]] = $matches[12]; + #$arr_stk[$matches[13]] = $matches[14]; + #$arr_stk[$matches[15]] = $matches[16]; + #$arr_stk[$matches[17]] = $matches[18]; + #return $arr_stk; + + preg_match("/^Stock Anda Saat ini : ; (\\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+)/s", $resp_value, $matches); + return $matches[1]; } function send_form($url, $url_ref, $fields){ @@ -258,10 +273,9 @@ Class KiselScrap { $log = "[$date] error" . curl_errno($ch)."\n"; } - #$fd = fopen("scrapper_kisel.log", "a+"); - #fwrite($fd, $log); - #fclose($fd); - + $fd = fopen("scrapper_kisel.log", "a+"); + fwrite($fd, $log); + fclose($fd); curl_close ($ch); $this->resp_str = $resp_str; return 1; diff --git a/scrap_kisel.php b/scrap_kisel.php index cd30874..c3e5e99 100644 --- a/scrap_kisel.php +++ b/scrap_kisel.php @@ -10,10 +10,7 @@ include('KiselScrap.php'); # '__fp' => 'wIlI6mnh04Y=' # ); -$arrinqtelconext = array('goToPin' => 'next', - '_sourcePage' => 'fRCY-X8ZXOIcbgrf1BkkxBM7KTI7S6exLVsnXnUiXn8=', - '__fp' => 'wIlI6mnh04Y=' - ); + $kisel = new KiselScrap(); @@ -35,6 +32,7 @@ $kisel->setRandomUserAgent(); $log = ""; // Format the date and time $date = date("Y-m-d H:i:s"); +$fd = fopen("scrapper_kisel.log", "a+"); $log = "[$date] Step-1 : get welcome page\n"; @@ -69,15 +67,18 @@ if($kisel->session_status) { $log .= "[$date] Step-4 : send purchase telco\n"; $log .= "--------------------------------\n"; + + $arrinqtelconext = array('goToPin' => 'next', + '_sourcePage' => $kisel->source_page, + '__fp' => $kisel->fp + ); + $kisel->send_form($purchasetelco_url, $purchasetelco_url, $arrinqtelconext); $kisel->parseResponse("//table[@class='tblogin']/tbody/tr/td",1); $kisel->printResponseXML(); - /* - $fd = fopen("scrapper_kisel.log", "a+"); fwrite($fd, $log); fclose($fd); - */ } ?> -- 1.9.0