justhrun

curl->bank.class.php

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