I am sending android push notifications using php (curl). Below is my class that sends the notification.
public function send_notification($registatoin_ids, $message)
{
include_once 'config.php';
$url = 'https://android.googleapis.com/gcm/send';
//issue here
$fields = array('registration_ids' => $registatoin_ids, 'data' => $message);
$headers = array('Authorization: key=' . GOOGLE_API_KEY, 'Content-Type: application/json');
$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_RETURNTRANSFER, true);
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($ch));
}
Like this I am able to send the message to the desired recipient and I am succeeding. However, I can only send messages like this.
Suppose I want to send additional information, such as a link of a site, or other data that won't be attached to the message.
Where would I add that ?
Are 'registration_ids' and 'data' unique values ?
androids documentation does not include php example.