-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmsgatewaycenter.misscall-2fa.api.class.php
381 lines (333 loc) · 12.1 KB
/
smsgatewaycenter.misscall-2fa.api.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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<?php
/*
|--------------------------------------------------------------------------
| SMSGatewayCenter - Class file to Authenticate via Miss Call to SMSGateway.center API
|--------------------------------------------------------------------------
|
| @package SMSGatewayCenter
| @version 1.0.0
| @api https://www.smsgateway.center/docs/api/
| @license <https://www.smsgateway.center> (SMSGatewayCenter)
| @author psmpl <psmpl@psmpl.com>
|
|
*/
/*
|--------------------------------------------------------------------------
| Class for psmpl SMS Gateway Center.
|--------------------------------------------------------------------------
|
|
*/
class psmplSMSGatewayCenter {
/*
|--------------------------------------------------------------------------
| Constant for all API Parameters
|--------------------------------------------------------------------------
|
|
*/
const MISSCALL2FAAPI = "http://www.smsgateway.center/OTPApi/"; // API End Point
const PARAM_APIKEY = "apiKey";
const PARAM_USERID = "userId";
const PARAM_PASSWORD = "password";
const PARAM_SEND_METHOD = "sendMethod";
const PARAM_MOBILE = "mobile";
const PARAM_MISSCALLTO = "missCallTo";
const PARAM_CODEEXPIRY = "codeExpiry";
const PARAM_RETRYEXPIRY = "retryExpiry";
const PARAM_RENEW = "renew";
const PARAM_CALLBACK = "callback"; //Capture response http://www.example.com/getMisscallResponse.php
const PARAM_FORMAT = "format";
const PARAM_MEDIUM = "medium";
const FORMAT_JSON = "json";
const FORMAT_PLAIN = "plain";
const FORMAT_XML = "xml";
const METHOD_SEND_GENERATE = "generate";
const METHOD_SEND_VERIFY = "verify";
const RETRY_MIN = 180;//Retry minimum time set to 3 minutes (180 seconds)
const MEDIUM_DEFAULT = "misscall";
/*
|--------------------------------------------------------------------------
| API parameters
|--------------------------------------------------------------------------
|
|
*/
private $apiKey;
private $userId;
private $password;
private $sendMethod;
private $mobile;
private $misscallto;
private $codeexpiry;
private $retryexpiry;
private $renew;
private $callback;
private $format;
private $medium;
private $response;
private $param = array();
/*
|--------------------------------------------------------------------------
| Object Instantiation
|--------------------------------------------------------------------------
|
| @param string $userid The userid
| @param string $password The password
| @param string $apiKey The api key
|
*/
public function __construct($userid, $password, $apiKey = '') {
$this->userId = $userid;
$this->password = $password;
if ($apiKey != '') {
$this->apiKey = $apiKey;
}
}
/*
|--------------------------------------------------------------------------
| Gets the response.
|--------------------------------------------------------------------------
|
| @return array|mixed The response.
|
*/
function getResponse() {
return $this->response;
}
/*
|--------------------------------------------------------------------------
| Sets the api key.
|--------------------------------------------------------------------------
|
| @param null|string $apiKey The api key
|
*/
function setApiKey($apiKey) {
$this->apiKey = $apiKey;
}
/*
|--------------------------------------------------------------------------
| Sets the user identifier.
|--------------------------------------------------------------------------
|
| @param string $userId The user identifier
|
*/
function setUserId($userId) {
$this->userId = $userId;
}
/*
|--------------------------------------------------------------------------
| Sets the password.
|--------------------------------------------------------------------------
|
| @param string $password The password
|
*/
function setPassword($password) {
$this->password = $password;
}
/*
|--------------------------------------------------------------------------
| Sets the send method.
|--------------------------------------------------------------------------
|
| @param string $sendMethod The send method
|
*/
function setSendMethod($sendMethod) {
$this->sendMethod = $sendMethod;
}
/*
|--------------------------------------------------------------------------
| Sets the Miss Call To.
|--------------------------------------------------------------------------
|
| @param string $misscallto The dedicated miss call number
|
*/
function setMissCallTo($misscallto) {
$this->missCallTo = $misscallto;
}
/*
|--------------------------------------------------------------------------
| Sets the Code Expiry.
|--------------------------------------------------------------------------
|
| @param <type> $codeexpiry The Code Expiry
|
*/
function setCodeExpiry($codeexpiry) {
$this->codeexpiry = $codeexpiry;
}
/*
|--------------------------------------------------------------------------
| Sets the retry Expiry.
|--------------------------------------------------------------------------
|
| @param <type> $retryexpiry The Retry Expiry
|
*/
function setRetryExpiry($retryexpiry) {
$this->$retryexpiry = $retryexpiry;
}
/*
|--------------------------------------------------------------------------
| Sets the Renew param.
|--------------------------------------------------------------------------
|
| @param <type> $renew The Renew
|
*/
function setRenew($renew) {
$this->renew = $renew;
}
/*
|--------------------------------------------------------------------------
| Sets the Callback.
|--------------------------------------------------------------------------
|
| @param <type> $callback The Callback
|
*/
function setCallback($callback) {
$this->callback = $callback;
}
/*
|--------------------------------------------------------------------------
| Sets the mobile.
|--------------------------------------------------------------------------
|
| @param <type> $mobile The mobile
|
*/
function setMobile($mobile) {
$this->mobile = $mobile;
}
/*
|--------------------------------------------------------------------------
| Sets the format.
|--------------------------------------------------------------------------
|
| @param string $format The format
|
*/
function setFormat($format) {
$this->format = $format;
}
/*
|--------------------------------------------------------------------------
| Sets the Medium Default value.
|--------------------------------------------------------------------------
|
| @param string $mediumdefault The medium default value
|
*/
function setMedium($medium) {
$this->medium = $medium;
}
/*
|--------------------------------------------------------------------------
| Sends OTP SMS Message
|--------------------------------------------------------------------------
|
| @param url|string $api The api
| @param component|string $sendtype The sendtype
|
| Build all param to send OTP SMS
|
|
*/
public function initiateMissCall($api, $sendtype) {
$param[psmplSMSGatewayCenter::PARAM_MISSCALLTO] = $this->missCallTo;
$param[psmplSMSGatewayCenter::PARAM_MOBILE] = $this->mobile;
$param[psmplSMSGatewayCenter::PARAM_CODEEXPIRY] = $this->codeexpiry;
$param[psmplSMSGatewayCenter::PARAM_RETRYEXPIRY] = $this->retryexpiry;
$param[psmplSMSGatewayCenter::PARAM_RENEW] = $this->renew;
$param[psmplSMSGatewayCenter::PARAM_CALLBACK] = $this->callback;
$param[psmplSMSGatewayCenter::PARAM_SEND_METHOD] = $this->sendMethod;
$param[psmplSMSGatewayCenter::PARAM_MEDIUM] = $this->medium;
$this->baseSGCRequest($api, $sendtype, $param);
}
/*
|--------------------------------------------------------------------------
| Build basic param
|--------------------------------------------------------------------------
|
| @param url|string $api The api
| @param comp|string $sendtype The sendtype
| @param array|mixed $param The parameter
|
| @return array|mixed ( Gets all basic requested data )
|
*/
private function baseSGCRequest($api, $sendtype, $param = array()) {
$apiEndPoint = $api . $sendtype;
$param[psmplSMSGatewayCenter::PARAM_USERID] = $this->userId;
$param[psmplSMSGatewayCenter::PARAM_PASSWORD] = $this->password;
$param[psmplSMSGatewayCenter::PARAM_FORMAT] = $this->format == "" ? psmplSMSGatewayCenter::FORMAT_PLAIN : $this->format;
return $this->response = $this->sendRequestDataPostarray($apiEndPoint, $param);
}
/*
|--------------------------------------------------------------------------
| Sends a request data with post array
|--------------------------------------------------------------------------
|
| @param url|string $api The api
| @param comp|string $sendtype The sendtype
| @param array|mixed $param The parameter
|
| @throws Exception
|
| @return boolean ( returns the curl scraped page response )
|
*/
private function sendRequestDataPostarray($apiEndPoint, $param) {
//echo $apiEndPoint;exit;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiEndPoint);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param));
if ($this->apiKey && $this->apiKey != '') {
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:', 'apikey:' . $this->apiKey));
} else {
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
$curl_scraped_page = curl_exec($ch);
$getHTTPCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlError = curl_error($ch);
curl_close($ch);
if ($curl_scraped_page === false) {
throw new Exception('Unable to connect to SMSGatewayCenter API: ' . $curlError);
} elseif ($getHTTPCode != 200) {
throw new Exception('Bad response from SMSGatewayCenter API: HTTP code ' . $getHTTPCode);
}
return $curl_scraped_page;
}
/*
|--------------------------------------------------------------------------
| Send basic API related
|--------------------------------------------------------------------------
|
| @param url|string $api The api
| @param comp|string $sendtype The sendtype
*/
public function checkBasic($api, $sendtype) {
$this->baseSGCRequest($api, $sendtype);
}
/*
|--------------------------------------------------------------------------
| Sends a record. Common function to use for any API
|--------------------------------------------------------------------------
|
| @param url|string $api The api
| @param comp|string $sendtype The sendtype
| @param array|mixed $param The parameter
*/
public function sendRecord($api, $sendtype, $param) {
$this->baseSGCRequest($api, $sendtype, $param);
}
}