/
SendMessage.php
102 lines (94 loc) · 2.37 KB
/
SendMessage.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
<?php
use FastSMS\Client;
use FastSMS\Model\Message;
use FastSMS\Exception\ApiException;
require __DIR__ . '/../vendor/autoload.php';
$config = require __DIR__ . '/config.php';
#init client
$client = new Client($config['token']);
#####################################
#Send message direct phone number(s)#
#####################################
// Init Message data model
$data = [
'destinationAddress' => $config['destinations'],
'sourceAddress' => $config['source'],
'body' => 'Test API Wraper',
'scheduleDate' => time() + 7200,
'validityPeriod' => 3600 * 6,
];
// Send Message
try {
$result1 = $client->message->send($data);
print_r($result1);
/*
* Example return:
* Array
* (
* [type] => direct
* [send] => success
* [messages] => Array
* (
* [0] => 55379665
* [1] => 55379666
* )
* )
*/
} catch (ApiException $aex) {
echo 'API error #' . $aex->getCode() . ': ' . $aex->getMessage();
} catch (Exception $ex) {
echo $ex->getMessage();
}
#####################################
########Send message to list#########
#####################################
$data = [
'list' => $config['list'],
'destinationAddress' => $config['destinations'],
'sourceAddress' => $config['source'],
'body' => 'Test API Wraper',
'scheduleDate' => time() + 7200,
'validityPeriod' => 3600 * 6,
];
// Send Message
try {
$result2 = $client->message->send($data);
print_r($result2);
/*
* Array
* (
* [type] => list
* [send] => success
* )
*/
} catch (ApiException $aex) {
echo 'API error #' . $aex->getCode() . ': ' . $aex->getMessage();
} catch (Exception $ex) {
echo $ex->getMessage();
}
#####################################
########Send message to group########
#####################################
$data = [
'group' => $config['group'],
'sourceAddress' => $config['source'],
'body' => 'Test group',
'scheduleDate' => time() + 7200,
'validityPeriod' => 3600 * 6,
];
// Send Message
try {
$result3 = $client->message->send($data);
print_r($result3);
/*
* Array
* (
* [type] => group
* [send] => success
* )
*/
} catch (ApiException $aex) {
echo 'API error #' . $aex->getCode() . ': ' . $aex->getMessage();
} catch (Exception $ex) {
echo $ex->getMessage();
}