Commit 12bc3d93d40d23c81a16306a8e847592b86c5c98

Authored by Adhidarma Hadiwinoto
1 parent e9dc6acc6e
Exists in master

source_page, fp, dan balance

Showing 2 changed files with 43 additions and 28 deletions Side-by-side Diff

... ... @@ -11,7 +11,9 @@ Class KiselScrap {
11 11 var $session_status = 1;
12 12 var $resp_str = '';
13 13 var $resp_target = '';
14   - var $resp_xml = '';
  14 + var $resp_xml = '';
  15 + var $source_page = '';
  16 + var $fp = '';
15 17  
16 18 function setRandomUserAgent()
17 19 {
... ... @@ -67,9 +69,9 @@ Class KiselScrap {
67 69 $log = "[$date] error" . curl_errno($ch)."\n";
68 70 }
69 71  
70   - #$fd = fopen("scrapper_kisel.log", "a+");
71   - #fwrite($fd, $log);
72   - #fclose($fd);
  72 + $fd = fopen("scrapper_kisel.log", "a+");
  73 + fwrite($fd, $log);
  74 + fclose($fd);
73 75  
74 76 curl_close($ch);
75 77  
... ... @@ -134,6 +136,7 @@ Class KiselScrap {
134 136 $arr_resp = explode("|", $resp_value);
135 137  
136 138 if($type == 1) {
  139 + $strBal = $this->balance();
137 140 if (preg_match("/TRANSAKSI SUKSES/i", $this->resp_str)) {
138 141 if(count($arr_resp) > 14){
139 142 $xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
... ... @@ -143,6 +146,7 @@ Class KiselScrap {
143 146 $xml_str .= "<harga>$arr_resp[11]</harga>";
144 147 $xml_str .= "<ref_num>$arr_resp[3]</ref_num>";
145 148 $xml_str .= "<kode_voucher>$arr_resp[13]</kode_voucher>";
  149 + $xml_str .= "<stock>$strBal</stock>";
146 150 $xml_str .= "<info>$arr_resp[14]</info>";
147 151 $xml_str .= "</trx_response>";
148 152 }
... ... @@ -174,6 +178,13 @@ Class KiselScrap {
174 178 # hit response transaksi ke ST24
175 179 #$this->send_form($this->resp_target, '', $arr_resp);
176 180 }
  181 + else {
  182 + preg_match("/name=\"_sourcePage\" value=\"(\\S+)\"/s", $this->resp_str, $matches);
  183 + $this->source_page = $matches[1];
  184 +
  185 + preg_match("/name=\"__fp\" value=\"(\\S+)\"/s", $this->resp_str, $matches2);
  186 + $this->fp = $matches2[1];
  187 + }
177 188 }
178 189 }
179 190  
... ... @@ -201,21 +212,25 @@ Class KiselScrap {
201 212 }
202 213 }
203 214 $resp_value = ltrim(rtrim($resp_value));
204   - print $resp_value."\n";
  215 +
  216 + #print $resp_value."\n";
205 217 # Stock Anda Saat ini : ; 10K = 1; 20K = 1; 25K = 0; 50K = 1; 100K = 1; 150K = 1; 200K = 1; 300K = 1; 500K = 1
206   - preg_match("/^Stock Anda Saat ini : ; (\S+) = (\S+); (\S+) = (\S+); (\S+) = (\S+); (\S+) = (\S+); (\S+) = (\S+); (\S+) = (\S+); (\S+) = (\S+); (\S+) = (\S+); (\S+) = (\S+)/s", $resp_value, $matches);
  218 + #preg_match("/^Stock Anda Saat ini : ; (\S+) = (\S+); (\S+) = (\S+); (\S+) = (\S+); (\S+) = (\S+); (\S+) = (\S+); (\S+) = (\S+); (\S+) = (\S+); (\S+) = (\S+); (\S+) = (\S+)/s", $resp_value, $matches);
207 219 #print_r($matches);
208   - $arr_stk = array();
209   - $arr_stk[$matches[1]] = $matches[2];
210   - $arr_stk[$matches[3]] = $matches[4];
211   - $arr_stk[$matches[5]] = $matches[6];
212   - $arr_stk[$matches[7]] = $matches[8];
213   - $arr_stk[$matches[9]] = $matches[10];
214   - $arr_stk[$matches[11]] = $matches[12];
215   - $arr_stk[$matches[13]] = $matches[14];
216   - $arr_stk[$matches[15]] = $matches[16];
217   - $arr_stk[$matches[17]] = $matches[18];
218   - return $arr_stk;
  220 + #$arr_stk = array();
  221 + #$arr_stk[$matches[1]] = $matches[2];
  222 + #$arr_stk[$matches[3]] = $matches[4];
  223 + #$arr_stk[$matches[5]] = $matches[6];
  224 + #$arr_stk[$matches[7]] = $matches[8];
  225 + #$arr_stk[$matches[9]] = $matches[10];
  226 + #$arr_stk[$matches[11]] = $matches[12];
  227 + #$arr_stk[$matches[13]] = $matches[14];
  228 + #$arr_stk[$matches[15]] = $matches[16];
  229 + #$arr_stk[$matches[17]] = $matches[18];
  230 + #return $arr_stk;
  231 +
  232 + preg_match("/^Stock Anda Saat ini : ; (\\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+ \\S+ \= \\S+)/s", $resp_value, $matches);
  233 + return $matches[1];
219 234 }
220 235  
221 236 function send_form($url, $url_ref, $fields){
... ... @@ -258,10 +273,9 @@ Class KiselScrap {
258 273 $log = "[$date] error" . curl_errno($ch)."\n";
259 274 }
260 275  
261   - #$fd = fopen("scrapper_kisel.log", "a+");
262   - #fwrite($fd, $log);
263   - #fclose($fd);
264   -
  276 + $fd = fopen("scrapper_kisel.log", "a+");
  277 + fwrite($fd, $log);
  278 + fclose($fd);
265 279 curl_close ($ch);
266 280 $this->resp_str = $resp_str;
267 281 return 1;
... ... @@ -10,10 +10,7 @@ include(&#39;KiselScrap.php&#39;);
10 10 # '__fp' => 'wIlI6mnh04Y='
11 11 # );
12 12  
13   -$arrinqtelconext = array('goToPin' => 'next',
14   - '_sourcePage' => 'fRCY-X8ZXOIcbgrf1BkkxBM7KTI7S6exLVsnXnUiXn8=',
15   - '__fp' => 'wIlI6mnh04Y='
16   - );
  13 +
17 14  
18 15 $kisel = new KiselScrap();
19 16  
... ... @@ -35,6 +32,7 @@ $kisel-&gt;setRandomUserAgent();
35 32 $log = "";
36 33 // Format the date and time
37 34 $date = date("Y-m-d H:i:s");
  35 +$fd = fopen("scrapper_kisel.log", "a+");
38 36  
39 37  
40 38 $log = "[$date] Step-1 : get welcome page\n";
... ... @@ -69,15 +67,18 @@ if($kisel-&gt;session_status) {
69 67  
70 68 $log .= "[$date] Step-4 : send purchase telco\n";
71 69 $log .= "--------------------------------\n";
  70 +
  71 + $arrinqtelconext = array('goToPin' => 'next',
  72 + '_sourcePage' => $kisel->source_page,
  73 + '__fp' => $kisel->fp
  74 + );
  75 +
72 76 $kisel->send_form($purchasetelco_url, $purchasetelco_url, $arrinqtelconext);
73 77 $kisel->parseResponse("//table[@class='tblogin']/tbody/tr/td",1);
74 78 $kisel->printResponseXML();
75 79  
76   - /*
77   - $fd = fopen("scrapper_kisel.log", "a+");
78 80 fwrite($fd, $log);
79 81 fclose($fd);
80   - */
81 82 }
82 83  
83 84 ?>