Ionic Push php Problem


#1

Hello,

i looking for a php backend, i found a working nodejs push sender but now i need one in php. i have already try some of the codes here on the forum but i cant get them to work. can someone send me a working source.

the one thats is working in nodejs: Trying to reach Ionic Push Api with Node.js (Android)

i also try to change it to build it in php but with not luck.

i hope someone can help me :grin:


#2

Try pushbots its free for the first 1.5 million pushs and I found it easy to get working. The only thing is on Android you have to go to /platforms/android/res/values/pushbots.xml and update that(its not mentioned in there documentation).


#3

I have found a way to do it in php.
for those how need this:

$data = array( "tokens" => array($device_token), "notification" => array( "alert" => "test") ); $url = 'https://push.ionic.io/api/v1/push'; $data_string = json_encode($data); $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_USERPWD, "Private key" . ":" ); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'X-Ionic-Application-Id: AppId' )); $result = curl_exec($ch); curl_close($ch);


#4

I have created a simple library that allows you to consume the Ionic Cloud API for sending push notifications (normal and scheduled), get a paginated list of sending push notifications, get information of registered devices, remove registered devices by token, …

This library requires PHP 5.1+ and cURL.


Installation:

composer require tomloprod/ionic-push-php

Simple usage:

$ionicPush = new IonicPush($ionicProfile, $ionicAPIToken);

$ionicPush->setConfig([
    "title" => "Your notification title",
    "tickerText" => "Your ticker text",
    "message" => "Your notification message. Bla, bla, bla, bla.",
    "android" => [
        "tag" => "YourTagIfYouNeedIt"
    ],
    "ios" => [
        "priority" => 10
    ]
]);

You can also pass custom data to the notification:

$ionicPush->setPayload([ 
    "myCustomField" => "This is the content of my customField",
    "anotherCustomField" => "More custom content"
]);

And send to the indicated devices:

$ionicPush->sendPush([$desiredToken1, $desiredToken2, $desiredToken3]);

Or send this to all registered devices:

$ionicPush->sendPushAll();

You can read more about this library here: https://github.com/tomloprod/ionic-push-php