justhrun

curl->bca2.class.php

Aug 25th, 2016
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.34 KB | None | 0 0
  1. <?php
  2. /****
  3. CLASS Bank BCA
  4. 20150504: ada field baru dalam form login bca
  5. <input type="hidden" name="value(CurNum)" value="4rlc6l9YOHqRiBjSXvX04gMvbP29g32f"> <== karakternya bener2 random
  6. <input type="hidden" name="value(user_ip)" value="ip_address_yg_konek_ke_bca">
  7. <input type="hidden" name="value(browser_info)" value="Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36">
  8. ***/
  9.  
  10. class bankBCA{
  11.     var $userid = "";
  12.     var $password = "";
  13.     var $rekening = 1;
  14.  
  15.     var $login_url = "https://ibank.klikbca.com";
  16.     var $login_process_url="https://ibank.klikbca.com/authentication.do";
  17.     var $login_success="authentication.do?value(actions)=welcome";
  18.     var $menu_url="https://ibank.klikbca.com/nav_bar_indo/menu_bar.htm";
  19.     var $info_rekening="https://ibank.klikbca.com/nav_bar_indo/account_information_menu.htm";
  20.     var $mutasi_form_url="https://ibank.klikbca.com/accountstmt.do?value(actions)=acct_stmt";
  21.     var $mutasi_url = "https://ibank.klikbca.com/accountstmt.do?value(actions)=acctstmtview";
  22.     var $logout_url = "https://ibank.klikbca.com/authentication.do?value(actions)=logout";
  23.     var $cookie = "cookiejar";
  24.     var $ch;
  25.  
  26.     function openCurl(){
  27.         $this->ch = curl_init();
  28.        
  29.         curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);
  30.         curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,1);
  31.         curl_setopt($this->ch, CURLOPT_BINARYTRANSFER,1);
  32.         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");
  33.         curl_setopt($this->ch, CURLOPT_COOKIEJAR, realpath($this->cookie));
  34.         curl_setopt($this->ch, CURLOPT_COOKIEFILE, realpath($this->cookie));
  35.         curl_setopt($this->ch, CURLOPT_CAINFO, "cert/cacert.pem");
  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_url);
  75.  
  76.         $str = $result['data'];
  77.         $str = preg_replace("/\n+/","",$str);
  78.         $str = preg_replace("/<br>/"," ",$str);
  79.         $str = preg_replace("/\s+/"," ",$str);
  80.         $str = preg_replace("/,/","",$str);
  81.         /* 20160606: lenyap lagi
  82.         preg_match('/<input type="hidden" name="value\(CurNum\)" value="(.*?)">/si', $str, $match);
  83.         $CurNum = $match[1];
  84.         */
  85.         preg_match('/<input type="hidden" name="value\(user_ip\)" value="(.*?)">/si', $str, $match);
  86.         $user_ip = $match[1];
  87.  
  88.         //$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';
  89.         $params = array();
  90.         $params[] = 'value%28actions%29=login';
  91.         $params[] = 'value%28user_id%29=' . $this->userid;
  92.         $params[] = 'value%28pswd%29=' . $this->password;
  93.         $params[] = 'value%28user_ip%29=' . $user_ip;
  94.         //$params[] = 'value%28CurNum%29=' . $CurNum;
  95.         $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';
  96.         $params[] = 'value%28mobile%29=false';
  97.         $params[] = 'value%28Submit%29=LOGIN';
  98.         $params = implode( '&', $params );
  99.  
  100.         $result = $this->browse($this->login_process_url,$params,false,$this->login_url);
  101.         return $isLogin = strpos($result['data'],$this->login_success);
  102.         /*
  103.         if(strpos($result['data'],$this->login_success))
  104.             return false;
  105.         return $result['data'];
  106.         */
  107.     }
  108.  
  109.     function mutasi($dari,$sampai,$rekening=false){
  110.         if(!$rekening){
  111.             $rekening=$this->rekening;
  112.         }
  113.  
  114.         $page = $this->browse($this->menu_url,false,false,$this->login_process_url);
  115.         $page = $this->browse($this->info_rekening,false,false,$this->login_process_url);
  116.         $page = $this->browse($this->mutasi_form_url,false,false,$this->info_rekening);
  117.  
  118.         $params = array();
  119.         $t1 = explode( '-', $sampai );
  120.         $t0 = explode( '-', $dari );
  121.  
  122.         $params[] = 'value%28startDt%29=' . $t0[2];
  123.         $params[] = 'value%28startMt%29=' . $t0[1];
  124.         $params[] = 'value%28startYr%29=' . $t0[0];
  125.         $params[] = 'value%28endDt%29=' . $t1[2];
  126.         $params[] = 'value%28endMt%29=' . $t1[1];
  127.         $params[] = 'value%28endYr%29=' . $t1[0];
  128.         $params[] = 'value%28D1%29=0';
  129.         $params[] = 'value%28r1%29=1';
  130.         $params[] = 'value%28fDt%29=';
  131.         $params[] = 'value%28tDt%29=';
  132.         $params[] = 'value%28submit1%29=Lihat+Mutasi+Rekening';
  133.         $params = implode( '&', $params );
  134.  
  135.         $page=$this->browse($this->mutasi_url,$params,false,$this->info_rekening);
  136.         // return $page;
  137.         $xmut = preg_match('/<table border="1" width="100%" cellpadding="0" cellspacing="0" bordercolor="#ffffff">(.*?)<\/table>/s', $page['data'], $mutasi);
  138.         if(!$xmut) { return false; }
  139.        
  140.         preg_match_all('/<tr>(.*?)<\/tr>/si', $mutasi[0], $mut);
  141.         $arrmut = $this->parseMutasi($mut[0]);
  142.  
  143.         // 20160609: ambil juga info summary
  144.         $arrsumm = array( 'awal' => 0, 'kredit' => 0, 'debet' => 0, 'akhir' => 0);
  145.         $xsal = preg_match('/<table border="0" width="70%" cellpadding="0" cellspacing="0" bordercolor="#ffffff">(.*?)<\/table>/s', $page['data'], $saldo);
  146.         if($xsal) {
  147.             preg_match_all('/<td align="right"><font face="Verdana" size="1" color="#0000bb">(.*?)<\/font>/si', $saldo[0], $sal);
  148.             $arrsum = $this->parseSummary($sal[0]);
  149.         }
  150.  
  151.         return array( 'mutasi' => $arrmut, 'summary' => $arrsum );
  152.     }
  153.  
  154.     function parseSummary($data){
  155.         $arrkey = array('awal', 'kredit', 'debet', 'akhir');
  156.         $retval = array();
  157.         $i = 0;
  158.         foreach($data as $tr){
  159.             $str = preg_replace("/\n+/","",$tr);
  160.             $str = preg_replace("/\s+/"," ",$str);
  161.             $str = preg_replace("/,/","",$str);
  162.            
  163.             preg_match_all('/<font face="verdana" size="1" color="#0000bb">(.*?)<\/font>/si', $str, $td);
  164.  
  165.             $key = $arrkey[$i];
  166.             $retval[$key] = trim($td[1][0]);
  167.             $i++;
  168.         }
  169.         return $retval;
  170.     }
  171.    
  172.     function parseMutasi($data){
  173.         $rows=array();
  174.         $i = 1;
  175.  
  176.         foreach($data as $tr){
  177.             if($i>1){
  178.                 $str = preg_replace("/\n+/","",$tr);
  179.                 $str = preg_replace("/<br>/"," ",$str);
  180.                 $str = preg_replace("/\s+/"," ",$str);
  181.                 $str = preg_replace("/,/","",$str);
  182.  
  183.                 preg_match_all('/<font face="verdana" size="1" color="#0000bb">(.*?)<\/font>/si', $str, $td);
  184.  
  185.                 $row['tanggal'] = trim($td[1][0]);
  186.                 $row['keterangan'] = trim($td[1][1]);
  187.                 $row['cabang'] = trim($td[1][2]);
  188.                 $row['jumlah'] = trim($td[1][3]);
  189.                 $row['jenis'] = trim($td[1][4]);
  190.                 $row['saldo'] = trim($td[1][5]);
  191.  
  192.                 $rows[]=$row;
  193.             }
  194.             $i++;
  195.         }
  196.  
  197.         return $rows;
  198.     }
  199.  
  200.     function logout(){
  201.         $this->browse($this->logout_url);
  202.     }
  203. }
  204.  
  205. ?>
Advertisement
Add Comment
Please, Sign In to add comment