Unified Push supports push notifications for iOS, Android and Windows Phone devices via APNs, GCM and MPNS.
Wiki: UML structure and sequence diagrams.
The recommended way to install UnifiedPush is through composer.
{
"require": {
"zbox/unified-push": "^0.9"
}
}
- Unified interface that supports sending push notifications for platforms:
- Apple (APNS)
- Android (GCM)
- Windows Phone (MPNS)
- PHP 5.3.2 or later
- HTTP client (kriswallsmith/buzz)
- PSR Log (psr/log)
- PHPUnit to run tests
Create service client factory configured with credentials.
<?php
use Zbox\UnifiedPush\NotificationService\ServiceClientFactory;
use Zbox\UnifiedPush\NotificationService\ServiceCredentialsFactory;
use Zbox\UnifiedPush\Utils\ClientCredentials\CredentialsMapper;
$credentialsFactory =
new ServiceCredentialsFactory(
new CredentialsMapper()
);
$credentials = ['certificate' => 'path', 'certificatePassPhrase' => 'pass'];
$credentialsFactory->addCredentialsForService('APNS', $credentials);
$clientFactory = new ServiceClientFactory($credentialsFactory);
$clientFactory->setDefaultConfigPath();
Initialize class with client factory, notification builder and response handler.
<?php
use Zbox\UnifiedPush\Dispatcher;
use Zbox\UnifiedPush\Notification\NotificationBuilder;
use Zbox\UnifiedPush\NotificationService\ResponseHandler;
$dispatcher =
new Dispatcher(
$clientFactory,
new NotificationBuilder(),
new ResponseHandler()
);
$dispatcher->setDevelopmentMode(true);
Create messages of type APNS, GCM, MPNS (Raw, Tile or Toast).
<?php
use Zbox\UnifiedPush\Message\MessageCollection;
use Zbox\UnifiedPush\Message\Type\APNS as APNSMessage;
use Zbox\UnifiedPush\Message\Type\APNSAlert;
use Zbox\UnifiedPush\Message\Type\GCM as GCMMessage;
$message1 = new APNSMessage();
$message1
->setAlertDictionary(
(new APNSAlert)
->setActionLocKey('btn')
->setLocKey('msg')
->setLocArgs([$args])
)
->setSound('alert')
->getBadge('2');
$message1->addRecipient('deviceToken1');
$message2 = new GCMMessage();
$message2
->setCollapseKey('key')
->addRecipientIdentifiers(
new \ArrayIterator([
'deviceToken1',
'deviceToken2'
])
)
->setPayloadData([
'keyA' => 'value1',
'keyB' => 'value2',
]);
$messages =
new MessageCollection([
$message1,
$message2
]);
Send messages and load feedback.
<?php
$dispatcher
->dispatchAll($messages)
->loadFeedback();
Handle responses to see a report on dispatch errors.
<?php
$responseHandler = $dispatcher->getResponseHandler();
$responseHandler->handleResponseCollection();
$invalidRecipients = $responseHandler->getInvalidRecipients();
$messageErrors = $responseHandler->getMessageErrors();
MIT, see LICENSE.