-
-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
1,283 additions
and
1,306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
bin | ||
composer.phar | ||
composer.lock | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,4 @@ script: | |
|
||
notifications: | ||
email: | ||
- ph3@slynett.com | ||
- cedric@dugat.me |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License | ||
|
||
Copyright (c) 2013 Cédric Dugat (cedric@dugat.me) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is furnished | ||
to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,168 +1,110 @@ | ||
# NotificationPusher | ||
|
||
PHP library for easy Apple/Android notification message pushing. | ||
Standalone PHP library for easy devices message notifications push. | ||
|
||
## WORK IN PROGRESS. | ||
|
||
[![Continuous Integration status](https://secure.travis-ci.org/Ph3nol/NotificationPusher.png)](http://travis-ci.org/Ph3nol/NotificationPusher) | ||
[![Build Status](https://secure.travis-ci.org/Ph3nol/NotificationPusher.png)](http://travis-ci.org/Ph3nol/NotificationPusher) | ||
|
||
## Requirements | ||
|
||
* PHP 5.3+ | ||
* PHP Curl extension - +SSL support (for AndroidPusher service) | ||
* PHP OpenSSL extension (for ApplePusher service) | ||
|
||
## Installation | ||
|
||
### Add to your project Composer packages | ||
|
||
Just add `sly/notification-pusher` package to the requirements of your Composer JSON configuration file, | ||
and run `php composer.phar install` to install it. | ||
|
||
### Install from GitHub | ||
|
||
Clone this library from Git with `git clone https://github.com/Ph3nol/NotificationPusher.git`. | ||
|
||
Goto to the library directory, get Composer phar package and install vendors: | ||
* PHP Curl and OpenSSL modules | ||
* Specific adapters requirements (like APNS certificate, GCM application ID and API key, etc.) | ||
|
||
``` | ||
curl -s https://getcomposer.org/installer | php | ||
php composer.phar install | ||
``` | ||
|
||
You're ready to go. | ||
|
||
## Example | ||
## Today available adapters | ||
|
||
### Apple push (iPhone / iPad) | ||
* APNS (Apple) | ||
* GCM (Android) - imminent implementation | ||
|
||
* Requirements: create a developer SSL certificate for your application | ||
## First basic push example (APNS one) | ||
|
||
``` php | ||
<?php | ||
|
||
require_once '/path/to/your/vendor/autoload.php'; | ||
|
||
use Sly\NotificationPusher\Model\Message; | ||
use Sly\NotificationPusher\Pusher\ApplePusher; | ||
|
||
/** | ||
* Initialize Apple pusher service. | ||
*/ | ||
$pusher = new ApplePusher(array( | ||
'dev' => true, // Developer/Sandbox mode enabled (default: false) | ||
'simulate' => false, // Simulate sendings (default: false) | ||
'certificate' => '/path/to/your/certificate.pem', | ||
'certificate_passphrase' => 'myPassPhrase', // Generated certificate passphrase (if needed) | ||
'devices' => array('D3v1c3T0k3n1', 'D3v1c3T0k3n2', 'D3v1c3T0k3n3'), // Apple Device Tokens | ||
require_once '/path/to/vendor/autoload.php'; | ||
|
||
use Sly\NotificationPusher\PushManager, | ||
Sly\NotificationPusher\Adapter\Apns as ApnsAdapter, | ||
Sly\NotificationPusher\Collection\DeviceCollection, | ||
Sly\NotificationPusher\Model\Device, | ||
Sly\NotificationPusher\Model\Message, | ||
Sly\NotificationPusher\Model\Push | ||
; | ||
|
||
// First, instanciate the manager. | ||
// | ||
// Example for production environement: | ||
// $pushManager = new PushManager(PushManager::ENVIRONMENT_PRODUCTION); | ||
// | ||
// Development one by default (without argument). | ||
$pushManager = new PushManager(PushManager::ENVIRONMENT_DEV); | ||
|
||
// Then declare an adapter. | ||
$apnsAdapter = new ApnsAdapter(array( | ||
'certificate' => '/path/to/your/apns-certificate.pem', | ||
)); | ||
|
||
/** | ||
* Add some test pushes. | ||
*/ | ||
for ($i = 1; $i <= 3; $i++) { | ||
$message = new Message(sprintf('This is Test #%d', $i)); | ||
// $message->setAlert(false); // Don't display message | ||
// $message->setBadge(5); // Increment users badges with '5' | ||
// $message->setSound('bingbong.aiff'); // Set specific sound | ||
|
||
$pusher->addMessage($message); | ||
} | ||
|
||
/** | ||
* Push queue. | ||
*/ | ||
$pushedMessages = $pusher->push(); | ||
``` | ||
// Set the device(s) to push the notification to. | ||
$devices = new DeviceCollection(array( | ||
new Device('149cc24975da6c6b98605a8d268052ac0a214ec1e32110ab06f72b58401c1611'), | ||
)); | ||
|
||
To manage users badges, we can pass a specific array to the pusher service (instead of passing an array of tokens). | ||
This array contains 2 informations: the device token and the actual user badge count. Here is an example of | ||
an ApplePusher service instance: | ||
// Then, create the push skel. | ||
$message = new Message('This is a basic example of push.'); | ||
|
||
``` php | ||
$pusher = new ApplePusher(array( | ||
'dev' => true, // Developer/Sandbox mode enabled (default: false) | ||
'simulate' => false, // Simulate sendings (default: false) | ||
'certificate' => '/path/to/your/certificate.pem', | ||
'devices' => array( | ||
array('D3v1c3T0k3n1', 0), // User 1 has a '0' badge count | ||
array('D3v1c3T0k3n2', 5), // User 2 has a '5' badge count | ||
array('D3v1c3T0k3n3', 2), // User 3 has a '2' badge count | ||
// ... | ||
), | ||
)); | ||
// Finally, create and add the push to the manager, and push it! | ||
$push = new Push($apnsAdapter, $devices, $message); | ||
$pushManager->add($push); | ||
$pushManager->push(); | ||
``` | ||
|
||
Each user badge count will be incremented with the Message object badge parameter. | ||
|
||
### Android push | ||
**For more examples and custom utilization, refer to the documentation below.** | ||
|
||
* Requirements: get a Google account project API key | ||
## First basic feedback example (APNS one) | ||
|
||
``` php | ||
<?php | ||
|
||
require_once '/path/to/your/vendor/autoload.php'; | ||
|
||
use Sly\NotificationPusher\Model\Message; | ||
use Sly\NotificationPusher\Pusher\AndroidPusher; | ||
|
||
/** | ||
* Initialize Android pusher service. | ||
*/ | ||
$pusher = new AndroidPusher(array( | ||
'applicationID' => '123456789012', // Your Google project application ID | ||
'apiKey' => 'y0ur4p1k3y', // Your Google account project API key | ||
'devices' => array('D3v1c3T0k3n1', 'D3v1c3T0k3n2', 'D3v1c3T0k3n3'), // Android register IDs | ||
)); | ||
require_once '/path/to/vendor/autoload.php'; | ||
|
||
/** | ||
* Add some test pushes. | ||
*/ | ||
for ($i = 1; $i <= 3; $i++) { | ||
$message = new Message(sprintf('This is Test #%d', $i)); | ||
use Sly\NotificationPusher\PushManager, | ||
Sly\NotificationPusher\Adapter\Apns as ApnsAdapter | ||
; | ||
|
||
$pusher->addMessage($message); | ||
} | ||
// First, instanciate the manager. | ||
// | ||
// Example for production environement: | ||
// $pushManager = new PushManager(PushManager::ENVIRONMENT_PRODUCTION); | ||
// | ||
// Development one by default (without argument). | ||
$pushManager = new PushManager(PushManager::ENVIRONMENT_DEV); | ||
|
||
/** | ||
* Push queue. | ||
*/ | ||
$pushedMessages = $pusher->push(); | ||
// Then declare an adapter. | ||
$apnsAdapter = new ApnsAdapter(array( | ||
'certificate' => '/path/to/your/apns-certificate.pem', | ||
)); | ||
|
||
$feedback = $pushManager->getFeedback($apnsAdapter); // array of Token + DateTime couples | ||
``` | ||
|
||
## Test with atoum | ||
|
||
This library is using [atoum](https://github.com/atoum/atoum) for unit testing, | ||
whose Composer package can be installed with `dev` mode: | ||
**For more examples and custom utilization, refer to the documentation below.** | ||
|
||
``` | ||
php composer install --dev | ||
bin/atoum -d tests/units | ||
``` | ||
## Documentation and examples | ||
|
||
## Complements | ||
Soon. | ||
|
||
### Create Apple SSL certificate | ||
## Todo | ||
|
||
Getting the certificates in place. Reach for your mac and start doing the following: | ||
* Add new features | ||
* Add new adapters (like Blackberry and Windows phones) | ||
* Write more documentation and examples | ||
* Write tests (hum... ASAP!) | ||
|
||
* 1. Login to iPhone Developer Connection Portal and click on App Ids. | ||
* 2. Create an AppId for your application withouth a wildcard. It should be something like this: **com.vxtindia.PushSample**. | ||
* 3. Click on configure and then go ahead and create a certificate for Push Notifications. Download it once it has been created. | ||
* 4. Import the newly created certificate into your keychain by double clicking it. | ||
* 5. Launch "Keychain Assistant" and filter it by the Certificate's category. Then you should see a "Apple Development Push Services" option. Expand it, right click on it, click on "Export..." and save this as **apns-dev-cert.p12**. Also download the private key as **apns-dev-key.p12**. | ||
* 6. Copy **apns-dev-cert.p12** file to your server source code folder. | ||
* 7. Now run `openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12` and `openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev-key.p12` on your server. | ||
* 8. From Ubuntu-9.04 server, we had to remove the passphrase, which can be done with `openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem`. | ||
* 9. Finally, combine the two to get your **apns-dev.pem file**: `cat apns-dev-cert.pem apns-dev-key-noenc.pem > apns-dev.pem`. | ||
## 1.x users | ||
|
||
Source: [http://vxtindia.com/blog/push-notifications-for-your-iphone-app-with-php-and-ubuntu/](http://vxtindia.com/blog/push-notifications-for-your-iphone-app-with-php-and-ubuntu/) | ||
Old version is still available from [1.x branch](https://github.com/Ph3nol/NotificationPusher/tree/1.x), with dedicated declared tags. | ||
|
||
### Create a Google account project ID and API key | ||
Just base your Composer package version on `1.x` like this: | ||
|
||
* 1. Go on [https://code.google.com/apis/console](Google APIs console dashboard) | ||
* 2. Create a new projet | ||
* 3. You are now on your new project homepage, with a URL like `https://code.google.com/apis/console/#project:123456789012`. `123456789012` is your application ID. | ||
* 4. Click "Api Access" tab to obtain your API key | ||
``` | ||
"sly/notification-pusher": "1.x" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Sly\NotificationPusher\Adapter; | ||
|
||
use Sly\NotificationPusher\Model\Push; | ||
|
||
/** | ||
* AdapterInterface. | ||
* | ||
* @author Cédric Dugat <cedric@dugat.me> | ||
*/ | ||
interface AdapterInterface | ||
{ | ||
/** | ||
* Push. | ||
* | ||
* @return \Sly\NotificationPusher\Collection\DeviceCollection | ||
*/ | ||
public function push(Push $push); | ||
|
||
/** | ||
* Supports. | ||
* | ||
* @param string $token Token | ||
* | ||
* @return boolean | ||
*/ | ||
public function supports($token); | ||
|
||
/** | ||
* Get default parameters. | ||
* | ||
* @return array | ||
*/ | ||
public function getDefaultParameters(); | ||
|
||
/** | ||
* Get required parameters. | ||
* | ||
* @return array | ||
*/ | ||
public function getRequiredParameters(); | ||
} |
Oops, something went wrong.