भेजा जा रहा है पुश अधिसूचना में ही है। बस अपने पंजीकृत सर्वर के सभी पंजीकृत डिवाइस के पंजीकरण टोकन को स्टोर करें। और कर्ल के साथ पुश अधिसूचना को कॉल करते समय (मुझे लगता है कि आप सर्वर पक्ष के रूप में php का उपयोग कर रहे हैं) सभी पंजीकरण आईडी को सरणी में रखें। यह एक नमूना कोड
<?php
//Define your GCM server key here
define('API_ACCESS_KEY', 'your server api key');
//Function to send push notification to all
function sendToAll($message)
{
$db = new DbOperation();
$tokens = $db->getAllToken();
$regTokens = array();
while($row = $tokens->fetch_assoc()){
array_push($regTokens,$row['token']);
}
sendNotification($regTokens,$message);
}
//function to send push notification to an individual
function sendToOne($email,$message){
$db = new DbOperation();
$token = $db->getIndividualToken($email);
sendNotification(array($token),$message);
}
//This function will actually send the notification
function sendNotification($registrationIds, $message)
{
$msg = array
(
'message' => $message,
'title' => 'Android Push Notification using Google Cloud Messaging',
'subtitle' => 'www.simplifiedcoding.net',
'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
'vibrate' => 1,
'sound' => 1,
'largeIcon' => 'large_icon',
'smallIcon' => 'small_icon'
);
$fields = array
(
'registration_ids' => $registrationIds,
'data' => $msg
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://android.googleapis.com/gcm/send');
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);
curl_close($ch);
$res = json_decode($result);
$flag = $res->success;
if($flag >= 1){
header('Location: index.php?success');
}else{
header('Location: index.php?failure');
}
}
ऊपर कोड हम mysql तालिका से पंजीकरण टोकन फ़ेच कर रहे हैं में है। सभी उपकरणों को भेजने के लिए हमें सभी टोकन की आवश्यकता है। और एक व्यक्तिगत डिवाइस भेजने के लिए हमें केवल उस डिवाइस के लिए टोकन की आवश्यकता है।
स्रोत: Google Cloud Messaging Example
स्रोत
2016-04-21 15:00:01
के संभावित डुप्लिकेट [वर्ष GCM टोकन एक स्थापना हटाने के बाद भी पर रहते हैं?] (http://stackoverflow.com/questions/17328654/do-old-gcm- टोकन-लाइव-ऑन-भी-बाद-एक-स्थापना रद्द करें) –