Advertisement
justhrun

curl->mandiri.class.php

Jul 29th, 2014
821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.52 KB | None | 0 0
  1. <?php
  2. /****
  3. CLASS Bank Mandiri
  4. ***/
  5.  
  6. class bankMandiri{
  7.         var $userid = "";
  8.         var $password = "";
  9.         var $rekening = "1";
  10.  
  11.         var $login_url = "https://ib.bankmandiri.co.id/retail/Login.do?action=form&lang=in_ID";
  12.         var $login_process_url="https://ib.bankmandiri.co.id/retail/Login.do";
  13.         var $login_success_url="https://ib.bankmandiri.co.id/retail/Redirect.do?action=forward";
  14.  
  15.         var $mutasi_form_url="https://ib.bankmandiri.co.id/retail/TrxHistoryInq.do?action=form";
  16.         var $mutasi_url = "https://ib.bankmandiri.co.id/retail/TrxHistoryInq.do";
  17.         var $logout_url = "https://ib.bankmandiri.co.id/retail/Logout.do?action=result";
  18.  
  19.         var $cookie="./cookie.txt";
  20.         var $ch;
  21.         var $dom;
  22.  
  23.         function __construct(){
  24.                 $this->dom = new DOMDocument();
  25.         }
  26.  
  27.         function openCurl(){
  28.  
  29.                 $this->ch = curl_init();
  30.                 curl_setopt($this->ch, CURLOPT_HEADER,1);
  31.                 curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,1);
  32.                 curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);
  33.                 curl_setopt($this->ch, CURLOPT_USERAGENT,
  34.                         "Mozilla/5.0 (X11; Linux i686 (x86_64); rv:2.0b4pre) Gecko/20100812 Minefield/4.0b4pre");
  35.                 curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->cookie);
  36.                 curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->cookie);
  37.                 curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
  38.                 curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 2);
  39.                 curl_setopt($this->ch, CURLOPT_SSLVERSION, 3);
  40.         }
  41.  
  42.         function closeCurl(){
  43.                 curl_close($this->ch);
  44.         }
  45.  
  46.         function browse($url,$post=false,$follow=false){
  47.                 $this->openCurl();
  48.                 curl_setopt($this->ch, CURLOPT_URL, $url);
  49.  
  50.                 if($post){
  51.                         curl_setopt($this->ch, CURLOPT_POST, 1 );
  52.                         curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post);
  53.                 }
  54.  
  55.                 if($follow){
  56.                         curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);
  57.                 }
  58.  
  59.                 $result = array("data"=>curl_exec($this->ch),"info"=>curl_getinfo($this->ch));
  60.  
  61.                 if(!$result['data']){
  62.                         echo 'Curl error: '.curl_error($this->ch);
  63.                 }
  64.  
  65.                 $result['headers'] = substr($result['data'], 0, $result['info']['header_size']);
  66.                 //      echo $result['data'];
  67.                 $this->closeCurl();
  68.  
  69.                 return $result;
  70.         }
  71.  
  72.         function login(){
  73.                 $this->browse($this->login_url);
  74.                 //curl_setopt($this->ch, CURLOPT_REFERER, $this->login_url);
  75.                 $param = "action=result&userID=".$this->userid."&password=".$this->password."&image.x=0&image.y=0";
  76.                 $result = $this->browse($this->login_process_url,$param);
  77.                 return $isLogin = strpos($result['headers'],$this->login_success_url);
  78.         }
  79.  
  80.         function mutasi($dari,$sampai,$rekening=false){
  81.                 if(!$rekening){
  82.                         $rekening=$this->rekening;
  83.                 }
  84.  
  85.                 $page = $this->browse($this->mutasi_form_url);
  86.                 $dom = new DOMDocument();
  87.  
  88.                 libxml_use_internal_errors(true);
  89.                 $dom->loadHTML($page['data']);
  90.                 $nodes = $dom->getElementsByTagName('select');
  91.  
  92.                 foreach($nodes as $node){
  93.                         if($node->getAttribute('name')=='fromAccountID'){
  94.                                 $options = $node->getElementsByTagName('option');
  95.                                 $i=1;
  96.  
  97.                                 foreach($options as $option){
  98.                                         if($i=$this->rekening){
  99.                                                 $param = "fromAccountID=".$option->getAttribute('value');
  100.                                         }
  101.                                         $i++;
  102.                                 }
  103.                         }
  104.                 }
  105.  
  106.                 $param.="&action=result&searchType=R&fromDay=".date('d', strtotime($dari))."&fromMonth=".date('n', strtotime($dari))."&fromYear=".date('Y', strtotime($dari))."&toDay=".date('d', strtotime($sampai))."&toMonth=".date('n', strtotime($sampai))."&toYear=".date('Y', strtotime($sampai))."&sortType=Date&orderBy=ASC&lastTransaction=10";
  107. //              die($param);
  108.  
  109.                 $result = $this->browse($this->mutasi_url,$param);
  110.                 $mydata = $result['data'];
  111.                 unset($result);
  112.  
  113.                 return array(   'soawal'        => $this->getSaldoAwalAkhir($mydata,true),
  114.                                                 'mutasi'        => $this->parseMutasi($mydata),
  115.                                                 'soakhir'       => $this->getSaldoAwalAkhir($mydata,false)
  116.                 );
  117.         }
  118.  
  119.         function getSaldoAwalAkhir($page,$lget) {
  120.                 if($lget)
  121.                         preg_match('/<span class="text-bold">Saldo Awal<\/span>(.*?)<\/span>/s', $page, $data);                    
  122.                 else
  123.                         preg_match('/<span class="text-bold">Saldo Akhir<\/span>(.*?)<\/span>/s', $page, $data);                    
  124.                 $str = preg_replace("/\n+/","",$data[0]);
  125.                 $str = preg_replace("/\s+/"," ",$str);        
  126.                 $str = preg_replace("/\./","",$str);        
  127.                 $str = preg_replace("/,/",".",$str);        
  128.                 preg_match_all('/<td height="25" align="right" class="tabledata"><span class="text-bold">(.*?)<\/span>/si', $str, $trs);    
  129.                 return $trs[1][0];
  130.         }
  131.  
  132.         function parseMutasi($page){
  133.                 preg_match('/<table border="0" cellpadding="2" cellspacing="1" width="100%">(.*?)<\/table>/s', $page, $data);
  134.                 preg_match_all('/<tr height="25">(.*?)<\/tr>/si', $data[0], $trs);
  135.  
  136.                 $rows=array();
  137.                 $i = 0;
  138.                 foreach($trs[1] as $tr){
  139.                         $str = preg_replace("/\n+/","",$tr);
  140.                         $str = preg_replace("/<br>/"," ",$str);
  141.                         $str = preg_replace("/\s+/"," ",$str);
  142.                         $str = preg_replace("/\./","",$str);
  143.                         $str = preg_replace("/,/",".",$str);
  144.                         $strb = $str;
  145.  
  146.                         if($i%2) {
  147.                                 preg_match_all('/<td height="25" class="tabledata" bgcolor="#DDF2FA">(.*?)<\/td>/si', $str, $tda);
  148.                                 preg_match_all('/<td height="25" class="tabledata" align="right" bgcolor="#DDF2FA">(.*?)<\/td>/si', $strb, $tdb);
  149.                         } else {
  150.                                 preg_match_all('/<td height="25" class="tabledata" bgcolor="">(.*?)<\/td>/si', $str, $tda);
  151.                                 preg_match_all('/<td height="25" class="tabledata" align="right" bgcolor="">(.*?)<\/td>/si', $strb, $tdb);
  152.                         }
  153.  
  154.                         $row['tanggal'] = $tda[1][0];
  155.                         $row['keterangan'] = $tda[1][1];
  156.                         $row['debet'] = $tdb[1][0];
  157.                         $row['credit'] = $tdb[1][1];
  158.                         $rows[]=$row;
  159.  
  160.                         $i++;
  161.                 }
  162.                 return $rows;
  163.         }
  164.  
  165.         function logout(){
  166.                 $this->browse($this->logout_url);
  167.         }
  168.  
  169. }
  170.  
  171. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement