-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsmsaeroapi.class.php
More file actions
122 lines (111 loc) · 3.56 KB
/
smsaeroapi.class.php
File metadata and controls
122 lines (111 loc) · 3.56 KB
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
<?php
/**
* SMSAERO class for smsaero.ru
*
* @package server API methods
* @autor Georgy Shpak http://sllite.ru/
* @version 1.0
*/
class Smsaero {
private $gate;
private $username;
private $password;
private $from;
private $typeanswer;
private $useragent;
function __construct($username,
$password,
$from,
$typeanswer = 'json',
$useragent = 'Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0.1')
{
$this->username = $username;
$this->password = md5($password);
$this->typeanswer = "&answer={$typeanswer}";
$this->from = $from;
$this->useragent = $useragent;
$this->gate = 'http://gate.smsaero.ru';
}
/**
* Отправить запрос на сервер
* @param $url адрес запроса
* @return mixed
*/
private function send_post($url, $data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->gate . $url . '?' . str_replace('+', '%20', http_build_query($data)) . $this->typeanswer);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_USERAGENT, $this->useragent);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
/**
* Передача сообщения
* @param $to Номер телефона получателя, в формате 71234567890
* @param $text Текст сообщения, в UTF-8 кодировке
* @param $from Подпись отправителя (например TEST)
* @param $date Дата для отложенной отправки сообщения (количество секунд с 1 января 1970 года)
*/
function send( $to, $text, $from=null, $date=null )
{
if(is_null($from))
$from=$this->from;
$response = $this->send_post(
"/send/",
array(
'user' => $this->username,
'password' => $this->password,
'to' => $to,
'text' => $text,
'from' => $from,
'date' => $date
)
);
return $response;
}
/**
* Проверка состояния отправленного сообщения
* @param $id Идентификатор сообщения, который вернул сервис при отправке сообщения
*/
function getStatus($id)
{
return $this->send_post(
"/status/",
array(
'user' => $this->username,
'password' => $this->password,
'id' => $id
)
);
}
/**
* Проверка состояния счёта
*/
function getBalance()
{
return $this->send_post(
"/balance/",
array(
'user' => $this->username,
'password' => $this->password
)
);
}
/**
* Список доступных подписей отправителя
*/
function getSenders()
{
return $this->send_post(
"/senders/",
array(
'user' => $this->username,
'password' => $this->password
)
);
}
}