Skip to content

Instantly share code, notes, and snippets.

@suyashbansal
Created November 6, 2015 17:44
Show Gist options
  • Save suyashbansal/4b1d4bee357ea526d578 to your computer and use it in GitHub Desktop.
Save suyashbansal/4b1d4bee357ea526d578 to your computer and use it in GitHub Desktop.
Way2SMS API in PHP fully working last checked on November 2015
<?php
/**
* @author SuyashBansal
* @author Kingster
* @category SMS
* @copyright 2015
* @description Request this page with get or post params
* @param uid = Way2SMS Username
* @param pwd = Way2SMS Password
* @param phone = Number to send to. Multiple Numbers separated by comma (,).
* @param msg = Your Message ( Upto 140 Chars)
*/
include ('way2sms-api.php');
if (isset($_GET['uid']) && isset($_GET['pwd']) && isset($_GET['phone']) && isset($_GET['msg']))
{
$res = sendWay2SMS($_GET['uid'], $_GET['pwd'], $_GET['phone'], $_GET['msg']);
if(is_array($res)) echo $res[0]['result'] ? 'true' : 'false';
else echo $res;
exit;
}
else
if (isset($_POST['uid']) && isset($_POST['pwd']) && isset($_POST['phone']) && isset($_POST['msg']))
{
$smsg = stripslashes($_POST['msg']);
$res = sendWay2SMS($_POST['uid'], $_POST['pwd'], $_POST['phone'], $smsg);
if(is_array($res)) echo $res[0]['result'] ? 'true' : 'false';
else echo $res;
exit;
}
?>
<?php
/**
* sendWay2SMS
* Function to send to sms to single/multiple people via way2sms
* @author SuyashBansal
* @author Kingster
* @category SMS
* @example sendWay2SMS ( '9000012345' , 'password' , '987654321,9876501234' , 'Hello World')
* @url https://github.com/suyashbansal/Way2SMS-API/
* @return String/Array
* Please use this code on your own risk. The author is no way responsible for the outcome arising out of this
* Good Luck!
**/
function sendWay2SMS($uid, $pwd, $phone, $msg)
{
$curl = curl_init();
$timeout = 30;
$result = array();
$uid = urlencode($uid);
$pwd = urlencode($pwd);
//$autobalancer = rand(1, 8);
$autobalancer = 23;
// Setup for login
curl_setopt($curl, CURLOPT_URL, "http://site".$autobalancer.".way2sms.com/Login1.action");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, "username=".$uid."&password=".$pwd."&button=Login");
curl_setopt($curl, CURLOPT_COOKIESESSION, 1);
curl_setopt($curl, CURLOPT_COOKIEFILE, "cookie_way2sms");
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_MAXREDIRS, 20);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5");
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_REFERER, "http://site".$autobalancer.".way2sms.com/");
$text = curl_exec($curl);
// Check if any error occured
if (curl_errno($curl))
return "access error : ". curl_error($curl);
// Check for proper login
$pos = stripos(curl_getinfo($curl, CURLINFO_EFFECTIVE_URL), "ebrdg.action");
if ($pos === "FALSE" || $pos == 0 || $pos == "")
return "invalid login";
// Check the message
if (trim($msg) == "" || strlen($msg) == 0)
return "invalid message";
// Take only the first 140 characters of the message
$msg = urlencode(substr($msg, 0, 140));
// Store the numbers from the string to an array
$pharr = explode(",", $phone);
// Set the home page from where we can send message
$refurl = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
$newurl = str_replace("ebrdg.action?id=", "main.action?section=s&Token=", $refurl);
curl_setopt($curl, CURLOPT_URL, $newurl);
// Extract the token from the URL
$jstoken = substr($newurl, 50, -41);
//Go to the homepage
$text = curl_exec($curl);
// Send SMS to each number
foreach ($pharr as $p)
{
// Check the mobile number
if (strlen($p) != 10 || !is_numeric($p) || strpos($p, ".") != false)
{
$result[] = array('phone' => $p, 'msg' => urldecode($msg), 'result' => "invalid number");
continue;
}
$p = urlencode($p);
// Setup to send SMS
curl_setopt($curl, CURLOPT_URL, 'http://site'.$autobalancer.'.way2sms.com/smstoss.action');
curl_setopt($curl, CURLOPT_REFERER, curl_getinfo($curl, CURLINFO_EFFECTIVE_URL));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, "ssaction=ss&Token=".$jstoken."&mobile=".$p."&message=".$msg."&button=Login");
$contents = curl_exec($curl);
//Check Message Status
$pos = strpos($contents, 'Message has been submitted successfully');
$res = ($pos !== false) ? true : false;
$result[] = array('phone' => $p, 'msg' => urldecode($msg), 'result' => $res);
}
// Logout
curl_setopt($curl, CURLOPT_URL, "http://site".$autobalancer.".way2sms.com/LogOut");
curl_setopt($curl, CURLOPT_REFERER, $refurl);
$text = curl_exec($curl);
curl_close($curl);
return $result;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment