I have an app built with cordova and pushplugin, i receive the token from the device then i try to send a notification using a php server with the following code:
require_once 'ApnsPHP/Autoload.php';
// Instantiate a new ApnsPHP_Push object
$push = new ApnsPHP_Push(
ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
'server_certificates.pem'
);
// Set the Root Certificate Autority to verify the Apple remote peer
$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');
// Connect to the Apple Push Notification Service
$push->connect();
// Instantiate a new Message with a single recipient
$message = new ApnsPHP_Message($regid);
// Set a simple welcome text
$message->setText("GELLLOOOOOO !! ");
// Play the default sound
$message->setSound();
// Add the message to the message queue
$push->add($message);
$push->send();
$push->disconnect();
$err = $push->getErrors() ;
echo "<pre>". var_dump($err) . "</pre>" ;
die("{}") ;
this code return no error in $err variable, I have absolutly no clue why this isn't working because it was working fine for a little moment i was able to get notifications on the device with the same code and same certificates and then it just decided to not work anymore.
Related
I am trying to send an (simple test) email when I receive an account.updated call for a custom account from Stripe API. My other webhooks to create charges and inform customers about successful or failed charges work like this, but here I get an error 500 (I can see that in the dashboard of the custom account) and the mail is NOT send, so I am not sure what I am doing wrong here. My code looks like this:
<?php
require_once('vendor/autoload.php');
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey("sk_test_XXXX");
// Retrieve the request's body and parse it as JSON
$input = #file_get_contents("php://input");
$event_json = json_decode($input);
// Verify the event by fetching it from Stripe
$event = \Stripe\Event::retrieve($event_json->id);
// Do something with $event
if ($event->type == 'account.updated') {
// The E-Mail message to send to inform about a succeeded charge
$message = 'test';
// Send the E-Mail
mail('test#example.com', 'We need more info about you!', $message);
}
http_response_code(200); // PHP 5.4 or greater
Thank you for your help!
If you look at your web server's error.log (usually accessible from your hosting control panel or in /var/log/) do you see more detail on what's causing the 500?
Could it be $event = \Stripe\Event::retrieve($event_json->id); failing?
If the event is occurring directly on a connected account, you may also need to pass the account id to retrieve it.
See here for a bit more context,
https://stripe.com/docs/connect/webhooks
The code would be more like:
$event = \Stripe\Event::retrieve(
array("id" => $event_json->id),
array("stripe_account" => $event_json->account));
https://stripe.com/docs/connect/authentication#authentication-via-the-stripe-account-header
My push notifications stopped working with one of the recent updates. When I looked into it more, I discovered that Apple now lets you generate a non-expiring APNs Auth Key that works for both production and test. I have it working with the following node.js script:
var apn = require('apn');
// Set up apn with the APNs Auth Key
var apnProvider = new apn.Provider({
token: {
key: 'apns.p8', // Path to the key p8 file
keyId: '<my key id>', // The Key ID of the p8 file (available at https://developer.apple.com/account/ios/certificate/key)
teamId: '<my team id' // The Team ID of your Apple Developer Account (available at https://developer.apple.com/account/#/membership/)
},
production: false // Set to true if sending a notification to a production iOS app
});
// Enter the device token from the Xcode console
var deviceToken = '<my device token>';
// Prepare a new notification
var notification = new apn.Notification();
// Specify your iOS app's Bundle ID (accessible within the project editor)
notification.topic = '<my bundle id';
// Set expiration to 1 hour from now (in case device is offline)
notification.expiry = Math.floor(Date.now() / 1000) + 3600;
// Set app badge indicator
notification.badge = 3;
// Play ping.aiff sound when the notification is received
notification.sound = 'ping.aiff';
// Display the following message (the actual notification text, supports emoji)
notification.alert = 'This is a test notification \u270C';
// Send any extra payload data with the notification which will be accessible to your app in didReceiveRemoteNotification
notification.payload = {id: 123};
// Actually send the notification
apnProvider.send(notification, deviceToken).then(function(result) {
// Check the result for any failed devices
console.log(result);
process.exit(0)
});
Is there any way to use the new APNs Auth Key with PHP? I can call the node.js script from PHP, using exec("node app.js &", $output);, and it works, but it starts to get ugly. Should PHP still work using the old .pem file approach?
I am trying to send push notification to apple's Passbook application on updation of a coupon, in order to update it in PassBook application on device.
According to apple's passbook documentation I am sending an empty push notification but it is not being received on device. I have tried to send with some text in the push notification but results are same.
I am using this PHP library to send push notification.
Here is my implementation which is being called on coupon update action;
// Adjust to your timezone
date_default_timezone_set('Asia/Karachi');
// Report all PHP errors
error_reporting(-1);
//Instantiate a new ApnsPHP_Push object
$push = new ApnsPHP_Push(
ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION,
base_path().'/config/ios-push-notification-certificates/production/ProductionCertificate.pem'
);
// Set the Provider Certificate passphrase
$push->setProviderCertificatePassphrase('mypassphrase');
// Set the Root Certificate Autority to verify the Apple remote peer
$push->setRootCertificationAuthority(base_path().'/config/ios-push-notification-certificates/entrust_root_certificate.pem');
// Connect to the Apple Push Notification Service
$push->connect();
// Instantiate a new Message with a single recipient
$message = new ApnsPHP_Message('b2ae8b68fff1fbbe957b8b8f703744794d89f09d45f69b2d847a26c3b064e268');
// Set a custom identifier. To get back this identifier use the getCustomIdentifier() method
// over a ApnsPHP_Message object retrieved with the getErrors() message.
$message->setCustomIdentifier("Message-Badge-3");
// Set badge icon to "3"
$message->setBadge(3);
// Set a simple welcome text
$message->setText('');
// Play the default sound
$message->setSound();
// Set a custom property
$message->setCustomProperty('acme2', array('bang', 'whiz'));
// Set another custom property
$message->setCustomProperty('acme3', array('bing', 'bong'));
// Set the expiry value to 30 seconds
$message->setExpiry(30);
// Add the message to the message queue
$push->add($message);
// Send all messages in the message queue
$push->send();
// Disconnect from the Apple Push Notification Service
$push->disconnect();
// Examine the error message container
$aErrorQueue = $push->getErrors();
if (!empty($aErrorQueue)) {
print_r($aErrorQueue);
}
And here is the output printed by the library which show message has been sent. It is not print_r($aErrorQueue); output.
I didn't get why I am unable to update the pass automatically or receive the push notification. It is quite new to me this push notification service. Please guide me if I can debug any thing or try something else. My endpoints for apple server are working fine I can install and update the pass manually from passbook.
Im trying to send push notification to multiple ios device, but when one or more tokens are invalids it crash and not send the message to the other devices, here is my code:
require_once "libs/ApnsPHP/Autoload.php";
$push = new ApnsPHP_Push(ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION,'WenderCastPush.pem');
$pushdevices = array('499D3684-5039-4E56ACB7E285057E8568','21bff83127f8f307b307e828cfe4a65081b7468f980d17f9fbbda05785298c7d');
$push->connect();
foreach ($pushdevices as $device)
{
try{
$message = new ApnsPHP_Message($device);
$message->setCustomIdentifier("Message-Badge-3");
$message->setBadge(3);
$message->setText('Message Alert : Testing IOS');
$message->setSound();
$message->setExpiry(30);
$push->add(#$message);
}
catch(Exception $e)
{}
}
$push->send();
$push->disconnect();
How come you are receiving the device token as invalid ones? Its either the developer who's is sending the token to you via web service is messing it up or there is a prob. at you end . Simple solution to this can be , put a check on device token if its above 32 bytes don't save it .
I have something wrong with my notifications but i can't see where is the problem. I have an app that generates the token successfully, at first I was able to send a notification from my localhost to the device, but after i restored the device and and tested with the new device token to push a simple notification i couldn't get get it to work even though I didn't made any changes to php code nor my app code, here is my php code :
require_once 'ApnsPHP/Autoload.php';
// Instantiate a new ApnsPHP_Push object
$push = new ApnsPHP_Push(
ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
'server_certificates_bundle_sandbox.pem'
);
// Set the Root Certificate Autority to verify the Apple remote peer
$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');
// Connect to the Apple Push Notification Service
$push->connect();
// Instantiate a new Message with a single recipient
$message = new ApnsPHP_Message($token);
// Set a simple welcome text
$message->setText("GELLLOOOOOO");
// Play the default sound
$message->setSound();
// Add the message to the message queue
$push->add($message);
$push->send();
$push->disconnect();
// Examine the error message container
$aErrorQueue = $push->getErrors();
var_dump($aErrorQueue);
I think it have something to do with certificates but i'm not sure where is the issues since it was working before and there is nothing in $aErrorQueue , just an empty array.