justhrun

curl->mandiri2.class.php

Aug 25th, 2016
1,763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.49 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',
  107.         strtotime($dari))."&fromYear=".date('Y', strtotime($dari))."&toDay=".date('d', strtotime($sampai))."&toMonth=".date('n',
  108.         strtotime($sampai))."&toYear=".date('Y', strtotime($sampai))."&sortType=Date&orderBy=ASC&lastTransaction=10";
  109.         //die($param);
  110.  
  111.         $result = $this->browse($this->mutasi_url,$param);
  112.         $mydata = $result['data'];
  113.         unset($result);
  114.  
  115.         return array(   'soawal'    => $this->getSaldoAwalAkhir($mydata,true),
  116.                         'mutasi'    => $this->parseMutasi($mydata),
  117.                         'soakhir'   => $this->getSaldoAwalAkhir($mydata,false)
  118.         );
  119.     }
  120.  
  121.     function getSaldoAwalAkhir($page,$lget) {
  122.         if($lget)
  123.             preg_match('/<span class="text-bold">Saldo Awal<\/span>(.*?)<\/span>/s', $page, $data);                    
  124.         else
  125.             preg_match('/<span class="text-bold">Saldo Akhir<\/span>(.*?)<\/span>/s', $page, $data);                    
  126.         $str = preg_replace("/\n+/","",$data[0]);
  127.         $str = preg_replace("/\s+/"," ",$str);        
  128.         $str = preg_replace("/\./","",$str);        
  129.         $str = preg_replace("/,/",".",$str);        
  130.         preg_match_all('/<td height="25" align="right" class="tabledata"><span class="text-bold">(.*?)<\/span>/si', $str, $trs);    
  131.         return $trs[1][0];
  132.     }
  133.  
  134.     function parseMutasi($page){
  135.         preg_match('/<table border="0" cellpadding="2" cellspacing="1" width="100%">(.*?)<\/table>/s', $page, $data);
  136.         preg_match_all('/<tr height="25">(.*?)<\/tr>/si', $data[0], $trs);
  137.  
  138.         $rows=array();
  139.         $i = 0;
  140.         foreach($trs[1] as $tr){
  141.             $str = preg_replace("/\n+/","",$tr);
  142.             $str = preg_replace("/<br>/"," ",$str);
  143.             $str = preg_replace("/\s+/"," ",$str);
  144.             $str = preg_replace("/\./","",$str);
  145.             $str = preg_replace("/,/",".",$str);
  146.             $strb = $str;
  147.  
  148.             if($i%2) {
  149.                 preg_match_all('/<td height="25" class="tabledata" bgcolor="#DDF2FA">(.*?)<\/td>/si', $str, $tda);
  150.                 preg_match_all('/<td height="25" class="tabledata" align="right" bgcolor="#DDF2FA">(.*?)<\/td>/si', $strb, $tdb);
  151.             } else {
  152.                 preg_match_all('/<td height="25" class="tabledata" bgcolor="">(.*?)<\/td>/si', $str, $tda);
  153.                 preg_match_all('/<td height="25" class="tabledata" align="right" bgcolor="">(.*?)<\/td>/si', $strb, $tdb);
  154.             }
  155.  
  156.             $row['tanggal'] = $tda[1][0];
  157.             $row['keterangan'] = $tda[1][1];
  158.             $row['debet'] = $tdb[1][0];
  159.             $row['credit'] = $tdb[1][1];
  160.             $rows[]=$row;
  161.  
  162.             $i++;
  163.         }
  164.         return $rows;
  165.     }
  166.  
  167.     function logout(){
  168.         $this->browse($this->logout_url);
  169.     }
  170.  
  171. }
  172.  
  173. ?>
Advertisement
Add Comment
Please, Sign In to add comment