forked from revathskumar/sms-with-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassSms.php
115 lines (100 loc) · 4.17 KB
/
classSms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/*Sms
*used to send sms using web service
*@ $uid String: username to authenticate the way2sms website
*@ $pwd String: password for way2sms website
*@ $phone String: phone numbers of recipients
*@ $msg String: the message to be send
*
*@Author : Aswin Anand
*@edited by Revath S Kumar
*
*
*/
class Sms
{
var $uid,$pwd,$phone,$msg;
/*
*@ constructor of Sms class
*
*@ $id String : username to authenticate the way2sms website
*@ $pass String : password for way2sms website
*
*/
function Sms($id,$pass)
{
$this->uid=$id;
$this->pwd=$pass;
}
/*
*sendSMSToMany
*@description : to send the sms
*
*@ $phone String : phone numbers of recipients
*@ $msg String : the message to be send
*
*@return String : error message or success message
*/
function sendSMSToMany($phone, $msg)
{
$curl = curl_init();
$timeout = 30;
$ret = "";
// $uid = urlencode($uid);
// $pwd = urlencode($pwd);
curl_setopt ($curl, CURLOPT_URL, "http://site6.way2sms.com/Login1.action");
curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, "username=" . $this->uid . "&password=" . $this->pwd);
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://site6.way2sms.com/");
$text = curl_exec($curl);
// Check for proper login
$pos = stripos(curl_getinfo($curl, CURLINFO_EFFECTIVE_URL), "main.action");
// echo $pos;
// exit();
if ($pos === "FALSE" || $pos == 0 || $pos == "")
return "invalid login";
if (trim($msg) == "" || strlen($msg) == 0) return "invalid message";
$msg = urlencode($msg);
$pharr = explode(";", $phone);
$refurl = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
curl_setopt ($curl, CURLOPT_REFERER, $refurl);
curl_setopt ($curl, CURLOPT_URL, "http://site6.way2sms.com/jsp/InstantSMS.jsp");
$text = curl_exec($curl);
$dom = new DOMDocument();
@$dom->loadHTML($text);
$action = $dom->getElementById("Action")->getAttribute('value');
foreach ($pharr as $p)
{
if (strlen($p) != 10 || !is_numeric($p) || strpos($p, ".") != false)
{
$ret .= "invalid number;" . $p . "\n";
continue;
}
$p = urlencode($p);
// Send SMS
curl_setopt ($curl, CURLOPT_URL, "http://site6.way2sms.com/quicksms.action?custid=\"+custid+\"&sponserid=\"+sponserid+\"");
curl_setopt ($curl, CURLOPT_REFERER, curl_getinfo($curl, CURLINFO_EFFECTIVE_URL));
curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, "MobNo=$p&textArea=$msg&HiddenAction=instantsms&login=&pass=&Action=$action");
$text = curl_exec($curl);
$sendError = curl_error($curl);
}
// Logout :P
curl_setopt ($curl, CURLOPT_URL, "http://site6.way2sms.com/jsp/logout.jsp");
curl_setopt ($curl, CURLOPT_REFERER, $refurl);
$text = curl_exec($curl);
curl_close($curl);
if ("" != $sendError){
return $sendError;
}
return "done" . $ret;
}
}
?>