-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgvmax.class.php
128 lines (109 loc) · 2.58 KB
/
gvmax.class.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
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
* GVMax API
*
* This is an API for
*
* @author Sean Thomas Burke <http://www.seantburke.com/>
*/
class GVMax
{
private $api; //this is the api token from GVMax, set with constructor
public $type;
public $number;
public $text;
public $error;
public $result;
/**
* Constructor that takes in the api token as a parameter
* Forward your gvmax HTTP request to a page with this object
*
* @author Sean Thomas Burke <http://www.seantburke.com>
* @param $api //Api from GVMax
* @return JSON
*/
function __construct($api)
{
$this->api = $api;
// stores variables from gvmax HTTP POST
if($_POST)
{
$this->type = $_POST['type'];
$this->number = $_POST['number'];
$this->text = $_POST['text'];
if($_POST['type'] == 'VM')
{
$this->link = $_POST['link'];
}
}
}
/**
* Send an SMS
*
* @author Sean Thomas Burke <http://www.seantburke.com>
* @param $number, $text //Api from
* @return JSON
*/
public function sms($number, $text)
{
//TODO validate number
//if the $number is an array, then send it to the group
if(is_array($number))
{
return $this->groupSMS($number, $text);
}
//REST URL for sending sms
$url = 'https://www.gvmax.com/api/send';
//parameters for call
$fields = array(
'pin'=>urlencode($this->api),
'number'=>urlencode($number),
'text'=>urlencode($text),
);
//url-ify the data for the POST
foreach($fields as $key=>$value)
{
$fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string,'&');
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
$result = curl_exec($ch);
curl_close($ch);
$this->result = json_decode($result, true);
//return the GVMax return {$number: ok}
return $this->result;
}
/**
* will send an SMS to a group
*
* @author Sean Thomas Burke <http://www.seantburke.com>
* @param $array_numbers, $text //Api from
* @return JSON
*/
private function groupSMS($array_numbers, $text)
{
foreach($array_numbers as $number)
{
$result[$i++] = $this->sms($number,$text);
}
$this->result = $result;
return $this->result;
}
/**
* call method will place a call to a phone
*
* @author Sean Thomas Burke <http://www.seantburke.com>
* @param $number //
* @return JSON
*/
public function call($number)
{
//TODO Implement this method
}
}
?>