-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmsGateway.php
113 lines (81 loc) · 3.53 KB
/
smsGateway.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
<?php
class SmsGateway {
static $baseUrl = "https://smsgateway.me";
function __construct($email,$password) {
$this->email = $email;
$this->password = $password;
}
function createContact ($name,$number) {
return $this->makeRequest('/api/v3/contacts/create','POST',['name' => $name, 'number' => $number]);
}
function getContacts ($page=1) {
return $this->makeRequest('/api/v3/contacts','GET',['page' => $page]);
}
function getContact ($id) {
return $this->makeRequest('/api/v3/contacts/view/'.$id,'GET');
}
function getDevices ($page=1)
{
return $this->makeRequest('/api/v3/devices','GET',['page' => $page]);
}
function getDevice ($id)
{
return $this->makeRequest('/api/v3/devices/view/'.$id,'GET');
}
function getMessages($page=1)
{
return $this->makeRequest('/api/v3/messages','GET',['page' => $page]);
}
function getMessage($id)
{
return $this->makeRequest('/api/v3/messages/view/'.$id,'GET');
}
function sendMessageToNumber($to, $message, $device, $options=[]) {
$query = array_merge(['number'=>$to, 'message'=>$message, 'device' => $device], $options);
return $this->makeRequest('/api/v3/messages/send','POST',$query);
}
function sendMessageToManyNumbers ($to, $message, $device, $options=[]) {
$query = array_merge(['number'=>$to, 'message'=>$message, 'device' => $device], $options);
return $this->makeRequest('/api/v3/messages/send','POST', $query);
}
function sendMessageToContact ($to, $message, $device, $options=[]) {
$query = array_merge(['contact'=>$to, 'message'=>$message, 'device' => $device], $options);
return $this->makeRequest('/api/v3/messages/send','POST', $query);
}
function sendMessageToManyContacts ($to, $message, $device, $options=[]) {
$query = array_merge(['contact'=>$to, 'message'=>$message, 'device' => $device], $options);
return $this->makeRequest('/api/v3/messages/send','POST', $query);
}
function sendManyMessages ($data) {
$query['data'] = $data;
return $this->makeRequest('/api/v3/messages/send','POST', $query);
}
private function makeRequest ($url, $method, $fields=[]) {
$fields['email'] = $this->email;
$fields['password'] = $this->password;
$url = smsGateway::$baseUrl.$url;
$fieldsString = http_build_query($fields);
$ch = curl_init();
if($method == 'POST')
{
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fieldsString);
}
else
{
$url .= '?'.$fieldsString;
}
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER , false); // we want headers
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec ($ch);
$return['response'] = json_decode($result,true);
if($return['response'] == false)
$return['response'] = $result;
$return['status'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
return $return;
}
}
?>