ph3nol / notificationpusher Goto Github PK
View Code? Open in Web Editor NEWStandalone PHP library for easy devices notifications push.
License: MIT License
Standalone PHP library for easy devices notifications push.
License: MIT License
In my case gcm token includes ":" (colon symbol) and I have error Adapter Gcm does not support ... token's device. I think regular expression should be changed
public function supports($token)
{
return (bool) preg_match('/^[0-9a-zA-Z\-\_]+$/i', $token);
}
I did successfully send a push notification to my device in production mode. I wanted to check feedback data, if I uninstalled the app. Now I uninstalled it, and installed another push enabling app (as suggested to update the APNS feedback server).
Now when I send the push, it is successfully delivered, but I have not received any feedback. The getFeedback()
is empty.
This is my code (simplified):
$pushManager = new PushManager('prod');
$push = new Push($the_adapter, new Device('my device token'), new Message('Some message', $options));
$pushManager->add($push);
$pushManager->push();
exit(var_dump($pushManager->getFeedback($the_adapter))); // no feedback recieved
UPDATE:
Even trying this with an invalid token returns no feedback
Hi, can I ask how can I implement this NotificationPusher, Is there running example for this so that I can see in action or video tutorial for this.
Thank you in advance.
Hi,
i have a problem when sending push notifications via the ios adapter.
The notification i'm sending is received but the request never get's finished so that it freezes all other outgoing notifications in the same process.
I cant find any thing in the logs. I'm just wondering if any other is having a similar issue?
I'm using both gcm and ios adapter.
What about using PSR-4 autoloading instead of PSR-0?
In both Apns::getServiceMessageFromOrigin and Gcm::getServiceMessageFromOrigin you are using MessageInterface
as the typehint, but MessageInterface
does not have the methods hasOption
or getOption
; those are only present in BaseOptionedModel so the type hint should be changed, i.e:
public function getServiceMessageFromOrigin(array $tokens, BaseOptionedModel $message)
PHP doesn't complain as type hints are only validated at runtime and it just works by accident since the only implementation of MessageInterface
is Message
, which happens to extend BaseOptionedModel
.
So can you please change the typehints to BaseOptionedModel
? Thanks :)
It seems that my push notifications are always sent to gateway.push.apple.com
despite setting the environment to prod
. I discovered this by dumping the result of $pushManager->push().
However I am unable to see where in this NotificationPusher that it decides whether to connect to the sandbox or other. Could you please provide some insight?
I wonder if anyone has already spent time to write a working windows phone 8 adapter and would share it :)? Besides, this class collection is simply awesome. Great work!
GCM allow to send notification to ios devices but need to add notification key intead of data or just use both, theres is a way to extend the ZendService\Google\Gcm\Message and override the toJson method.
Or another walk around
It appears as if NotificationPusher is not in fact standalone, but is dependent upon several other components (a complete list of which appears to be present on NotificationPusher's Packagist listing). Is there a reason these dependencies are not listed in the "Requirements" section of the readme?
This was rather confusing when I first realized it.
When running the CLI script in a Laravel site this error occurs:
PHP Fatal error: Class 'Doctrine\Common\Util\Inflector' not found in /../vendor/sly/notification-pusher/src/Sly/NotificationPusher/Console/Command/PushCommand.php on line 139
Hi,
I'm trying to use this library but I have the error in object.
I copied the folder Sly in the root, I copied the composer.json file and I launched composer update, then I made a simple page with
require_once 'vendor/autoload.php';
use Sly\NotificationPusher\PushManager,
Sly\NotificationPusher\Adapter\Gcm as GcmAdapter,
Sly\NotificationPusher\Collection\DeviceCollection,
Sly\NotificationPusher\Model\Device,
Sly\NotificationPusher\Model\Message,
Sly\NotificationPusher\Model\Push
;
// First, instantiate the manager.
//
// Example for production environment:
// $pushManager = new PushManager(PushManager::ENVIRONMENT_PROD);
//
// Development one by default (without argument).
$pushManager = new PushManager(PushManager::ENVIRONMENT_DEV);
and here I have the error
Fatal error: Class 'Sly\NotificationPusher\PushManager' not found in /home/mumble/push-notification/gcm.php on line 19
that is the last line I pasted here.
Can someone suggest me anything?
Thanks
Hi,
It is working if I use has separate instance. When I integrate with my application which is built on symfony 1.4 it is giving fatal error.
PHP Fatal error: Class 'Zend\Http\Header\AbstractLocation' not found in symfony/lib/vendor/NotificationPusher/vendor/zendframework/zend-http/src/Header/Location.php on line 18
PHP Fatal error: Call to a member function evictAll() on a non-object in on a non-object in symfony/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php on line 1239
This is the critical issue.
I guess at the moment after each push, the connection is closed. Is it possible to implement some kind of batch functionality where the connection is only closed when all messages are sent?
as you can see in http://gcm-client.readthedocs.org/en/latest/intro.html
there is different result on response
can we get this on information by using this notification pusher package
There is no option to send a "custom payload" with the push notification as documented in by apple here:
Proposal:
For Apple's push notification service which uses a certificate, the certificate might be created with an passphrase. It would be nice to allow for making the library work in these cases by supplying an additional config option for certificate_passphrase.
I have already fixed this in my local branch and if there's interest for it it would be nice if it could be merged into this codebase. Let me know if you want me to make a pull request or share the relevant parts of the code.
I'm having trouble pushing APNS messages to devices. The pushes do show up, almost instantly, on the device. However the request that processes the sending exceeds in execution time.
This is a problem because i'm using queues and the queue will think the task has failed since it got a 500 and will retry.
I've inspected the code and perhaps this could have something to do with the ServiceClient
object. https://github.com/Ph3nol/NotificationPusher/blob/master/src/Sly/NotificationPusher/Adapter/Apns.php#L59
Or maybe I'm just doing something wrong. I am using Google App Engine.
Here is my code.
...
function __construct()
{
$environment = Config::get('push.apns.environment') == 'development' ? PushManager::ENVIRONMENT_DEV : PushManager::ENVIRONMENT_PROD;
$this->pushManager = new PushManager($environment);
$this->apnsAdapter = new ApnsAdapter([
'certificate' => Config::get('push.apns.certificate'),
'passPhrase' => Config::get('push.apns.passPhrase')
]);
}
/**
* Handle the command
*
* @param SendApnsNotificationCommand $command
* @return mixed
*/
public function handle($command)
{
$devices = $this->deviceCollectionForRecipients($command->recipients);
$message = new PushMessage($command->message, array(
'badge' => '+1'
));
Log::info('Sending push notification: "' . $command->message . '" to '. iterator_count($devices) .' device(s): ' . $this->stringForDeviceCollection($devices));
$push = new Push($this->apnsAdapter, $devices, $message);
$this->pushManager->add($push);
$result = $this->pushManager->push();
Log::info('Notifications sent');
return $result;
}
...
My log. The Notifications sent
log message is never reached.
10:55:28.875 production.INFO: Executing Clickin\ApnsTokens\SendApnsNotificationCommand on queue. [] []
10:55:28.976 production.INFO: Sending push notification: "Xander: Testerdietest" to 1 device(s): "17a0eed527d2471e1fd95af92b5716aa5d1ea8bc6e52098c048bf412f3771d4c", [] []
10:56:29.449 PHP Fatal error: The request was aborted because it exceeded the maximum execution time. in /base/data/home/apps/s~clickin-c1/one.378213990390859398/vendor/laravel/framework/src/Illuminate/Exception/Handler.php on line 130
10:56:29.449 PHP Fatal error: The request was aborted because it exceeded the maximum execution time. in /base/data/home/apps/s~clickin-c1/one.378213990390859398/vendor/laravel/framework/src/Illuminate/Exception/Handler.php on line 180
When I run simple code to do a push notification via iOS I get this error:
ErrorException in AbstractClient.php line 102:
Failed to enable crypto
Push.php:
PushNotification::app('test')->to($deviceToken)->send('test')
Settings.php:
return array(
'test' => array(
'environment' => 'development',
'certificate' => base_path() . '/cert.pem',
'passPhrase' => env('CERT_PASS'),
'service' => 'apns'
)
);
I am running this on Laravel Forge with hhvm installed. I think the problem is facebook/hhvm#1647 but I am not too sure.
The error says its here:
at stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', '0', '', '60', '4', resource) in AbstractClient.php line 102
Everytime I try to push notification to android I receive this issue
[Mon Jul 14 09:14:28.373673 2014] [:error] [pid 2829] [client 197.207.74.200:14763] PHP Fatal error: Uncaught exception 'ErrorException' with message 'stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:\nerror:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed' in /var/www/html/v2/vendor/zendframework/zend-http/Zend/Http/Client/Adapter/Socket.php:283\nStack trace:\n#0 [internal function]: Zend\\Stdlib\\ErrorHandler::addError(2, 'stream_socket_e...', '/var/www/html/v...', 283, Array)\n#1 /var/www/html/v2/vendor/zendframework/zend-http/Zend/Http/Client/Adapter/Socket.php(283): stream_socket_enable_crypto(Resource id #5, true, 2)\n#2 /var/www/html/v2/vendor/zendframework/zend-http/Zend/Http/Client.php(1358): Zend\\Http\\Client\\Adapter\\Socket->connect('android.googlea...', 443, true)\n#3 /var/www/html/v2/vendor/zendframework/zend-http/Zend/Http/Client.php(878): Zend\\Http\\Client->doRequest(Object(Zend\\Uri\\Http), 'POST', true, Array, '{"registration_...')\n#4 /var/www/html/v2/vendor/zendframework/zendservice-google-gcm/library/ZendService/Google/Gcm/Client.php(114 in /var/www/html/v2/vendor/zendframework/zend-http/Zend/Http/Client/Adapter/Socket.php on line 310
Some people does not seems to get the pushes, even though that the status of the push model is sent
.
Any ideas how to debug this to figure out the where the issue is?
NOTE: Most of the people not getting the push message seems to be on iOS.
PHP Fatal error: Class 'Doctrine\Common\Util\Inflector' not found in /../vendor/sly/notification-pusher/src/Sly/NotificationPusher/Console/Command/PushCommand.php on line 139.
Could you change namespace in PushCommand.php to actual. At now actual is "Doctrine\Common\Inflector\Inflector"
Hi,
the method setAdapterParameters in the Gcm Adapter class does actually nothing, because the httpClient variable is not used in the getOpenedClient Function.
It would be nice if you could fix this, so that getOpenedClient Function takes the httpclient variable if set or otherwise create a new httpclient.
Many thanks.
Hi, there is one issue about google cloud messaging. i had found that the message cannot be displayed if the data parameters: [contentTitle], [contentText] and [tickerText] are missed. After i hard code something to the data array at [email protected], it works normally.
Hi,
I am trying to send push notification to iOS Device. certificate.pem file is correct.
I have created a route to send out a notification to IOS device. But when i am trying to call the function, its throwing me: -
local.ERROR: exception 'Sly\NotificationPusher\Exception\AdapterException' with message 'Adapter Apns does not support XXXX token's device' in /private/var/www/pattypets/vendor/sly/notification-pusher/src/Sly/NotificationPusher/Model/Push.php:90
Please see:- Its working well and good in android.
When Trying to call the push()
method on an instance of the PushManager Class I am getting the following error:
Fatal error: Class 'ZendService\Apple\Exception\RuntimeException' not found in PROJECTDIR/vendor/zendframework/zendservice-apple-apns/library/ZendService/Apple/Apns/Client/AbstractClient.php on line 105
Hi,
Is there an easy way to wire in logging (monolog or similar)?
Thanks,
I am sending push notifications to my Android (and it works), but I get the following error:
Error message:
Fatal error: Cannot access private property Sly\NotificationPusher\Collection\DeviceCollection::$coll in %my_repo%/vendor/sly/notification-pusher/src/Sly/NotificationPusher/Collection/AbstractCollection.php on line 31
The error happens right after sending the message, in https://github.com/Ph3nol/NotificationPusher/blob/master/src/Sly/NotificationPusher/Adapter/Gcm.php#L60
Hello again, I'm having another problem, is that I think the message text is not sent in Android notifications, I could not try on Ios.
In function getServiceMessageFromOrigin() just getting options and not text
Hello,
I tried first time your library and it works! But I needed to modify a file in used zend framework to get it work. The problem is the following error message:
Zend\Http\Client\Adapter\Exception\RuntimeException: Unable to enable crypto on TCP connection android.googleapis.com: make sure the "sslcapath" option points to a valid SSL certificate directory in /.../vendor/zendframework/zend-http/Zend/Http/Client/Adapter/Socket.php on line 299
The $config attribute of this socket class has the default value null
for the option sslcapath
. And there is no way to edit this option without changing the code itself.
So it would be nice if you would add such a possibility.
Thanks in advance,
Armin.
This is related to this ZF2 bug: zendframework/zendframework#2535
As a workaround, I have modified getOpenedClient
in Sly\NotificationPusher\Adapter\Gcm.php
like this:
public function getOpenedClient(ServiceClient $client)
{
$client->setApiKey($this->getParameter('apiKey'));
$c = new \Zend\Http\Client(null, array(
'adapter' => 'Zend\Http\Client\Adapter\Socket',
'sslverifypeer' => false
));
$client->setHttpClient($c);
return $client;
}
This bypasses the certificate verification and everything works fine. However doing this cleanly (maybe with a setHttpClient
method in BaseAdapter
?) would be much better.
I experienced the fact that notifications are not received by devices that are off or not connected on a network (e.g. airplane mode). It seems that Apple provide an "expiricy" param that is not set here.
In sly/notification-pusher/src/Sly/NotificationPusher/Apns.php (line 166) I tried to add the following line:
$serviceMessage->setExpire(time() + 60_60_24_7_2); //expire in two weeks
And the issue seems to be fixed.
Hi there,
I am on laravel 4.2 and I just followed the installation docs here https://github.com/Ph3nol/NotificationPusher/blob/master/doc/installation.md
It installed well but I ran into the error:
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)
Class 'PushManager' not found
when I ran the /push route as below:
Route::get('push', function(){
// First, instantiate the manager and declare an adapter.
$pushManager = new PushManager();
$exampleAdapter = new ApnsAdapter();
// Set the device(s) to push the notification to.
$devices = new DeviceCollection(array(
new Device('Token1'),
new Device('Token2'),
new Device('Token3'),
// ...
));
// Then, create the push skel.
$message = new Message('This is an example.');
// Finally, create and add the push to the manager, and push it!
$push = new Push($exampleAdapter, $devices, $message);
$pushManager->add($push);
return $pushManager->push();
});
Could I be missing a step? (perhaps declaring a provider or alias in my app.php)
When using the Sly\NotificationPusher\Adapter\Apns to send a Sly\NotificationPusher\Model\Message, there's no option to set the aps category, although the ZendService\Apple\Apns\Message supports this attribute.
Hello,
When sending a push notification, it works fine on iOS but on Android, the name of the app is not showing up, only the message, why is this happening ?
$pushManager = new PushManager(PushManager::ENVIRONMENT_PROD);
//
// Development one by default (without argument).
// $pushManager = new PushManager( PushManager::ENVIRONMENT_DEV );
// Set the device(s) to push the notification to.
// Pourquoi 0 ???
$devices = new DeviceCollection( array(
new Device( $friendDevice->getToken() )
));
//Send back where did we send it ?
$platform = $friendDevice->getPlatform();
// Then, create the push skel.
// DO NOT ADD BADGES!!!
$message = new Message( $message, array(
'custom' => array(
'type' => $type,
'id' => $id,
'friendId' => $user->getId(),
'friendName'=> $user->getName(),
'requestId' => $requestId
)
)
);
//IF IOS IF ANDROID
if ( $platform == "iOS" )
{
// Then declare an adapter.
$adapter = new ApnsAdapter( array(
'certificate' => $this->certificate
));
} elseif ( $platform == "android" || $platform == "Android" )
{
// Then declare an adapter.
$adapter = new GcmAdapter(array(
'apiKey' => $this->apiKey,
));
}
// Finally, create and add the push to the manager, and push it!
$push = new Push( $adapter, $devices, $message );
$pushManager->add( $push );
$pushManager->push();````
Thanks
File: sly\notification-pusher\src\Sly\NotificationPusher\Adapter\Gcm.php
Line: 117
Parameters accepted at method getDefinedParameters are 'collapse_key', 'delay_while_idle', 'time_to_live', 'restricted_package_name', 'dry_run', but at getServiceMessageFromOrigin they are wrong
public function getServiceMessageFromOrigin(array $tokens, BaseOptionedModel $message)
{
$data = $message->getOptions();
$data['message'] = $message->getText();
$serviceMessage = new ServiceMessage();
$serviceMessage->setRegistrationIds($tokens);
$serviceMessage->setData($data);
$serviceMessage->setCollapseKey($this->getParameter('collapseKey'));
$serviceMessage->setRestrictedPackageName($this->getParameter('restrictedPackageName'));
$serviceMessage->setDelayWhileIdle($this->getParameter('delayWhileIdle', false));
$serviceMessage->setTimeToLive($this->getParameter('ttl', 600));
$serviceMessage->setDryRun($this->getParameter('dryRun', false));
return $serviceMessage;
}
public function getDefinedParameters()
{
return array(
'collapse_key',
'delay_while_idle',
'time_to_live',
'restricted_package_name',
'dry_run'
);
}
Hello,
I am trying to send 1000+ APNS notifications. When I put my script in test mode and send notifications to just my device it works fine.
However as soon as I try to send a lot of notifications (exact threshold not known) it fails: my phone (and devices from friends) does not get them. I have tried to group those notifications in different sizes (1, 100, 250...) but it fails in all cases.
Is anyone been able to send a lot of APSN notifications with this library?
Is there anyway to understand what is going on?
Thanks,
Nicolas
$push_devices[] = new Device($device_token, array('badge' => 0));
$devices = new DeviceCollection($push_devices);
In GCM adapter, in the push function you chunk the tokens per 100. When you iterate over the chunks, you store the response of the client->send()
in $this->response
, but if someone sends more than 100 tokens you override the response with the new response you receive from the send()
!
If for example I send a message to 110 tokens, you will send the first 100 and store the response, but in the next iteration (next 10 tokens) you will override the previous response with the last 10.
Also you should consider changing the chunk value to 1000 (as this the maximum number of allowed tokens in GCM multicast), to improve the performance. Or even better this value should be passed as an optional argument in the push()
function of the push manager.
Hi!
I'm trying to send message with accents (i.e. "Deutche stadt Köln", "Polskie miasto Łódź") and push notification doesn't appear in ipad/iphone. Without diacritics ("Deutche stadt Koln", "Polskie miasto Lodz") i get the push notification in my phone without any problems.
Please allow developers to remove badge field. For example class ZendService\Apple\Apns\Message accepts badge to be null (then badge is not sent) but you force badge field to be an integer.
Class: Sly\NotificationPusher\Adapter\Apns
Lines: 163- 166
Content of that lines:
$badge = ($message->hasOption('badge'))
? (int) ($message->getOption('badge') + $device->getParameter('badge', 0))
: 0
;
Sample solution:
Hi @Ph3nol,
currently i'm using this library, but if i use badge, but it didn't count or didn't catch the provided badge number in the class init.
'devices' => array(
array('d3v1c3t0k3n1', 0),
array('d3v1c3t0k3n2', 5)
),
i'm adding new param at ApplePusher.php
method getPayloadFromMessage(MessageInterface $message, $badge)
and put this also $payload = $this->getPayloadFromMessage($message, $userBadgeCount);
at getPackedMessageFromGivenToken()
am i doing this right? or am i missing something?
thanks!
Hi, i was testing the new version and i had a problem, my android tokens have 183 characters so i was receiving a AdapterException.
Hi,
When sending the same data using the sync form submit its sending the notification. But same data if I send using the ajax async form submit it won't send the notifications. Why is that so??
After I push a message to a couple of registration IDs, there are some that have an Invalid Registration response from GCM. Is there any way I can extract the registration IDs that are not valid?
Hello,
I am trying to send push notifications to iPhone device, but I think I am stuck on the certificate format : I managed to send manual notifications with a pem file I generated with the following commands :
$ openssl x509 -in aps_development.cer -inform der -out PushChatCert.pem
$ openssl pkcs12 -nocerts -out PushChatKey.pem -in PushChatKey.p12
$ cat PushChatCert.pem PushChatKey.pem > ck.pem
( as seen on : http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1 )
But this don't seems to work with NotificationPusher ?
I have tried with and without a passphrase and with the DEV environment.
NB : I also tried the command from :
https://blog.serverdensity.com/how-to-build-an-apple-push-notification-provider-server-tutorial/
What does NotificationPusher expect ?
Problem 1
- Conclusion: don't install sly/notification-pusher v2.1.2
- Conclusion: don't install sly/notification-pusher v2.1.1
- Conclusion: don't install sly/notification-pusher v2.1.0
- Installation request for doctrine/cache == 1.2.0.0 -> satisfiable by doctrine/cache[v1.2.0].
- Installation request for sly/notification-pusher 2.x -> satisfiable by sly/notification-pusher[v2.0, v2.1.0, v2.1.1, v2.1.2].
- Conclusion: remove symfony/symfony v2.3.6
- sly/notification-pusher v2.0 requires symfony/options-resolver 2.3 -> satisfiable by symfony/symfony[v2.3.0], symfony/options-resolver[v2.3.0].
- Can only install one of: symfony/symfony[v2.3.6, v2.3.0].
- don't install symfony/options-resolver v2.3.0|don't install symfony/symfony v2.3.6
- Installation request for symfony/symfony == 2.3.6.0 -> satisfiable by symfony/symfony[v2.3.6].
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.