arijulianto

mutasi bcA

Mar 17th, 2014 (edited)
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.13 KB | None | 0 0
  1. <?php
  2. class bankBCA{
  3.     var $userid = "";
  4.     var $password = "";
  5.     var $rekening = 1;
  6.  
  7.     var $login_url = "https://ibank.klikbca.com";
  8.     var $login_process_url="https://ibank.klikbca.com/authentication.do";
  9.     var $login_success="authentication.do?value(actions)=welcome";
  10.     var $menu_url="https://ibank.klikbca.com/nav_bar_indo/menu_bar.htm";
  11.     var $info_rekening="https://ibank.klikbca.com/nav_bar_indo/account_information_menu.htm";
  12.     var $mutasi_form_url="https://ibank.klikbca.com/accountstmt.do?value(actions)=acct_stmt";
  13.     var $mutasi_url = "https://ibank.klikbca.com/accountstmt.do?value(actions)=acctstmtview";
  14.     var $logout_url = "https://ibank.klikbca.com/authentication.do?value(actions)=logout";
  15.     var $cookie = "cookiejar";
  16.     var $ch;
  17.  
  18.     function openCurl(){
  19.         $this->ch = curl_init();
  20.        
  21.         curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);
  22.         curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,1);
  23.         curl_setopt($this->ch, CURLOPT_BINARYTRANSFER,1);
  24.         curl_setopt($this->ch, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
  25.         curl_setopt($this->ch, CURLOPT_COOKIEJAR, realpath($this->cookie));
  26.         curl_setopt($this->ch, CURLOPT_COOKIEFILE, realpath($this->cookie));
  27.         curl_setopt($this->ch, CURLOPT_CAINFO, "cert/cacert.pem");
  28.         curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);
  29.         curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);
  30.     }
  31.  
  32.     function closeCurl(){
  33.         curl_close($this->ch);
  34.     }
  35.  
  36.     function browse($url,$post=false,$follow=false,$reffer=false){
  37.         $this->openCurl();
  38.         curl_setopt($this->ch, CURLOPT_URL, $url);
  39.  
  40.         if($post){
  41.             curl_setopt($this->ch, CURLOPT_POST, 1 );
  42.             curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post);
  43.         }
  44.  
  45.         if($follow){
  46.             curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);
  47.         }
  48.  
  49.         if($reffer){
  50.             curl_setopt($this->ch, CURLOPT_REFERER,$reffer);
  51.         }
  52.  
  53.         $result = array("data"=>curl_exec($this->ch),"info"=>curl_getinfo($this->ch));
  54.         $result['headers'] = substr($result['data'], 0, $result['info']['header_size']);
  55.  
  56.         $this->closeCurl();
  57.         return $result;
  58.     }
  59.  
  60.     function login(){
  61.         $result = $this->browse($this->login_url);
  62.  
  63.         $str = $result['data'];
  64.         $str = preg_replace("/\n+/","",$str);
  65.         $str = preg_replace("/<br>/"," ",$str);
  66.         $str = preg_replace("/\s+/"," ",$str);
  67.         $str = preg_replace("/,/","",$str);
  68.         preg_match('/<input type="hidden" name="value\(user_ip\)" value="(.*?)">/si', $str, $match);
  69.         $user_ip = $match[1];
  70.  
  71.         $params = array();
  72.         $params[] = 'value%28actions%29=login';
  73.         $params[] = 'value%28user_id%29=' . $this->userid;
  74.         $params[] = 'value%28pswd%29=' . $this->password;
  75.         $params[] = 'value%28user_ip%29=' . $user_ip;
  76.         $params[] = 'value%28browser_info%29=Mozilla/5.0+(Windows;+U;+Windows+NT+5.1;+en-GB;+rv:1.8.1.6)+Gecko/20070725+Firefox/2.0.0.6';
  77.         $params[] = 'value%28mobile%29=false';
  78.         $params[] = 'value%28Submit%29=LOGIN';
  79.         $params = implode( '&', $params );
  80.  
  81.         $result = $this->browse($this->login_process_url,$params,false,$this->login_url);
  82.         return $isLogin = strpos($result['data'],$this->login_success);
  83.     }
  84.  
  85.     function mutasi($dari,$sampai,$rekening=false){
  86.         if(!$rekening){
  87.             $rekening=$this->rekening;
  88.         }
  89.  
  90.         $page = $this->browse($this->menu_url,false,false,$this->login_process_url);
  91.         $page = $this->browse($this->info_rekening,false,false,$this->login_process_url);
  92.         $page = $this->browse($this->mutasi_form_url,false,false,$this->info_rekening);
  93.  
  94.         $params = array();
  95.         $t1 = explode( '-', $sampai );
  96.         $t0 = explode( '-', $dari );
  97.  
  98.         $params[] = 'value%28startDt%29=' . $t0[2];
  99.         $params[] = 'value%28startMt%29=' . $t0[1];
  100.         $params[] = 'value%28startYr%29=' . $t0[0];
  101.         $params[] = 'value%28endDt%29=' . $t1[2];
  102.         $params[] = 'value%28endMt%29=' . $t1[1];
  103.         $params[] = 'value%28endYr%29=' . $t1[0];
  104.         $params[] = 'value%28D1%29=0';
  105.         $params[] = 'value%28r1%29=1';
  106.         $params[] = 'value%28fDt%29=';
  107.         $params[] = 'value%28tDt%29=';
  108.         $params[] = 'value%28submit1%29=Lihat+Mutasi+Rekening';
  109.         $params = implode( '&', $params );
  110.  
  111.         $page=$this->browse($this->mutasi_url,$params,false,$this->info_rekening);
  112.         // return $page;
  113.         $xmut = preg_match('/<table border="1" width="100%" cellpadding="0" cellspacing="0" bordercolor="#ffffff">(.*?)<\/table>/s', $page['data'], $mutasi);
  114.         if(!$xmut) { return false; }
  115.        
  116.         preg_match_all('/<tr>(.*?)<\/tr>/si', $mutasi[0], $mut);
  117.         $arrmut = $this->parseMutasi($mut[0]);
  118.  
  119.         $arrsumm = array( 'awal' => 0, 'kredit' => 0, 'debet' => 0, 'akhir' => 0);
  120.         $xsal = preg_match('/<table border="0" width="70%" cellpadding="0" cellspacing="0" bordercolor="#ffffff">(.*?)<\/table>/s', $page['data'], $saldo);
  121.         if($xsal) {
  122.             preg_match_all('/<td align="right"><font face="Verdana" size="1" color="#0000bb">(.*?)<\/font>/si', $saldo[0], $sal);
  123.             $arrsum = $this->parseSummary($sal[0]);
  124.         }
  125.  
  126.         return array( 'mutasi' => $arrmut, 'summary' => $arrsum );
  127.     }
  128.  
  129.     function parseSummary($data){
  130.         $arrkey = array('awal', 'kredit', 'debet', 'akhir');
  131.         $retval = array();
  132.         $i = 0;
  133.         foreach($data as $tr){
  134.             $str = preg_replace("/\n+/","",$tr);
  135.             $str = preg_replace("/\s+/"," ",$str);
  136.             $str = preg_replace("/,/","",$str);
  137.            
  138.             preg_match_all('/<font face="verdana" size="1" color="#0000bb">(.*?)<\/font>/si', $str, $td);
  139.  
  140.             $key = $arrkey[$i];
  141.             $retval[$key] = trim($td[1][0]);
  142.             $i++;
  143.         }
  144.         return $retval;
  145.     }
  146.    
  147.     function parseMutasi($data){
  148.         $rows=array();
  149.         $i = 1;
  150.  
  151.         foreach($data as $tr){
  152.             if($i>1){
  153.                 $str = preg_replace("/\n+/","",$tr);
  154.                 $str = preg_replace("/<br>/"," ",$str);
  155.                 $str = preg_replace("/\s+/"," ",$str);
  156.                 $str = preg_replace("/,/","",$str);
  157.  
  158.                 preg_match_all('/<font face="verdana" size="1" color="#0000bb">(.*?)<\/font>/si', $str, $td);
  159.  
  160.                 $row['tanggal'] = trim($td[1][0]);
  161.                 $row['keterangan'] = trim($td[1][1]);
  162.                 $row['cabang'] = trim($td[1][2]);
  163.                 $row['jumlah'] = trim($td[1][3]);
  164.                 $row['jenis'] = trim($td[1][4]);
  165.                 $row['saldo'] = trim($td[1][5]);
  166.  
  167.                 $rows[]=$row;
  168.             }
  169.             $i++;
  170.         }
  171.  
  172.         return $rows;
  173.     }
  174.  
  175.     function logout(){
  176.         $this->browse($this->logout_url);
  177.     }
  178. }
  179.  
  180.  
  181. ?>
Add Comment
Please, Sign In to add comment