/
Documentação para programadores BulkGate
/
PHP SDK
/
SMS em massa (PHP SDK 1.0)
SMS em massa (PHP SDK 1.0)
A classe BulkGate\Sms\BulkMessage representa o objeto que junta mensagens do tipo `BulkGate\Sms\Message` numa mensagem em massa (campanha).
use BulkGate\Sms\BulkMessage ;
O construtor tem um parâmetro opcional do tipo array , que tem de conter itens `BulkGate\Sms\Message` .
$array = [
new BulkGate\Sms\Message ("420777777777" , "test1" ),
new BulkGate\Sms\Message ("420777777778" , "test2" ),
new BulkGate\Sms\Message ("420777777779" , "test3" ),
new BulkGate\Sms\Message ("420777777780" , "test4" ),
];
$bulk_message = new BulkMessage ($array );
As mensagens podem ser adicionadas uma de cada vez:
$message = new BulkGate\Sms\Message (
new BulkGate\Sms\Message\PhoneNumber ("777777781" , BulkGate\Sms\Country ::CZECH_REPUBLIC ),
new BulkGate\Sms\Message\Text ("test<number>" , [
'number' => '5'
])
);
$bulk_message ->addMessage ($message );
Iterador
Pode percorrer as mensagens com o ciclo foreach
foreach ($bulk_message as $message )
{
echo $message ;
}
O número de mensagens obtém-se com count()
$bulk_message ->count ();
Suporte de JSON
O objeto BulkGate\Sms\BulkMessage implementa a interface \JsonSerializable , que permite convertê-lo para o formato JSON através da função json_encode() .
echo json_encode ($bulk_message );
O resultado é:
[
{
"number" : {
"number" : "420777777777" ,
"iso" : null
} ,
"text" : "test1" ,
"status" : "preparation" ,
"price" : 0.0,
"credit" : 0.0,
"id" : null,
"scheduled" : null
} ,
{
"number" : {
"number" : "420777777778" ,
"iso" : null
} ,
"text" : "test2" ,
"status" : "preparation" ,
"price" : 0.0,
"credit" : 0.0,
"id" : null,
"scheduled" : null
} ,
{
"number" : {
"number" : "420777777779" ,
"iso" : null
} ,
"text" : "test3" ,
"status" : "preparation" ,
"price" : 0.0,
"credit" : 0.0,
"id" : null,
"scheduled" : null
} ,
{
"number" : {
"number" : "420777777780" ,
"iso" : null
} ,
"text" : "test4" ,
"status" : "preparation" ,
"price" : 0.0,
"credit" : 0.0,
"id" : null,
"scheduled" : null
} ,
{
"number" : {
"number" : "777777781" ,
"iso" : "cz"
} ,
"text" : "test5" ,
"status" : "preparation" ,
"price" : 0.0,
"credit" : 0.0,
"id" : null,
"scheduled" : null
}
]
Conversão para string
O objeto BulkGate\Sms\BulkMessage implementa o método mágico __string() .
$message = (string ) $bulk_message ;
echo $bulk_message ;
O resultado é:
420777777777 : test1
420777777778 : test2
420777777779 : test3
420777777780 : test4
777777781 : test5
Conversão para array
$array = $message ->toArray ();
Esta página foi útil?
thumb_up Sim
thumb_down Não
Obrigado pelo seu feedback.