-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.smsreg.php
More file actions
184 lines (165 loc) · 4.31 KB
/
Copy pathclass.smsreg.php
File metadata and controls
184 lines (165 loc) · 4.31 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
/*
sms-reg.com api simple class
All Methods: https://sms-reg.com/docs/APImethods.html
*/
class SMSREG
{
private $API_URL = "http://api.sms-reg.com";
public $api_key = null;
public function __construct($key){
if($key !== null){
$this->api_key = $key;
}else{
print "[SMS-REG] API Key Required";
}
}
/*
METHOD NAME: getNum
RETURN: tzid
Country code, service parameters are here: https://sms-reg.com/docs/APImethods.html?getNum
*/
public function getNum($service, $country_code = "all", $appid = null){
return $this->_response(
$this->_request("getNum", [
"country"=>$country_code,
"service"=>$service,
"appid"=>$appid
]),
"tzid"
);
}
/*
METHOD NAME: setReady
RETURN: all
*/
public function setReady($tzid){
return $this->_response(
$this->_request("setReady", [
"tzid"=>$tzid
])
);
}
/*
METHOD NAME: getState
RETURN: all
*/
public function getState($tzid){
return $this->_response(
$this->_request("getState", [
"tzid"=>$tzid
])
);
}
/*
METHOD NAME: getState
RETURN: all (operations array)
*/
public function getOperations($count = 10, $opstate = "active", $output = "array"){
return $this->_response(
$this->_request("getOperations", [
"count"=>$count,
"opstate"=>$opstate,
"output"=>$output
])
);
}
/*
METHOD NAME: setOperationOk
RETURN: all
*/
public function setOperationOk($tzid){
return $this->_response(
$this->_request("setOperationOk", [
"tzid"=>$tzid,
])
);
}
/*
METHOD NAME: getNumRepeat
RETURN: new tzid
*/
public function getNumRepeat($tzid, $all = 0){
return $this->_response(
$this->_request("getNumRepeat", [
"tzid"=>$tzid,
]),
($all == 0 ? "tzid" : null)
);
}
/*
METHOD NAME: getNumRepeatOffline
RETURN: all
*/
public function getNumRepeatOffline($params){
return $this->_response(
$this->_request("getNumRepeatOffline", $params)
);
}
/*
METHOD NAME: setOperationUsed
RETURN: tzid
*/
public function setOperationUsed($tzid){
return $this->_response(
$this->_request("getNumRepeatOffline", [
"tzid"=>$tzid
]),
"tzid"
);
}
/*
METHOD NAME: getBalance
RETURN: balance
*/
public function getBalance(){
return $this->_response(
$this->_request("getBalance"),
"balance"
);
}
/*
METHOD NAME: setRate
RETURN: rate
*/
public function setRate($rate){
return $this->_response(
$this->_request("setRate"),
"rate"
);
}
private function _response($x, $y = null){
if($y != null){
if(isset($x->$y)):
return $x->$y;
endif;
}
return $x;
}
private function _request($method_name, $params = null){
return json_decode(
$this->_curl(
$this->_apiUrl($method_name, ($params != null ? http_build_query($params) : null))
)
);
}
private function _apiUrl($method_name, $query_string = null){
return $this->API_URL . "/" . $method_name . ".php?apikey=" . $this->api_key . ($query_string != null ? "&" . $query_string : null);
}
private function _curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
public function _debug($things){
echo '<pre>';
print_r($things);
echo '</pre>';
}
}