├── .gitignore ├── README.md ├── sendsms.php └── way2sms-api.php /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | test/ 5 | 6 | # Folder config file 7 | Desktop.ini 8 | 9 | # Recycle Bin used on file shares 10 | $RECYCLE.BIN/ 11 | 12 | # Windows Installer files 13 | *.cab 14 | *.msi 15 | *.msm 16 | *.msp 17 | 18 | # Windows shortcuts 19 | *.lnk 20 | 21 | # ========================= 22 | # Operating System Files 23 | # ========================= 24 | 25 | # OSX 26 | # ========================= 27 | 28 | .DS_Store 29 | .AppleDouble 30 | .LSOverride 31 | 32 | # Thumbnails 33 | ._* 34 | 35 | # Files that might appear on external disk 36 | .Spotlight-V100 37 | .Trashes 38 | 39 | # Directories potentially created on remote AFP share 40 | .AppleDB 41 | .AppleDesktop 42 | Network Trash Folder 43 | Temporary Items 44 | .apdisk 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Way2SMS PHP API 2 | ============= 3 | 4 | Send SMS Via Way2SMS from PHP. 5 | 6 | Tested Working with Way2SMS UI Version 4. Supports upto 140 Characters
7 | Way2SMS has added a Captcha Verification. Will update when I can find a workaround
8 | UPDATE: Fully functional again :) 9 | 10 | 11 | 12 | How to Use 13 | ------- 14 | 15 | ##### Simple Usage 16 | 17 | ```php 18 | 23 | ``` 24 | 25 | ##### Multiple Messages with different content 26 | ```php 27 | login('username', 'password'); 31 | $client->send('987654321', 'msg1'); 32 | //Add sleep between requests to make this requests more human like! 33 | //A blast of request's may mark the ip as spammer and blocking further requests. 34 | sleep(1); 35 | $client->send('987654321,9876501234', 'msg2'); 36 | sleep(1); 37 | $client->logout(); 38 | ?> 39 | ``` 40 | 41 | 42 | 43 | 44 | HTTP API 45 | ------------ 46 | 47 | Send SMS just making GET or POST Requests. 48 | 49 | Incase u want to use the service from your application then the parameters for ur application would be 50 | 51 | ``` 52 | http://www.yourdomain.com/sendsms.php?uid=LOGIN_ID&pwd=PASSWORD&phone=XXXXXXXXX,YYYYYYYYY&msg=Hello+World 53 | 54 | Parameters 55 | uid = LOGIN_ID ( Your Login ID [either nickname or 10 Digit mobile no] ) 56 | pwd = PASSWORD ( Your Login Password ) 57 | phone = 10 Digit Mobile number. Incase of multiple numbers then numbers separated by comma (,) 58 | msg = Your Message. 59 | ``` 60 | 61 | 62 | Note 63 | ------- 64 | Please use this code on your own risk. The author is no way responsible for the outcome arising out of this. 65 | -------------------------------------------------------------------------------- /sendsms.php: -------------------------------------------------------------------------------- 1 | curl = curl_init(); 28 | $uid = urlencode($username); 29 | $pwd = urlencode($password); 30 | 31 | // Go where the server takes you :P 32 | curl_setopt($this->curl, CURLOPT_URL, "http://way2sms.com"); 33 | curl_setopt($this->curl, CURLOPT_HEADER, true); 34 | curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, false); 35 | curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, TRUE); 36 | $a = curl_exec($this->curl); 37 | if (preg_match('#Location: (.*)#', $a, $r)) 38 | $this->way2smsHost = trim($r[1]); 39 | 40 | // Setup for login 41 | curl_setopt($this->curl, CURLOPT_URL, $this->way2smsHost . "Login1.action"); 42 | curl_setopt($this->curl, CURLOPT_POST, 1); 43 | curl_setopt($this->curl, CURLOPT_POSTFIELDS, "username=" . $uid . "&password=" . $pwd . "&button=Login"); 44 | curl_setopt($this->curl, CURLOPT_COOKIESESSION, 1); 45 | curl_setopt($this->curl, CURLOPT_COOKIEFILE, "cookie_way2sms"); 46 | curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, 1); 47 | curl_setopt($this->curl, CURLOPT_MAXREDIRS, 20); 48 | curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1); 49 | curl_setopt($this->curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"); 50 | curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, $this->timeout); 51 | curl_setopt($this->curl, CURLOPT_REFERER, $this->way2smsHost); 52 | $text = curl_exec($this->curl); 53 | 54 | // Check if any error occured 55 | if (curl_errno($this->curl)) 56 | return "access error : " . curl_error($this->curl); 57 | 58 | // Check for proper login 59 | $pos = stripos(curl_getinfo($this->curl, CURLINFO_EFFECTIVE_URL), "main.action"); 60 | if ($pos === "FALSE" || $pos == 0 || $pos == "") 61 | return "invalid login"; 62 | 63 | // Set the home page from where we can send message 64 | $this->refurl = curl_getinfo($this->curl, CURLINFO_EFFECTIVE_URL); 65 | /*$newurl = str_replace("ebrdg.action?id=", "main.action?section=s&Token=", $this->refurl); 66 | curl_setopt($this->curl, CURLOPT_URL, $newurl);*/ 67 | 68 | // Extract the token from the URL 69 | $tokenLocation = strpos($this->refurl, "Token"); 70 | $this->jstoken = substr($this->refurl, $tokenLocation + 6, 37); 71 | //Go to the homepage 72 | //$text = curl_exec($this->curl); 73 | 74 | return true; 75 | } 76 | 77 | 78 | /** 79 | * @param $phone 80 | * @param $msg 81 | * @return array 82 | */ 83 | function send($phone, $msg) 84 | { 85 | $result = array(); 86 | 87 | // Check the message 88 | if (trim($msg) == "" || strlen($msg) == 0) 89 | return "invalid message"; 90 | 91 | // Take only the first 140 characters of the message 92 | $msg = substr($msg, 0, 140); 93 | // Store the numbers from the string to an array 94 | $pharr = explode(",", $phone); 95 | 96 | // Send SMS to each number 97 | foreach ($pharr as $p) { 98 | // Check the mobile number 99 | if (strlen($p) != 10 || !is_numeric($p) || strpos($p, ".") != false) { 100 | $result[] = array('phone' => $p, 'msg' => $msg, 'result' => "invalid number"); 101 | continue; 102 | } 103 | 104 | // Setup to send SMS 105 | curl_setopt($this->curl, CURLOPT_URL, $this->way2smsHost . 'smstoss.action'); 106 | curl_setopt($this->curl, CURLOPT_REFERER, curl_getinfo($this->curl, CURLINFO_EFFECTIVE_URL)); 107 | curl_setopt($this->curl, CURLOPT_POST, 1); 108 | 109 | curl_setopt($this->curl, CURLOPT_POSTFIELDS, "ssaction=ss&Token=" . $this->jstoken . "&mobile=" . $p . "&message=" . $msg . "&button=Login"); 110 | $contents = curl_exec($this->curl); 111 | 112 | //Check Message Status 113 | $pos = strpos($contents, 'Message has been submitted successfully'); 114 | $res = ($pos !== false) ? true : false; 115 | $result[] = array('phone' => $p, 'msg' => $msg, 'result' => $res); 116 | } 117 | return $result; 118 | } 119 | 120 | 121 | /** 122 | * logout of current session. 123 | */ 124 | function logout() 125 | { 126 | curl_setopt($this->curl, CURLOPT_URL, $this->way2smsHost . "LogOut"); 127 | curl_setopt($this->curl, CURLOPT_REFERER, $this->refurl); 128 | $text = curl_exec($this->curl); 129 | curl_close($this->curl); 130 | } 131 | 132 | } 133 | 134 | /** 135 | * Helper Function to send to sms to single/multiple people via way2sms 136 | * @example sendWay2SMS ( '9000012345' , 'password' , '987654321,9876501234' , 'Hello World') 137 | */ 138 | 139 | function sendWay2SMS($uid, $pwd, $phone, $msg) 140 | { 141 | $client = new WAY2SMSClient(); 142 | $client->login($uid, $pwd); 143 | $result = $client->send($phone, $msg); 144 | $client->logout(); 145 | return $result; 146 | } 147 | 148 | --------------------------------------------------------------------------------