Send Notification in php:
It's very easy way to send notification to a android phone in php.
Firstly we have to register on Google Cloud Messaging using its steps.
You'll get a api key due do doing all the steps.
One more thing you have to do , just find your device token of your android phone and that's it. Use the following code and you'll get a sure notification
$ids = array($deviceToken);
$apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$url = 'https://android.googleapis.com/gcm/send';
$message = json_encode(
array(
'registration_ids' => $ids,
'data' => $sendData
)
);
$headers = array(
'Authorization: key=' . $apiKey,
'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_POSTFIELDS, $message);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'GCM error: ' . curl_error($ch);
}
curl_close($ch);
Thanks
It's very easy way to send notification to a android phone in php.
Firstly we have to register on Google Cloud Messaging using its steps.
You'll get a api key due do doing all the steps.
One more thing you have to do , just find your device token of your android phone and that's it. Use the following code and you'll get a sure notification
$ids = array($deviceToken);
$apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$url = 'https://android.googleapis.com/gcm/send';
$message = json_encode(
array(
'registration_ids' => $ids,
'data' => $sendData
)
);
$headers = array(
'Authorization: key=' . $apiKey,
'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_POSTFIELDS, $message);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'GCM error: ' . curl_error($ch);
}
curl_close($ch);
Thanks
No comments:
Post a Comment