No se ha encontrado nada

Está viendo una versión anterior de esta página.

Abrir versión actual

SMS masivos (PHP SDK 1.0)

La clase BulkGate\Sms\BulkMessage representa el objeto que agrupa mensajes del tipo `BulkGate\Sms\Message` en un mensaje masivo (campaña).

use BulkGate\Sms\BulkMessage;

El constructor tiene un parámetro opcional de tipo array, que debe contener elementos `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);

Los mensajes pueden añadirse de uno en uno:

$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

Puede recorrer los mensajes con el bucle foreach

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

Puede averiguar el número de mensajes con count()

/** @var BulkGate\Sms\BulkMessage $bulk_message */ $bulk_message->count();

Compatibilidad con JSON

El objeto BulkGate\Sms\BulkMessage implementa la interfaz \JsonSerializable, que permite convertirlo a formato JSON mediante la función json_encode().

/** @var BulkGate\Sms\BulkMessage $bulk_message */ echo json_encode($bulk_message);

La salida es:

[ { "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 } ]

Conversión a cadena

El objeto BulkGate\Sms\BulkMessage implementa el método mágico __string().

/** @var BulkGate\Sms\BulkMessage $bulk_message */ $message = (string) $bulk_message; // a la variable echo $bulk_message; // a la salida

La salida es:

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

Conversión a array

/** @var BulkGate\Sms\BulkMessage $bulk_message */ $array = $message->toArray();
¿Le ha resultado útil esta página?