/
Dokumentácia pre vývojárov BulkGate
/
PHP SDK
/
Hromadná správa (PHP SDK 1.0)
Hromadná správa (PHP SDK 1.0)
Trieda BulkGate\Sms\BulkMessage reprezentuje objekt, ktorý spája správy typu `BulkGate\Sms\Message` do hromadnej správy (kampane).
use BulkGate\Sms\BulkMessage ;
Konštruktor má jeden nepovinný parameter typu array , ktorý musí obsahovať položky typu `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 );
Správy môžete pridávať aj po jednej:
$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 );
Iterátor
Správami môžete prechádzať pomocou cyklu foreach
foreach ($bulk_message as $message )
{
echo $message ;
}
Počet správ zistíme metódou count()
$bulk_message ->count ();
Podpora JSON
Objekt BulkGate\Sms\BulkMessage implementuje rozhranie \JsonSerializable , vďaka ktorému ho môžete previesť pomocou funkcie json_encode() do formátu JSON.
echo json_encode ($bulk_message );
Výstupom je:
[
{
"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
}
]
Prevod na reťazec
Objekt BulkGate\Sms\BulkMessage implementuje magickú metódu __string() .
$message = (string ) $bulk_message ;
echo $bulk_message ;
Výstupom je:
420777777777 : test1
420777777778 : test2
420777777779 : test3
420777777780 : test4
777777781 : test5
Prevod na pole
$array = $message ->toArray ();
Bola táto stránka užitočná?
thumb_up Áno
thumb_down Nie
Ďakujeme za spätnú väzbu.