-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.php
993 lines (852 loc) · 34.8 KB
/
main.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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
<?php
/**
*
* Live Update integration with SMSLink.ro
*
* SMSLink Live Update allows you to perform various operations on your SMSLink account, using Live Update API, such as:
*
* Blacklist Phone Number Add/Remove/Verify
* Contact Create/Remove/Update
*
* Featured Functions of SMSLinkLiveUpdate class
*
* $liveUpdate = new SMSLinkLiveUpdate("MyLiveUpdateConnectionID", "MyLiveUpdatePassword");
*
* $liveUpdate->blacklistAdd(...)
* Adds a Phone Number to the Blacklist in your SMSLink account
*
* $liveUpdate->blacklistRemove(...)
* Removes a Phone Number from the Blacklist in your SMSLink account
*
* $liveUpdate->isBlacklisted(...)
* Checks if Phone Number is in the Blacklist in your SMSLink account
*
* $liveUpdate->createContact(...)
* Creates a Contact into a Specified Group in your SMSLink account
*
* $liveUpdate->updateContact(...)
* Updates a Contact from a Specified Group in your SMSLink account
*
* $liveUpdate->removeContact(...)
* Removes a Phone Number from a Specified Group or from All Groups in your SMSLink account
*
* Features
*
* Supports HTTP and HTTPS protocols
* Supports PHP cURL GET, PHP cURL POST and file_get_contents()
*
* Usage:
*
* See Usage Examples for the SMSLinkLiveUpdate() class starting on line 659
*
* Get your SMSLink / SMS Marketing / Live Update Connection ID and Password from
* https://www.smslink.ro/get-live-update-api-key/
*
* System Requirements:
*
* PHP 5 with
* CURL enabled or file_get_contents with allow_url_fopen to be set to 1 in php.ini
*
* @version 1.0
* @see https://www.smslink.ro/sms-marketing-documentatie-live-update.html
*
*/
class SMSLinkLiveUpdate
{
private $connection_id = null;
private $password = null;
private $doHTTPS = true;
private $requestMethod = 1;
protected $endpointHTTP = "http://www.smslink.ro/sms/marketing/communicate/index.php";
protected $endpointHTTPS = "https://secure.smslink.ro/sms/marketing/communicate/index.php";
public $communicationLogs = array();
protected $serviceIDs = array(
1 => "SMS Marketing",
2 => "Mail to SMS",
3 => "SMS Gateway (HTTP)",
9 => "SMS Gateway (BULK)",
10 => "SMS Gateway (SOAP)",
11 => "SMS Gateway (JSON)",
4 => "SMS Alerts",
7 => "SMS Connectors",
5 => "2-Way SMS"
);
/*******************************************************************************************************************************************************************************
*
*
* Public-Scope Functions for Object Handling and Configuration
*
*
******************************************************************************************************************************************************************************/
/**
* Initialize SMSLink - Live Update
*
* Initializing Live Update will require the parameters $connection_id and $password. $connection_id and $password can be generated at
* https://www.smslink.ro/sms/marketing/liveupdate.php after authenticated with your account credentials.
*
* @param string $connection_id SMSLink - Live Update - Connection ID
* @param string $password SMSLink - Live Update - Password
*
* @return void
*/
public function __construct($connection_id, $password)
{
if (!is_null($connection_id))
$this->connection_id = $connection_id;
if (!is_null($password))
$this->password = $password;
if ((is_null($this->connection_id)) or (is_null($this->password)))
exit("SMS Gateway initialization failed, credentials not provided. Please see documentation.");
}
public function __destruct()
{
$this->connection_id = null;
$this->password = null;
$this->doHTTPS = true;
$this->requestMethod = 1;
}
/**
* Sets the method in which the parameters are sent to SMS Gateway
*
* @param int $requestMethod 1 for cURL GET (recommended and default value)
* 2 for cURL POST
* 3 for file_get_contents (recommended if you do not have PHP cURL installed)
*
* @return bool true if method was set or false otherwise
*/
public function setRequestMethod($requestMethod = 1)
{
if (in_array($requestMethod, array(1, 2, 3))) $this->requestMethod = $requestMethod;
else return false;
return true;
}
/**
* Returns the method in which the parameters are sent to SMS Gateway
*
* @return int
*/
public function getRequestMethod()
{
return $this->requestMethod;
}
/**
* Sets the protocol that will be used by SMS Gateway (HTTPS or HTTP).
*
* @param string $methodName POST or GET
*
* @return bool true if method was set or false otherwise
*/
public function setProtocol($protocolName = "HTTPS")
{
$protocolName = strtoupper($protocolName);
if ($protocolName == "HTTPS") $this->doHTTPS = true;
elseif ($protocolName == "HTTP") $this->doHTTPS = false;
else return false;
return true;
}
/**
* Returns the protocol that is used by SMS Gateway (HTTPS or HTTP)
*
* @return string GET or POST possible values
*/
public function getProtocol()
{
return ($this->doHTTPS) ? "HTTPS" : "HTTP";
}
/**
* Returns the latest log message from communication log
*
* @return string
*/
public function getLastLogMessage()
{
return $this->communicationLogs[sizeof($this->communicationLogs) - 1];
}
/**
* Displays the communication log
*
* @return string
*/
public function displayLogMessages()
{
echo "<b>Communication Log:</b><br />";
foreach ($this->communicationLogs as $key => $logMessage)
echo $logMessage."<br />";
}
/*******************************************************************************************************************************************************************************
*
*
* Private-Scope Functions
*
*
******************************************************************************************************************************************************************************/
/**
* Prepares the Request Response
*
* @param string $requestResponse
*
* @return array
*/
private function prepareResponse($requestResponse)
{
$requestResponse = explode(";", $requestResponse);
$requestStatus = false;
if (isset($requestResponse[0]))
if ($requestResponse[0] == "MESSAGE")
$requestStatus = true;
return array(
"responseStatus" => $requestStatus,
"responseCategory" => isset($requestResponse[0]) ? $requestResponse[0] : "ERROR",
"responseCode" => isset($requestResponse[1]) ? $requestResponse[1] : 0,
"responseMessage" => isset($requestResponse[2]) ? $requestResponse[2] : "Unknown Error",
"responseParams" => isset($requestResponse[3]) ? explode(",", $requestResponse[3]) : array()
);
}
/**
* Associate the Locally Generated Request Response
*
* @param array $requestResponse
*
* @return array
*/
private function assocResponse($requestResponse)
{
return array(
"responseStatus" => isset($requestResponse[0]) ? $requestResponse[0] : false,
"responseCategory" => isset($requestResponse[1]) ? $requestResponse[1] : "ERROR",
"responseCode" => isset($requestResponse[2]) ? $requestResponse[2] : 0,
"responseMessage" => isset($requestResponse[3]) ? $requestResponse[3] : "Unknown Error",
"responseParams" => isset($requestResponse[4]) ? explode(",", $requestResponse[4]) : array()
);
}
/**
* Prepares the Request for SMSLink
*
* @param array $requestParameters
*
* @return string
*/
private function prepareSendRequest($requestParameters)
{
$requestURL = ($this->getProtocol() == "HTTPS") ? $this->endpointHTTPS : $this->endpointHTTP;
$requestCommonParameters = array(
"connection_id" => $this->connection_id,
"password" => $this->password
);
$requestParameters = array_merge($requestCommonParameters, $requestParameters);
return $this->sendRequest($requestURL, $requestParameters);
}
/**
* Sends Request to SMSLink
*
* @param string $requestURL
* @param array $requestParameters
*
* @return string
*/
private function sendRequest($requestURL, $requestParameters)
{
$requestResult = false;
$returnedResult = "ERROR;0;Unknown error.";
$requestMethod = $this->getRequestMethod();
$logMessage = date("d-m-Y H:i:s")." - Sending Request using ";
if ($requestMethod == 1)
$logMessage = $logMessage."cURL GET";
if ($requestMethod == 2)
$logMessage = $logMessage."cURL POST";
if ($requestMethod == 3)
$logMessage = $logMessage."file_get_contents()";
$serializedParameters = http_build_query($requestParameters);
if (($requestMethod == 1) or ($requestMethod == 2))
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $requestURL.(($requestMethod == 1) ? "?".$serializedParameters : ""));
$logMessage = $logMessage." to URL: [".$requestURL.(($requestMethod == 1) ? "?".$serializedParameters : "")."]";
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if ($requestMethod == 2)
{
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $serializedParameters);
$logMessage = $logMessage." with POST parameters: [".$serializedParameters."]";
}
if (strpos($requestURL, "https://") !== false)
{
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
$requestResult = curl_exec($ch);
$connectionErrorCode = curl_errno($ch);
$connectionErrorMessage = curl_error($ch);
$requestStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($connectionErrorCode == 0)
{
if (($requestStatusCode >= 200) and ($requestStatusCode <= 299))
{
$returnedResult = $requestResult;
}
else
{
$returnedResult = "ERROR;0;Unexpected HTTP code ".$requestStatusCode;
}
}
else
{
$returnedResult = "ERROR;0;".$connectionErrorMessage;
}
curl_close($ch);
}
else
{
if ($requestMethod == 3)
{
$requestResult = file_get_contents($requestURL."?".$serializedParameters);
$logMessage = $logMessage." to URL: [".$requestURL."?".$serializedParameters."]";
if ($requestResult !== false)
{
$returnedResult = $requestResult;
}
else
{
$returnedResult = "ERROR;0;Connection failed using file_get_contents().";
}
}
}
$logMessage = $logMessage." => Request Result: [".$returnedResult."]";
$this->communicationLogs[] = $logMessage;
return $returnedResult;
}
/**
* Formats the Phone Number
*
* @param string $phoneNumber
*
* @return string
*/
private function formatPhoneNumber($phoneNumber)
{
$phoneNumber = str_replace("+", "00", $phoneNumber); // Converts + to 00
$phoneNumber = preg_replace("/[^0-9]/", "", $phoneNumber); // Remove all non-numeric characters
return $phoneNumber;
}
/*******************************************************************************************************************************************************************************
*
*
* Public-Scope Functions
*
*
******************************************************************************************************************************************************************************/
/**
* Adds a Phone Number to the Blacklist
*
* @param string $phoneNumber Phone Number
*
* @param array $blacklistedServiceIDs If the value is an empty array, the Phone Number will be blacklisted for all the SMSLink services.
* If the value is an array, the Phone Number will be blacklisted for the enumerated services from the array.
*
* Examples:
*
* - if the value is array(), the Phone Number will be blacklisted for all the SMSLink services
* - if the value is array(1, 2), the Phone Number will be blacklisted for SMS Marketing and Mail to SMS services.
*
* @param bool $forceUpdate If the Phone Number already exists in the blacklist and if this parameter is set to true, it will force an update of the
* Phone Number from the Blacklist.
*
* If the Phone Number already exists in the blacklist and if this parameter is set to false, it will do nothing to the
* Phone Number in the Blacklist.
*
* @return array
*/
public function blacklistAdd($phoneNumber, $blacklistedServiceIDs = array(), $forceUpdate = true)
{
$phoneNumber = $this->formatPhoneNumber($phoneNumber);
if (strlen($phoneNumber) == 0)
return $this->assocResponse(array(false, "ERROR", 0, "Error Thrown in ".__FUNCTION__.": Invalid Phone Number."));
$requestParameters = array(
"mode" => "blacklist-add",
"receiver_number" => $phoneNumber,
"force_update" => ($forceUpdate == true) ? 1 : 0
);
if (sizeof($blacklistedServiceIDs) > 0)
$requestParameters["service_ids"] = implode(",", $blacklistedServiceIDs);
$requestResponse = $this->prepareSendRequest($requestParameters);
$requestResponse = $this->prepareResponse($requestResponse);
return $requestResponse;
}
/**
* Removes a Phone Number from the Blacklist
*
* @param string $phoneNumber Phone Number
*
* @return array
*/
public function blacklistRemove($phoneNumber)
{
$phoneNumber = $this->formatPhoneNumber($phoneNumber);
if (strlen($phoneNumber) == 0)
return $this->assocResponse(array(false, "ERROR", 0, "Error Thrown in ".__FUNCTION__.": Invalid Phone Number."));
$requestParameters = array(
"mode" => "blacklist-remove",
"receiver_number" => $phoneNumber
);
$requestResponse = $this->prepareSendRequest($requestParameters);
$requestResponse = $this->prepareResponse($requestResponse);
return $requestResponse;
}
/**
* Checks if Phone Number is in the Blacklist
*
* @param string $phoneNumber Phone Number
*
* @return array(
* "isRequestError" => (bool) true if an error occured occured during request or false otherwise,
* "isBlacklisted" => (bool) true if Phone Number is blacklisted or false otherwise,
* "responseCategory" => (string) the category of the response, ERROR for errors or MESSAGE on success,
* "responseCode" => (int) the code of the response, according to the documentation,
* "responseMessage" => (string) the blacklist response message for the query,
* "responseParams" => (array) the parameters associated with the response, according to the documentation
* )
*/
public function isBlacklisted($phoneNumber)
{
$phoneNumber = $this->formatPhoneNumber($phoneNumber);
if (strlen($phoneNumber) == 0)
return $this->assocResponse(array(false, "ERROR", 0, "Error Thrown in ".__FUNCTION__.": Invalid Phone Number."));
$requestParameters = array(
"mode" => "blacklist-verify",
"receiver_number" => $phoneNumber
);
$requestResponse = $this->prepareSendRequest($requestParameters);
$requestResponse = $this->prepareResponse($requestResponse);
$isBlacklistedResponse = array(
"isRequestError" => true,
"isBlacklisted" => false,
);
if ($requestResponse["responseStatus"] == true)
{
if ($requestResponse["responseCategory"] == "MESSAGE")
{
$isBlacklistedResponse["isRequestError"] = false;
if (((int) $requestResponse["responseCode"] == 12) or ((int) $requestResponse["responseCode"] == 13))
$isBlacklistedResponse["isBlacklisted"] = true;
if ((int) $requestResponse["responseCode"] == 14)
$isBlacklistedResponse["isBlacklisted"] = false;
}
}
$isBlacklistedResponse = array_merge($isBlacklistedResponse, $requestResponse);
return $isBlacklistedResponse;
}
/**
* Creates a Contact into a Specified Group
*
* @param string $phoneNumber Phone Number
*
* @param int $groupId Group ID in which the contact will be created
*
* @param string $contactFullName (Optional) Full name for the contact
*
* @param array $contactVariabiles (Optional) Associative array with up to 25 contact variabiles. Example:
* array(
* "dynamic_variabile_1" => "... value ...",
* "dynamic_variabile_2" => "... value ...",
* "dynamic_variabile_3" => "... value ...",
* ...
* "dynamic_variabile_25" => "... value ...",
* )
*
* @param bool $allowDuplicate (Optional) If set to true, duplicates will be allowed.
* If set to false, duplicates will return an error.
*
* @param int $duplicateScope (Optional) Scope for duplicates check.
* If set to 1, the check will be done inside the Group ID.
* If set to 2, the check will be within all groups from the account.
*
* @return array
*/
public function createContact($phoneNumber, $groupId, $contactFullName = null, $contactVariabiles = array(), $allowDuplicate = false, $duplicateScope = 1)
{
$phoneNumber = $this->formatPhoneNumber($phoneNumber);
if (strlen($phoneNumber) == 0)
return $this->assocResponse(array(false, "ERROR", 0, "Error Thrown in ".__FUNCTION__.": Invalid Phone Number."));
if ($groupId == 0)
return $this->assocResponse(array(false, "ERROR", 0, "Error Thrown in ".__FUNCTION__.": Invalid Group ID."));
if (sizeof($contactVariabiles) > 25)
return $this->assocResponse(array(false, "ERROR", 0, "Error Thrown in ".__FUNCTION__.": Too many contact variabiles."));
$requestParameters = array(
"mode" => "receiver-add",
"receiver_number" => $phoneNumber,
"group_id" => $groupId,
"duplicate" => ($allowDuplicate == false) ? 1 : 0,
"duplicate_scope" => $duplicateScope,
"receiver_name" => (!is_null($contactFullName)) ? $contactFullName : "",
);
if (sizeof($contactVariabiles) > 0)
{
foreach($contactVariabiles as $contactVariabileKey => $contactVariabileValue)
$requestParameters[$contactVariabileKey] = $contactVariabileValue;
}
$requestResponse = $this->prepareSendRequest($requestParameters);
$requestResponse = $this->prepareResponse($requestResponse);
return $requestResponse;
}
/**
* Updates a Contact from a Specified Group
*
* @param string $phoneNumber Phone Number
*
* @param int $groupId Group ID in which the contact will be updated.
* If set to 0, the contact will be updated within all groups.
*
* @param string $contactFullName (Optional) Full name for the contact
*
* @param array $contactVariabiles (Optional) Associative array with up to 25 contact variabiles. Example:
* array(
* "dynamic_variabile_1" => "... value ...",
* "dynamic_variabile_2" => "... value ...",
* "dynamic_variabile_3" => "... value ...",
* ...
* "dynamic_variabile_25" => "... value ...",
* )
*
* @return array
*/
public function updateContact($phoneNumber, $groupId = 0, $contactFullName = null, $contactVariabiles = array())
{
$phoneNumber = $this->formatPhoneNumber($phoneNumber);
if (strlen($phoneNumber) == 0)
return $this->assocResponse(array(false, "ERROR", 0, "Error Thrown in ".__FUNCTION__.": Invalid Phone Number."));
if (sizeof($contactVariabiles) > 25)
return $this->assocResponse(array(false, "ERROR", 0, "Error Thrown in ".__FUNCTION__.": Too many contact variabiles."));
$requestParameters = array(
"mode" => "receiver-update",
"receiver_number" => $phoneNumber,
"group_id" => $groupId,
"receiver_name" => (!is_null($contactFullName)) ? $contactFullName : "",
);
if (sizeof($contactVariabiles) > 0)
{
foreach($contactVariabiles as $contactVariabileKey => $contactVariabileValue)
$requestParameters[$contactVariabileKey] = $contactVariabileValue;
}
$requestResponse = $this->prepareSendRequest($requestParameters);
$requestResponse = $this->prepareResponse($requestResponse);
return $requestResponse;
}
/**
* Removes a Phone Number from a Specified Group or from All Groups
*
* @param string $phoneNumber Phone Number
* @param int $groupId The Group ID from which the contact will be removed. If set to 0, the contact will be removed from all groups.
*
* @return array
*/
public function removeContact($phoneNumber, $groupId = 0)
{
$phoneNumber = $this->formatPhoneNumber($phoneNumber);
if (strlen($phoneNumber) == 0)
return $this->assocResponse(array(false, "ERROR", 0, "Error Thrown in ".__FUNCTION__.": Invalid Phone Number."));
$requestParameters = array(
"mode" => "receiver-remove",
"receiver_number" => $phoneNumber,
"group_id" => $groupId
);
$requestResponse = $this->prepareSendRequest($requestParameters);
$requestResponse = $this->prepareResponse($requestResponse);
return $requestResponse;
}
}
/*
*
*
*
*
*
* Usage Examples for the SMSLinkLiveUpdate() class
*
*
*
*
*
*
*/
/*
*
*
* Initialize SMS Marketing Live Update
*
* Get your SMSLink / SMS Gateway Connection ID and Password from
* https://www.smslink.ro/get-live-update-api-key/
*
*
*
*/
$liveUpdate = new SMSLinkLiveUpdate("MyLiveUpdateConnectionID", "MyLiveUpdatePassword");
/*
* Sets the method in which the parameters are sent to Live Update
*
* 1 for cURL GET (make sure you have PHP cURL installed) (default and recommended)
* 2 for cURL POST (make sure you have PHP cURL installed)
* 3 for file_get_contents (requires allow_url_fopen to be set to 1 in php.ini) (recommended if you do not have PHP cURL installed)
*/
$liveUpdate->setRequestMethod(1);
/*
* Sets the protocol that will be used by SMS Gateway (HTTPS or HTTP).
*/
$liveUpdate->setProtocol("HTTPS");
/*
*
*
*
* Request & Response Examples
*
*
*
*/
/*
*
*
* Adds a Phone Number to the Blacklist
*
*
*/
echo "<b>Example for Adding a Phone Number to the Blacklist</b><br />";
$liveUpdateResult = $liveUpdate->blacklistAdd("07xyzzzzzz");
if ($liveUpdateResult["responseStatus"] == true)
{
echo "-- Phone Number successfuly added to the blacklist. ".$liveUpdateResult["responseMessage"]."<br />";
}
else
{
echo "-- Could not add Phone Number to the blacklist. ".$liveUpdateResult["responseMessage"]."<br />";
if ($liveUpdateResult["responseCategory"] == "ERROR")
{
switch ((int) $liveUpdateResult["responseCode"])
{
case 14:
echo "---- Phone Number is already blacklisted.";
break;
default:
echo "---- Failed to connect to the blacklist.";
break;
}
echo "<br />";
}
}
echo "<br />";
/*
*
*
* Checks if a Phone Number is Blacklisted
*
*
*/
echo "<b>Example for Verifying a Phone Number to the Blacklist</b><br />";
$liveUpdateResult = $liveUpdate->isBlacklisted("07xyzzzzzz");
if ($liveUpdateResult["isRequestError"] == false)
{
if ($liveUpdateResult["isBlacklisted"] == true)
{
echo "-- Phone Number found in the blacklist. (".$liveUpdateResult["responseMessage"].")<br />";
if ($liveUpdateResult["responseCategory"] == "MESSAGE")
{
switch ((int) $liveUpdateResult["responseCode"])
{
case 12:
echo "---- Phone Number is blacklisted for all services.";
break;
case 13:
echo "---- Phone Number is blacklisted for the following services: ";
break;
}
echo "<br />";
}
}
else
{
echo "-- Phone Number not found in the blacklist. (".$liveUpdateResult["responseMessage"].")<br />";
}
}
else
{
echo "-- Could not query the blacklist. (".$liveUpdateResult["responseMessage"].")<br />";
}
echo "<br />";
/*
*
*
* Removes a Phone Number from the Blacklist
*
*
*/
echo "<b>Example for Removing a Phone Number from the Blacklist</b><br />";
$liveUpdateResult = $liveUpdate->blacklistRemove("07xyzzzzzz");
if ($liveUpdateResult["responseStatus"] == true)
{
echo "-- Phone Number successfuly removed from the blacklist. ".$liveUpdateResult["responseMessage"]."<br />";
}
else
{
echo "-- Could not remove Phone Number from the blacklist. ".$liveUpdateResult["responseMessage"]."<br />";
if ($liveUpdateResult["responseCategory"] == "ERROR")
{
switch ((int) $liveUpdateResult["responseCode"])
{
case 12:
echo "---- Phone Number is not blacklisted.";
break;
default:
echo "---- Failed to connect to the blacklist.";
break;
}
echo "<br />";
}
}
echo "<br />";
/*
*
*
* Create a Contact in a Group
*
*
*/
echo "<b>Example for Creating a Contact in a Group</b><br />";
$liveUpdateResult = $liveUpdate->createContact(
"07xyzzzzzz",
54321,
"Nume Prenume",
array(
"dynamic_variabile_1" => "... valoare 1 ...",
"dynamic_variabile_2" => "... valoare 2 ...",
"dynamic_variabile_3" => "... valoare 3 ...",
"dynamic_variabile_4" => "... valoare 4 ...",
),
false,
1
);
if ($liveUpdateResult["responseStatus"] == true)
{
echo "-- Contact successfuly created. ".$liveUpdateResult["responseMessage"]."<br />";
}
else
{
echo "-- Could create contact. ".$liveUpdateResult["responseMessage"]."<br />";
if ($liveUpdateResult["responseCategory"] == "ERROR")
{
switch ((int) $liveUpdateResult["responseCode"])
{
case 10:
echo "---- Permission denied to specified group.";
break;
case 15:
echo "---- Phone Number already exists in the specified group.";
break;
case 22:
echo "---- Phone Number already exists in groups.";
break;
case 30:
echo "---- Permission denied the specified Live Update method. Check Live Update settings on SMSLink.";
break;
default:
echo "---- Failed to connect to the specified group.";
break;
}
echo "<br />";
}
}
echo "<br />";
/*
*
*
* Updates a Contact in a Group
*
*
*/
echo "<b>Example for Updating a Contact in a Group</b><br />";
$liveUpdateResult = $liveUpdate->updateContact(
"07xyzzzzzz",
54321,
"Nume Prenume",
array(
"dynamic_variabile_1" => "... valoare actualizata 1 ...",
"dynamic_variabile_2" => "... valoare actualizata 2 ...",
"dynamic_variabile_3" => "... valoare actualizata 3 ...",
"dynamic_variabile_4" => "... valoare actualizata 4 ...",
)
);
if ($liveUpdateResult["responseStatus"] == true)
{
echo "-- Contact successfuly updated. ".$liveUpdateResult["responseMessage"]."<br />";
}
else
{
echo "-- Could update contact. ".$liveUpdateResult["responseMessage"]."<br />";
if ($liveUpdateResult["responseCategory"] == "ERROR")
{
switch ((int) $liveUpdateResult["responseCode"])
{
case 24:
echo "---- Permission denied to specified group.";
break;
case 25:
echo "---- Phone Number not found.";
break;
case 26:
echo "---- No associated data passed for updating.";
break;
case 30:
echo "---- Permission denied the specified Live Update method. Check Live Update settings on SMSLink.";
break;
default:
echo "---- Failed to connect to the specified group.";
break;
}
echo "<br />";
}
}
echo "<br />";
/*
*
*
* Removes a Contact from a Group
*
*
*/
echo "<b>Example for Removing a Contact in a Group</b><br />";
$liveUpdateResult = $liveUpdate->removeContact(
"07xyzzzzzz",
54321
);
if ($liveUpdateResult["responseStatus"] == true)
{
echo "-- Contact successfuly removed. ".$liveUpdateResult["responseMessage"]."<br />";
}
else
{
echo "-- Could remove contact. ".$liveUpdateResult["responseMessage"]."<br />";
if ($liveUpdateResult["responseCategory"] == "ERROR")
{
switch ((int) $liveUpdateResult["responseCode"])
{
case 13:
echo "---- Permission denied to specified group.";
break;
case 17:
echo "---- Invalid specified group.";
break;
case 30:
echo "---- Permission denied the specified Live Update method. Check Live Update settings on SMSLink.";
break;
case 32:
case 33:
echo "---- Phone Number not found.";
break;
default:
echo "---- Failed to connect to the specified group.";
break;
}
echo "<br />";
}
}
echo "<br />";
?>