Membuat wrapper SMS gratis IM3 Januari 16, 2008
Posted by bahroell in Tips and tricks.Tags: M3, SMS, Sms gratis, Wrapper
21 comments
Berikut langkah – langkah membuat wrapper sms gratis Indosat M3 :
1. Buat account di http://www.m3-access.com
2. Sementara account anda masih limited (terbatas 10 sms /hari)
3. Untuk membuat unlimited account di m3-access.com akan saya posting berikutnya
4. Tulis script dibawah ini pada editor misal : notepad, editplus, dll
5. Simpan dengan nama index yang berekstensi .php (index.php)
<?php include("lib.php"); $username = "username"; //masukkan username anda $password = "password"; //masukkan password anda echo " <title>Wrapper SMS</title> "; if($_POST['message'] && $_POST['recipient']) { $m3 = new m3sms(); $m3->Login($username, $password); $m3->kirimSms($_POST['recipient'], $_POST['message']); echo " <div><h1><span>Laporan</span></h1> <fieldset> <legend>Laporan</legend> <p> <label>SMS dari:</label><br /> m3."\"><br /> </p> <p> <label>ke:</label><br /> <br /> </p> <p> <label>Status:</label><br /> status()."\"><br /> </p> <p> <ul> <li><a>« Kirim SMS Lagi</a></li> <li>By bahroell </a></li> </ul> </p> </fieldset> </div>"; } else { echo " <div>SMS gratis IM3 </div> <div><h1><span>FREE SMS</span></h1> <form> <fieldset> <legend>SMS Gratis</legend> <p> <label>Kirim ke: </label><br /> <br /> </p> <p> <label>Isi SMS:</label><br /> <textarea></textarea><br /> </p> <p> characters left </p> <p> <br /> </p> <p> <ul> <li>Terima Kasih</a></li> </ul> </p> </fieldset> </form> </div> "; } echo " "; ?>
6. Buat lembar baru dan tuliskan script dibawah ini
version = "1.0"; $this->created = true; if (!extension_loaded('curl')) { if (isset($_ENV["NUMBER_OF_PROCESSORS"]) and ($_ENV["NUMBER_OF_PROCESSORS"] > 1)) { $this->created = false; $a = array( "action" => "constructing M3SMS object", "status" => "failed", "message" => "lib-M3SMS: Using a multithread server. Ensure php_curl.dll has been enabled (uncommented) in your php.ini." ); array_unshift($this->status_log, $a); } else { if (!dl('php_curl.dll') && !dl('curl.so')) { $this->created = false; $a = array( "action" => "constructing M3SMS object", "status" => "failed", "message" => "lib-M3SMS: unable to load curl extension." ); array_unshift($this->status_log, $a); } } } if (!function_exists("curl_setopt")) { $this->created = false; $a = array( "action" => "constructing M3SMS object", "status" => "failed", "message" => "lib-M3SMS: No curl." ); array_unshift($this->status_log, $a); } $this->username = $username; $this->password = $password; $this->proxy_host = ""; $this->proxy_auth = ""; $this->use_session = 2; if ($this->created == true) { $a = array( "action" => "constructing M3SMS object", "status" => "success", "message" => "lib-M3SMS: Constructing completed." ); array_unshift($this->status_log, $a); } //$this->Login(); } function setProxy($proxy_host, $proxy_user, $proxy_pass) { if (strlen($this->proxy_host) > 0) { $this->proxy_host = $proxy_host; if (strlen($proxy_user) > 0 || strlen($proxy_pass) > 0) { $this->proxy_auth = $proxy_user.":".$proxy_pass; } $a = array( "action" => "set proxy", "status" => "success", "message" => "lib-M3SMS: Proxy set." ); array_unshift($this->status_log, $a); } else { $a = array( "action" => "set proxy", "status" => "failed", "message" => "lib-M3SMS: no hostname supplied." ); array_unshift($this->status_log, $a); } } function CURL_PROXY($cc) { if (strlen($this->proxy_host) > 0) { curl_setopt($cc, CURLOPT_PROXY, $this->proxy_host); if (strlen($this->proxy_auth) > 0) curl_setopt($cc, CURLOPT_PROXYUSERPWD, $this->proxy_auth); } } function Login($username, $password){ $this->cookie = m3_COOKIE_PATH."m3@cookie.txt"; $this->username = $username; $this->password = $password; /* looking for sid */ $this->ch = curl_init(); curl_setopt($this->ch, CURLOPT_URL, M3SMS_URL); $this->CURL_PROXY($this->ch); curl_setopt($this->ch, CURLOPT_HEADER, 1); // baca header curl_setopt($this->ch, CURLOPT_USERAGENT, M3SMS_USERAGENT); curl_setopt($this->ch, CURLOPT_COOKIE, $this->cookie_string); curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->cookie); curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->cookie); curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1); $indexContent = curl_exec($this->ch); $ereg_sid = ereg("PHPSESSID\=([0-9a-z]+)", $indexContent, $ketemu_sid); $this->sid = $ketemu_sid[1]; /* Login */ curl_setopt($this->ch, CURLOPT_URL, M3SMS_LOGIN); $this->CURL_PROXY($this->ch); curl_setopt($this->ch, CURLOPT_POST, 1); curl_setopt($this->ch, CURLOPT_USERAGENT, M3SMS_USERAGENT); curl_setopt($this->ch, CURLOPT_COOKIE, $this->cookie_string); curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->cookie.txt); curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->cookie.txt); curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1); $loginPost = "username=".urlencode($this->username); $loginPost .= "&password=".urlencode($this->password); $loginPost .= "&sid=".urlencode($this->sid); $loginPost .= "&redirect=".urlencode("index.php"); $loginPost .= "&login=".urlencode("Log in"); curl_setopt($this->ch, CURLOPT_POSTFIELDS, $loginPost); $loginContent = curl_exec($this->ch); $this->lihatErrorCurl($this->ch); // curl_close($this->ch); } function kirimSms($recipient, $message) { // FORM SMS curl_setopt($this->ch, CURLOPT_URL, M3SMS_FORMSMS); curl_setopt($this->ch, CURLOPT_POST, 1); curl_setopt($this->ch, CURLOPT_USERAGENT, M3SMS_USERAGENT); curl_setopt($this->ch, CURLOPT_COOKIEJAR, $cookiefile); curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1); // langsung return curl_setopt($this->ch, CURLOPT_VERBOSE, 1); curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1); $formSMSContent = curl_exec ($this->ch); if(empty($this->m3)) { $ereg_m3 = ereg("<span>\+([0-9a-z]+)", $formSMSContent, $ketemu_m3); $this->m3 = $ketemu_m3[1]; //echo "\$m3 = $ketemu_m3[1]<br />"; } // KIRIM SMS $this->recipient = $recipient; $this->message = $message; curl_setopt($this->ch, CURLOPT_URL, M3SMS_KIRIM_SMS); $this->CURL_PROXY($this->ch); curl_setopt ($this->ch, CURLOPT_POST, 1); curl_setopt($this->ch, CURLOPT_REFERER, M3SMS_FORMSMS); curl_setopt ($this->ch, CURLOPT_COOKIE, $this->cookie_string); curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1); $kirimPost = "recipient=".urlencode($this->recipient); $kirimPost .= "&message=".urlencode($this->message); $kirimPost .= "&jml_kar=125"; $kirimPost .= "&username=".urlencode($this->m3); $kirimPost .= "&user_id=&submit=".urlencode("Kirim SMS"); curl_setopt ($this->ch, CURLOPT_POSTFIELDS, $kirimPost); $kirimContent = curl_exec($this->ch); $infoKirim = curl_getinfo($this->ch); if($kirimContent) { if(ereg("masuk antrian", $kirimContent)) { $this->status = "terkirim"; } elseif(ereg("Wah, sms hari ini dah 10 sms nih", $kirimContent)) { $this->status = "over-limit"; } } else { if (empty($infoKirim['http_code'])) { $this->status = "No HTTP code was returned"; } else { $this->status = $infoKirim['http_code']; } } $this->lihatErrorCurl($this->ch); // curl_close($this->ch); } function terkirim() { return $this->terkirim; } function lihatStatusLog() { print implode("<br>\n", $this->status_log); } function status() { return $this->status; } function lihatErrorCurl($ch) { if (curl_errno($this->ch)) { echo "cURL info:". print_r(curl_getinfo($this->ch)); echo "<br>"; echo "cURL error number:" .curl_errno($this->ch); echo "<br>"; echo "cURL error:" . curl_error($this->ch); } } } ?>
7. Simpan dengan nama m3smslib yang berekstensi .php (lib.php)
8. Setelah kedua file tersebut jadi, titipkan pada hosting gratis yang support script php
9. Anda bisa menitipkan di http://www.110mb.com
10. Anda bisa menaruh kedua file tersebut di root direktory atau didirektori yang lain
11. Nah jadi deh wrappernya
12. Anda tinggal memanggilnya pada direktori misal http://coba.110mb.com/sms/
13. Semoga bermanfaat