Commit 12bc3d93d40d23c81a16306a8e847592b86c5c98
1 parent
e9dc6acc6e
Exists in
master
source_page, fp, dan balance
Showing 2 changed files with 43 additions and 28 deletions Inline Diff
KiselScrap.php
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | Class KiselScrap { | 3 | Class KiselScrap { |
4 | 4 | ||
5 | # Object properties | 5 | # Object properties |
6 | var $reqid = ''; | 6 | var $reqid = ''; |
7 | var $msisdn = ''; | 7 | var $msisdn = ''; |
8 | var $product = ''; | 8 | var $product = ''; |
9 | var $user_agent = ''; | 9 | var $user_agent = ''; |
10 | var $session_id = ''; | 10 | var $session_id = ''; |
11 | var $session_status = 1; | 11 | var $session_status = 1; |
12 | var $resp_str = ''; | 12 | var $resp_str = ''; |
13 | var $resp_target = ''; | 13 | var $resp_target = ''; |
14 | var $resp_xml = ''; | 14 | var $resp_xml = ''; |
15 | var $source_page = ''; | ||
16 | var $fp = ''; | ||
15 | 17 | ||
16 | function setRandomUserAgent() | 18 | function setRandomUserAgent() |
17 | { | 19 | { |
18 | $userAgents=array( | 20 | $userAgents=array( |
19 | "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)", | 21 | "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)", |
20 | "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6", | 22 | "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6", |
21 | "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)", | 23 | "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)", |
22 | "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)", | 24 | "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)", |
23 | "Opera/9.20 (Windows NT 6.0; U; en)", | 25 | "Opera/9.20 (Windows NT 6.0; U; en)", |
24 | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.50", | 26 | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.50", |
25 | "Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.1) Opera 7.02 [en]", | 27 | "Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.1) Opera 7.02 [en]", |
26 | "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; fr; rv:1.7) Gecko/20040624 Firefox/0.9", | 28 | "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; fr; rv:1.7) Gecko/20040624 Firefox/0.9", |
27 | "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/48 (like Gecko) Safari/48" | 29 | "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/48 (like Gecko) Safari/48" |
28 | ); | 30 | ); |
29 | $random = rand(0,count($userAgents)-1); | 31 | $random = rand(0,count($userAgents)-1); |
30 | 32 | ||
31 | $this->user_agent = $userAgents[$random]; | 33 | $this->user_agent = $userAgents[$random]; |
32 | } | 34 | } |
33 | 35 | ||
34 | function setTrxParam($reqid, $msisdn, $product) { | 36 | function setTrxParam($reqid, $msisdn, $product) { |
35 | $this->reqid = $reqid; | 37 | $this->reqid = $reqid; |
36 | $this->msisdn = $msisdn; | 38 | $this->msisdn = $msisdn; |
37 | $this->product = $product; | 39 | $this->product = $product; |
38 | } | 40 | } |
39 | 41 | ||
40 | function getRandomUserAgent() { | 42 | function getRandomUserAgent() { |
41 | return $this->user_agent; | 43 | return $this->user_agent; |
42 | } | 44 | } |
43 | 45 | ||
44 | function get_page($url){ | 46 | function get_page($url){ |
45 | 47 | ||
46 | if (!function_exists('curl_init')){ | 48 | if (!function_exists('curl_init')){ |
47 | die('Sorry cURL is not installed!'); | 49 | die('Sorry cURL is not installed!'); |
48 | } | 50 | } |
49 | 51 | ||
50 | $ch = curl_init(); | 52 | $ch = curl_init(); |
51 | curl_setopt($ch, CURLOPT_URL, $url); | 53 | curl_setopt($ch, CURLOPT_URL, $url); |
52 | curl_setopt($ch, CURLOPT_REFERER, $url); | 54 | curl_setopt($ch, CURLOPT_REFERER, $url); |
53 | curl_setopt($ch, CURLOPT_USERAGENT, $this->getRandomUserAgent()); | 55 | curl_setopt($ch, CURLOPT_USERAGENT, $this->getRandomUserAgent()); |
54 | curl_setopt($ch, CURLOPT_HEADER, 1); | 56 | curl_setopt($ch, CURLOPT_HEADER, 1); |
55 | 57 | ||
56 | curl_setopt($ch, CURLOPT_COOKIE, 'JSESSIONID=' . $this->getSessionId()); | 58 | curl_setopt($ch, CURLOPT_COOKIE, 'JSESSIONID=' . $this->getSessionId()); |
57 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | 59 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
58 | session_write_close(); | 60 | session_write_close(); |
59 | $output = curl_exec($ch); | 61 | $output = curl_exec($ch); |
60 | 62 | ||
61 | $date = date("Y-m-d H:i:s"); | 63 | $date = date("Y-m-d H:i:s"); |
62 | if(!curl_errno($ch)) | 64 | if(!curl_errno($ch)) |
63 | { | 65 | { |
64 | $info = curl_getinfo($ch); | 66 | $info = curl_getinfo($ch); |
65 | $log = "[$date] Took " . $info['total_time'] . ' seconds to send a request to ' . $info['url']."\n"; | 67 | $log = "[$date] Took " . $info['total_time'] . ' seconds to send a request to ' . $info['url']."\n"; |
66 | } else { | 68 | } else { |
67 | $log = "[$date] error" . curl_errno($ch)."\n"; | 69 | $log = "[$date] error" . curl_errno($ch)."\n"; |
68 | } | 70 | } |
69 | 71 | ||
70 | #$fd = fopen("scrapper_kisel.log", "a+"); | 72 | $fd = fopen("scrapper_kisel.log", "a+"); |
71 | #fwrite($fd, $log); | 73 | fwrite($fd, $log); |
72 | #fclose($fd); | 74 | fclose($fd); |
73 | 75 | ||
74 | curl_close($ch); | 76 | curl_close($ch); |
75 | 77 | ||
76 | if(preg_match("/HTTP\/1\.1 302 Found/i", $output)) { | 78 | if(preg_match("/HTTP\/1\.1 302 Found/i", $output)) { |
77 | $this->session_status = -1; | 79 | $this->session_status = -1; |
78 | } | 80 | } |
79 | return 1; | 81 | return 1; |
80 | } | 82 | } |
81 | 83 | ||
82 | /** | 84 | /** |
83 | * Determine if a variable is iterable. i.e. can be used to loop over. | 85 | * Determine if a variable is iterable. i.e. can be used to loop over. |
84 | * | 86 | * |
85 | * @return bool | 87 | * @return bool |
86 | */ | 88 | */ |
87 | function isIterable($var) | 89 | function isIterable($var) |
88 | { | 90 | { |
89 | return $var !== null | 91 | return $var !== null |
90 | && (is_array($var) | 92 | && (is_array($var) |
91 | || $var instanceof Traversable | 93 | || $var instanceof Traversable |
92 | || $var instanceof Iterator | 94 | || $var instanceof Iterator |
93 | || $var instanceof IteratorAggregate); | 95 | || $var instanceof IteratorAggregate); |
94 | } | 96 | } |
95 | 97 | ||
96 | function clearResponseStr() { | 98 | function clearResponseStr() { |
97 | $this->resp_str = ''; | 99 | $this->resp_str = ''; |
98 | } | 100 | } |
99 | 101 | ||
100 | function printResponseStr() { | 102 | function printResponseStr() { |
101 | print $this->resp_str."\n"; | 103 | print $this->resp_str."\n"; |
102 | } | 104 | } |
103 | 105 | ||
104 | function printResponseXML() { | 106 | function printResponseXML() { |
105 | print $this->resp_xml; | 107 | print $this->resp_xml; |
106 | } | 108 | } |
107 | 109 | ||
108 | function parseResponse($query,$type) { | 110 | function parseResponse($query,$type) { |
109 | $dom = new DOMDocument; | 111 | $dom = new DOMDocument; |
110 | libxml_use_internal_errors(true); | 112 | libxml_use_internal_errors(true); |
111 | #print $this->resp_str; | 113 | #print $this->resp_str; |
112 | if (!@$dom->loadHTML($this->resp_str)) | 114 | if (!@$dom->loadHTML($this->resp_str)) |
113 | { | 115 | { |
114 | $errors=""; | 116 | $errors=""; |
115 | foreach (libxml_get_errors() as $error) { | 117 | foreach (libxml_get_errors() as $error) { |
116 | $errors.=$error->message."\n"; | 118 | $errors.=$error->message."\n"; |
117 | } | 119 | } |
118 | libxml_clear_errors(); | 120 | libxml_clear_errors(); |
119 | print "libxml errors: $errors \n"; | 121 | print "libxml errors: $errors \n"; |
120 | return; | 122 | return; |
121 | } | 123 | } |
122 | 124 | ||
123 | $xpath = new DOMXPath($dom); | 125 | $xpath = new DOMXPath($dom); |
124 | $entries = $xpath->query($query); | 126 | $entries = $xpath->query($query); |
125 | 127 | ||
126 | if ($this->isIterable($entries)) | 128 | if ($this->isIterable($entries)) |
127 | { | 129 | { |
128 | $resp_value = ''; | 130 | $resp_value = ''; |
129 | foreach ($entries as $entry) { | 131 | foreach ($entries as $entry) { |
130 | if(ltrim(rtrim($entry->nodeValue)) != '' and !preg_match("/setTimeout/",$entry->nodeValue)) { | 132 | if(ltrim(rtrim($entry->nodeValue)) != '' and !preg_match("/setTimeout/",$entry->nodeValue)) { |
131 | $resp_value .= ltrim(rtrim($entry->nodeValue))."|"; | 133 | $resp_value .= ltrim(rtrim($entry->nodeValue))."|"; |
132 | } | 134 | } |
133 | } | 135 | } |
134 | $arr_resp = explode("|", $resp_value); | 136 | $arr_resp = explode("|", $resp_value); |
135 | 137 | ||
136 | if($type == 1) { | 138 | if($type == 1) { |
139 | $strBal = $this->balance(); | ||
137 | if (preg_match("/TRANSAKSI SUKSES/i", $this->resp_str)) { | 140 | if (preg_match("/TRANSAKSI SUKSES/i", $this->resp_str)) { |
138 | if(count($arr_resp) > 14){ | 141 | if(count($arr_resp) > 14){ |
139 | $xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; | 142 | $xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; |
140 | $xml_str .= "<trx_response>"; | 143 | $xml_str .= "<trx_response>"; |
141 | $xml_str .= "<product>$arr_resp[5]</product>"; | 144 | $xml_str .= "<product>$arr_resp[5]</product>"; |
142 | $xml_str .= "<msisdn>$arr_resp[7]</msisdn>"; | 145 | $xml_str .= "<msisdn>$arr_resp[7]</msisdn>"; |
143 | $xml_str .= "<harga>$arr_resp[11]</harga>"; | 146 | $xml_str .= "<harga>$arr_resp[11]</harga>"; |
144 | $xml_str .= "<ref_num>$arr_resp[3]</ref_num>"; | 147 | $xml_str .= "<ref_num>$arr_resp[3]</ref_num>"; |
145 | $xml_str .= "<kode_voucher>$arr_resp[13]</kode_voucher>"; | 148 | $xml_str .= "<kode_voucher>$arr_resp[13]</kode_voucher>"; |
149 | $xml_str .= "<stock>$strBal</stock>"; | ||
146 | $xml_str .= "<info>$arr_resp[14]</info>"; | 150 | $xml_str .= "<info>$arr_resp[14]</info>"; |
147 | $xml_str .= "</trx_response>"; | 151 | $xml_str .= "</trx_response>"; |
148 | } | 152 | } |
149 | else { | 153 | else { |
150 | $xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; | 154 | $xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; |
151 | $xml_str .= "<trx_response>"; | 155 | $xml_str .= "<trx_response>"; |
152 | $xml_str .= "<info>Error Parsing</info>"; | 156 | $xml_str .= "<info>Error Parsing</info>"; |
153 | $xml_str .= "</trx_response>"; | 157 | $xml_str .= "</trx_response>"; |
154 | } | 158 | } |
155 | } else { | 159 | } else { |
156 | if(count($arr_resp) > 13){ | 160 | if(count($arr_resp) > 13){ |
157 | $xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; | 161 | $xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; |
158 | $xml_str .= "<trx_response>"; | 162 | $xml_str .= "<trx_response>"; |
159 | $xml_str .= "<product>$arr_resp[5]</product>"; | 163 | $xml_str .= "<product>$arr_resp[5]</product>"; |
160 | $xml_str .= "<msisdn>$arr_resp[7]</msisdn>"; | 164 | $xml_str .= "<msisdn>$arr_resp[7]</msisdn>"; |
161 | $xml_str .= "<harga>$arr_resp[11]</harga>"; | 165 | $xml_str .= "<harga>$arr_resp[11]</harga>"; |
162 | $xml_str .= "<info>$arr_resp[13]</info>"; | 166 | $xml_str .= "<info>$arr_resp[13]</info>"; |
163 | $xml_str .= "</trx_response>"; | 167 | $xml_str .= "</trx_response>"; |
164 | } | 168 | } |
165 | else { | 169 | else { |
166 | $xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; | 170 | $xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; |
167 | $xml_str .= "<trx_response>"; | 171 | $xml_str .= "<trx_response>"; |
168 | $xml_str .= "<info>Error Parsing</info>"; | 172 | $xml_str .= "<info>Error Parsing</info>"; |
169 | $xml_str .= "</trx_response>"; | 173 | $xml_str .= "</trx_response>"; |
170 | } | 174 | } |
171 | } | 175 | } |
172 | 176 | ||
173 | $this->resp_xml = $xml_str; | 177 | $this->resp_xml = $xml_str; |
174 | # hit response transaksi ke ST24 | 178 | # hit response transaksi ke ST24 |
175 | #$this->send_form($this->resp_target, '', $arr_resp); | 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 | ||
180 | function balance() { | 191 | function balance() { |
181 | $dom = new DOMDocument; | 192 | $dom = new DOMDocument; |
182 | libxml_use_internal_errors(true); | 193 | libxml_use_internal_errors(true); |
183 | if (!@$dom->loadHTML($this->resp_str)) | 194 | if (!@$dom->loadHTML($this->resp_str)) |
184 | { | 195 | { |
185 | $errors=""; | 196 | $errors=""; |
186 | foreach (libxml_get_errors() as $error) { | 197 | foreach (libxml_get_errors() as $error) { |
187 | $errors.=$error->message."\n"; | 198 | $errors.=$error->message."\n"; |
188 | } | 199 | } |
189 | libxml_clear_errors(); | 200 | libxml_clear_errors(); |
190 | print "libxml errors: $errors \n"; | 201 | print "libxml errors: $errors \n"; |
191 | return; | 202 | return; |
192 | } | 203 | } |
193 | 204 | ||
194 | $xpath = new DOMXPath($dom); | 205 | $xpath = new DOMXPath($dom); |
195 | $entries = $xpath->query("//div[@id='header']/table[@width='98%']/tr/td[@align='center']"); | 206 | $entries = $xpath->query("//div[@id='header']/table[@width='98%']/tr/td[@align='center']"); |
196 | 207 | ||
197 | $resp_value = ''; | 208 | $resp_value = ''; |
198 | foreach ($entries as $entry) { | 209 | foreach ($entries as $entry) { |
199 | if(ltrim(rtrim($entry->nodeValue)) != '' ) { | 210 | if(ltrim(rtrim($entry->nodeValue)) != '' ) { |
200 | $resp_value .= $entry->nodeValue; | 211 | $resp_value .= $entry->nodeValue; |
201 | } | 212 | } |
202 | } | 213 | } |
203 | $resp_value = ltrim(rtrim($resp_value)); | 214 | $resp_value = ltrim(rtrim($resp_value)); |
204 | print $resp_value."\n"; | 215 | |
216 | #print $resp_value."\n"; | ||
205 | # Stock Anda Saat ini : ; 10K = 1; 20K = 1; 25K = 0; 50K = 1; 100K = 1; 150K = 1; 200K = 1; 300K = 1; 500K = 1 | 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 | #print_r($matches); | 219 | #print_r($matches); |
208 | $arr_stk = array(); | 220 | #$arr_stk = array(); |
209 | $arr_stk[$matches[1]] = $matches[2]; | 221 | #$arr_stk[$matches[1]] = $matches[2]; |
210 | $arr_stk[$matches[3]] = $matches[4]; | 222 | #$arr_stk[$matches[3]] = $matches[4]; |
211 | $arr_stk[$matches[5]] = $matches[6]; | 223 | #$arr_stk[$matches[5]] = $matches[6]; |
212 | $arr_stk[$matches[7]] = $matches[8]; | 224 | #$arr_stk[$matches[7]] = $matches[8]; |
213 | $arr_stk[$matches[9]] = $matches[10]; | 225 | #$arr_stk[$matches[9]] = $matches[10]; |
214 | $arr_stk[$matches[11]] = $matches[12]; | 226 | #$arr_stk[$matches[11]] = $matches[12]; |
215 | $arr_stk[$matches[13]] = $matches[14]; | 227 | #$arr_stk[$matches[13]] = $matches[14]; |
216 | $arr_stk[$matches[15]] = $matches[16]; | 228 | #$arr_stk[$matches[15]] = $matches[16]; |
217 | $arr_stk[$matches[17]] = $matches[18]; | 229 | #$arr_stk[$matches[17]] = $matches[18]; |
218 | return $arr_stk; | 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 | function send_form($url, $url_ref, $fields){ | 236 | function send_form($url, $url_ref, $fields){ |
222 | 237 | ||
223 | $postvars = ""; | 238 | $postvars = ""; |
224 | foreach($fields as $k => $v) | 239 | foreach($fields as $k => $v) |
225 | { | 240 | { |
226 | $postvars .= $k . '='.$v.'&'; | 241 | $postvars .= $k . '='.$v.'&'; |
227 | } | 242 | } |
228 | $postvars = rtrim($postvars, '&'); | 243 | $postvars = rtrim($postvars, '&'); |
229 | 244 | ||
230 | if (!function_exists('curl_init')){ | 245 | if (!function_exists('curl_init')){ |
231 | die('Sorry cURL is not installed!'); | 246 | die('Sorry cURL is not installed!'); |
232 | } | 247 | } |
233 | 248 | ||
234 | $ch = curl_init(); | 249 | $ch = curl_init(); |
235 | curl_setopt($ch, CURLOPT_URL,$url); | 250 | curl_setopt($ch, CURLOPT_URL,$url); |
236 | curl_setopt($ch, CURLOPT_REFERER, $url_ref); | 251 | curl_setopt($ch, CURLOPT_REFERER, $url_ref); |
237 | curl_setopt($ch, CURLOPT_USERAGENT, $this->getRandomUserAgent()); | 252 | curl_setopt($ch, CURLOPT_USERAGENT, $this->getRandomUserAgent()); |
238 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); | 253 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
239 | curl_setopt($ch, CURLOPT_HEADER, 1); | 254 | curl_setopt($ch, CURLOPT_HEADER, 1); |
240 | 255 | ||
241 | curl_setopt($ch, CURLOPT_COOKIE, "JSESSIONID=".$this->getSessionId()); | 256 | curl_setopt($ch, CURLOPT_COOKIE, "JSESSIONID=".$this->getSessionId()); |
242 | curl_setopt($ch, CURLOPT_POST, count($fields)); | 257 | curl_setopt($ch, CURLOPT_POST, count($fields)); |
243 | curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars); | 258 | curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars); |
244 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | 259 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
245 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | 260 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
246 | unset($postvars); | 261 | unset($postvars); |
247 | 262 | ||
248 | ob_start(); | 263 | ob_start(); |
249 | $resp_str = curl_exec($ch); | 264 | $resp_str = curl_exec($ch); |
250 | ob_end_clean(); | 265 | ob_end_clean(); |
251 | 266 | ||
252 | $date = date("Y-m-d H:i:s"); | 267 | $date = date("Y-m-d H:i:s"); |
253 | if(!curl_errno($ch)) | 268 | if(!curl_errno($ch)) |
254 | { | 269 | { |
255 | $info = curl_getinfo($ch); | 270 | $info = curl_getinfo($ch); |
256 | $log = "[$date] Took " . $info['total_time'] . ' seconds to send a request to ' . $info['url']."\n"; | 271 | $log = "[$date] Took " . $info['total_time'] . ' seconds to send a request to ' . $info['url']."\n"; |
257 | } else { | 272 | } else { |
258 | $log = "[$date] error" . curl_errno($ch)."\n"; | 273 | $log = "[$date] error" . curl_errno($ch)."\n"; |
259 | } | 274 | } |
260 | 275 | ||
261 | #$fd = fopen("scrapper_kisel.log", "a+"); | 276 | $fd = fopen("scrapper_kisel.log", "a+"); |
262 | #fwrite($fd, $log); | 277 | fwrite($fd, $log); |
263 | #fclose($fd); | 278 | fclose($fd); |
264 | |||
265 | curl_close ($ch); | 279 | curl_close ($ch); |
266 | $this->resp_str = $resp_str; | 280 | $this->resp_str = $resp_str; |
267 | return 1; | 281 | return 1; |
268 | 282 | ||
269 | } | 283 | } |
270 | 284 | ||
271 | function setSessionId($session_id){ | 285 | function setSessionId($session_id){ |
272 | $this->session_id = $session_id; | 286 | $this->session_id = $session_id; |
273 | } | 287 | } |
274 | 288 | ||
275 | function getSessionId() { | 289 | function getSessionId() { |
276 | return $this->session_id; | 290 | return $this->session_id; |
277 | } | 291 | } |
278 | 292 | ||
279 | 293 | ||
280 | function do_logout($sess_id) { | 294 | function do_logout($sess_id) { |
281 | if (!function_exists('curl_init')){ | 295 | if (!function_exists('curl_init')){ |
282 | die('Sorry cURL is not installed!'); | 296 | die('Sorry cURL is not installed!'); |
283 | } | 297 | } |
284 | 298 | ||
285 | $ch = curl_init(); | 299 | $ch = curl_init(); |
286 | curl_setopt($ch, CURLOPT_URL, $url); | 300 | curl_setopt($ch, CURLOPT_URL, $url); |
287 | curl_setopt($ch, CURLOPT_REFERER, $url_ref); | 301 | curl_setopt($ch, CURLOPT_REFERER, $url_ref); |
288 | curl_setopt($ch, CURLOPT_USERAGENT, $this->getRandomUserAgent()); | 302 | curl_setopt($ch, CURLOPT_USERAGENT, $this->getRandomUserAgent()); |
289 | curl_setopt($ch, CURLOPT_HEADER, 1); | 303 | curl_setopt($ch, CURLOPT_HEADER, 1); |
290 | curl_setopt($ch, CURLOPT_COOKIE, "JSESSIONID=".$this->get_sessionid()); | 304 | curl_setopt($ch, CURLOPT_COOKIE, "JSESSIONID=".$this->get_sessionid()); |
291 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | 305 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
292 | curl_exec($ch); | 306 | curl_exec($ch); |
293 | curl_close($ch); | 307 | curl_close($ch); |
294 | } | 308 | } |
295 | 309 | ||
296 | } | 310 | } |
297 | 311 | ||
298 | ?> | 312 | ?> |
scrap_kisel.php
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | include('kisel.conf.php'); | 3 | include('kisel.conf.php'); |
4 | include('KiselScrap.php'); | 4 | include('KiselScrap.php'); |
5 | 5 | ||
6 | #$arrinqtelco = array('customerId' => '08122027896', | 6 | #$arrinqtelco = array('customerId' => '08122027896', |
7 | # 'product' => 'SI10', | 7 | # 'product' => 'SI10', |
8 | # 'inquiry' => 'Inquiry', | 8 | # 'inquiry' => 'Inquiry', |
9 | # '_sourcePage' => 'fRCY-X8ZXOIcbgrf1BkkxBM7KTI7S6exLVsnXnUiXn8=', | 9 | # '_sourcePage' => 'fRCY-X8ZXOIcbgrf1BkkxBM7KTI7S6exLVsnXnUiXn8=', |
10 | # '__fp' => 'wIlI6mnh04Y=' | 10 | # '__fp' => 'wIlI6mnh04Y=' |
11 | # ); | 11 | # ); |
12 | 12 | ||
13 | $arrinqtelconext = array('goToPin' => 'next', | 13 | |
14 | '_sourcePage' => 'fRCY-X8ZXOIcbgrf1BkkxBM7KTI7S6exLVsnXnUiXn8=', | ||
15 | '__fp' => 'wIlI6mnh04Y=' | ||
16 | ); | ||
17 | 14 | ||
18 | $kisel = new KiselScrap(); | 15 | $kisel = new KiselScrap(); |
19 | 16 | ||
20 | $redis = new Redis(); | 17 | $redis = new Redis(); |
21 | $redis->connect($redis_url); | 18 | $redis->connect($redis_url); |
22 | $kisel->setSessionId($redis->get($redis_prefix.'01.sessionid')); | 19 | $kisel->setSessionId($redis->get($redis_prefix.'01.sessionid')); |
23 | 20 | ||
24 | // get querystring | 21 | // get querystring |
25 | $kisel->setTrxParam($_REQUEST['reqid'], $_REQUEST['msisdn'], $_REQUEST['product']); | 22 | $kisel->setTrxParam($_REQUEST['reqid'], $_REQUEST['msisdn'], $_REQUEST['product']); |
26 | $arrinqtelco = array('customerId' => $kisel->msisdn, | 23 | $arrinqtelco = array('customerId' => $kisel->msisdn, |
27 | 'product' => $kisel->product, | 24 | 'product' => $kisel->product, |
28 | 'inquiry' => 'Inquiry', | 25 | 'inquiry' => 'Inquiry', |
29 | '_sourcePage' => 'fRCY-X8ZXOIcbgrf1BkkxBM7KTI7S6exLVsnXnUiXn8=', | 26 | '_sourcePage' => 'fRCY-X8ZXOIcbgrf1BkkxBM7KTI7S6exLVsnXnUiXn8=', |
30 | '__fp' => 'wIlI6mnh04Y=' | 27 | '__fp' => 'wIlI6mnh04Y=' |
31 | ); | 28 | ); |
32 | 29 | ||
33 | $kisel->setRandomUserAgent(); | 30 | $kisel->setRandomUserAgent(); |
34 | 31 | ||
35 | $log = ""; | 32 | $log = ""; |
36 | // Format the date and time | 33 | // Format the date and time |
37 | $date = date("Y-m-d H:i:s"); | 34 | $date = date("Y-m-d H:i:s"); |
35 | $fd = fopen("scrapper_kisel.log", "a+"); | ||
38 | 36 | ||
39 | 37 | ||
40 | $log = "[$date] Step-1 : get welcome page\n"; | 38 | $log = "[$date] Step-1 : get welcome page\n"; |
41 | $log .= "--------------------------------\n"; | 39 | $log .= "--------------------------------\n"; |
42 | $kisel->get_page($welcome_url); | 40 | $kisel->get_page($welcome_url); |
43 | if(!$kisel->session_status) { | 41 | if(!$kisel->session_status) { |
44 | print "masuk"; | 42 | print "masuk"; |
45 | $log .= "Error Session Invalid. Please input session"; | 43 | $log .= "Error Session Invalid. Please input session"; |
46 | $err = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; | 44 | $err = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
47 | $err .= "<trx_response>\n"; | 45 | $err .= "<trx_response>\n"; |
48 | $err .= "<product>".$_REQUEST['product']."</product>\n"; | 46 | $err .= "<product>".$_REQUEST['product']."</product>\n"; |
49 | $err .= "<msisdn>".$_REQUEST['msisdn']."</msisdn>\n"; | 47 | $err .= "<msisdn>".$_REQUEST['msisdn']."</msisdn>\n"; |
50 | $err .= "<info>SESSION INVALID !!!</info>\n"; | 48 | $err .= "<info>SESSION INVALID !!!</info>\n"; |
51 | $err .= "</trx_response>"; | 49 | $err .= "</trx_response>"; |
52 | print $err; | 50 | print $err; |
53 | } | 51 | } |
54 | sleep(1); | 52 | sleep(1); |
55 | if($kisel->session_status) { | 53 | if($kisel->session_status) { |
56 | $log .= "[$date] Step-2 : get purchase telco page\n"; | 54 | $log .= "[$date] Step-2 : get purchase telco page\n"; |
57 | $log .= "--------------------------------\n"; | 55 | $log .= "--------------------------------\n"; |
58 | $kisel->get_page($purchasetelco_url); | 56 | $kisel->get_page($purchasetelco_url); |
59 | #$prevbal = array(); | 57 | #$prevbal = array(); |
60 | #$prevbal = $kisel->balance(); | 58 | #$prevbal = $kisel->balance(); |
61 | #print_r($prevbal); | 59 | #print_r($prevbal); |
62 | sleep(1); | 60 | sleep(1); |
63 | 61 | ||
64 | $log .= "[$date] Step-3 : send inquiry telco\n"; | 62 | $log .= "[$date] Step-3 : send inquiry telco\n"; |
65 | $log .= "--------------------------------\n"; | 63 | $log .= "--------------------------------\n"; |
66 | $kisel->send_form($purchasetelco_url, $purchasetelco_url, $arrinqtelco); | 64 | $kisel->send_form($purchasetelco_url, $purchasetelco_url, $arrinqtelco); |
67 | $kisel->parseResponse("//table[@class='tblogin']/tbody/tr/td",0); | 65 | $kisel->parseResponse("//table[@class='tblogin']/tbody/tr/td",0); |
68 | sleep(1); | 66 | sleep(1); |
69 | 67 | ||
70 | $log .= "[$date] Step-4 : send purchase telco\n"; | 68 | $log .= "[$date] Step-4 : send purchase telco\n"; |
71 | $log .= "--------------------------------\n"; | 69 | $log .= "--------------------------------\n"; |
70 | |||
71 | $arrinqtelconext = array('goToPin' => 'next', | ||
72 | '_sourcePage' => $kisel->source_page, | ||
73 | '__fp' => $kisel->fp | ||
74 | ); | ||
75 | |||
72 | $kisel->send_form($purchasetelco_url, $purchasetelco_url, $arrinqtelconext); | 76 | $kisel->send_form($purchasetelco_url, $purchasetelco_url, $arrinqtelconext); |
73 | $kisel->parseResponse("//table[@class='tblogin']/tbody/tr/td",1); | 77 | $kisel->parseResponse("//table[@class='tblogin']/tbody/tr/td",1); |
74 | $kisel->printResponseXML(); | 78 | $kisel->printResponseXML(); |
75 | 79 | ||
76 | /* | ||
77 | $fd = fopen("scrapper_kisel.log", "a+"); | ||
78 | fwrite($fd, $log); | 80 | fwrite($fd, $log); |