-4

I want to send android push notification from php. I have created admin in php & mysql when admin approve anything from admin than send notification to user.

closed as off-topic by Mark Kaplun, Pieter Goosen, TheDeadMedic, Sumit, birgire Jun 14 '16 at 17:53

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • This is a question about php, not about WP (even if it maybe is incorporated in some plugin) – cjbj Jun 10 '16 at 9:35
1

Android Push Notification requires you to have GCM Keys and Project ID which needs to be registered on Google Developer console.

I am assuming you are able to get your users registration IDs and stored in a table.

To send Android Push Notification create a function somewhere in your functions file

function AndroidPushNotification($registration_ids, $message) {

$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
    'registration_ids' => $registration_ids,
    'data' => $message,
);

define('GOOGLE_API_KEY', 'YOUR-API-KEYS');

$headers = array(
    'Authorization:key=' . GOOGLE_API_KEY,
    'Content-Type: application/json'
);
echo json_encode($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

$result = curl_exec($ch);
if($result === false)
    die('Curl failed ' . curl_error());

curl_close($ch);
return $result;

}

Fetch all registration IDS from your database and call this function. Break registration IDs into group of 999. Sometimes, if your array has more than 1000 registration IDs, the notifications aren't delivered.

If you subscribers list if very big, you can also look for multi-curl option which will be faster.

Not the answer you're looking for? Browse other questions tagged or ask your own question.