Nada encontrado

Está a ver uma versão anterior desta página.

Abrir versão atual

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' ]) ); /** @var BulkGate\Sms\BulkMessage $bulk_message */ $bulk_message->addMessage($message);

Iterador

Pode percorrer as mensagens com o ciclo foreach

/** * @var BulkGate\Sms\BulkMessage $bulk_message * @var BulkGate\Sms\Message $message */ foreach($bulk_message as $message) { echo $message; }

O número de mensagens obtém-se com count()

/** @var BulkGate\Sms\BulkMessage $bulk_message */ $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().

/** @var BulkGate\Sms\BulkMessage $bulk_message */ 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().

/** @var BulkGate\Sms\BulkMessage $bulk_message */ $message = (string) $bulk_message; // para a variável echo $bulk_message; // para a saída

O resultado é:

420777777777: test1 420777777778: test2 420777777779: test3 420777777780: test4 777777781: test5

Conversão para array

/** @var BulkGate\Sms\BulkMessage $bulk_message */ $array = $message->toArray();
Esta página foi útil?