सबसे पहले Implementing GCM Client का पालन करें और अपने एंड्रॉइड ऐप में जीसीएम क्लाइंट को लागू करें।
जीपीएम सर्वर के लिए PHP में आप इसे निम्न तरीके से कार्यान्वित कर सकते हैं। पोस्ट को प्रकाशित करते समय कोड की तरह अपनी आवश्यकता के अनुसार अपना कोड संपादित करें। GCM सर्वर को लागू करने के बारे में अधिक जानकारी के लिए जाना Implementing GCM Server
<?php
// Replace with the real server API key from Google APIs
$apiKey = "your api key";
// Replace with the real client registration IDs
$registrationIDs = array("reg id1","reg id2");
// Message to be sent
$message = "Your message e.g. the title of post";
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array("message" => $message),
);
$headers = array(
'Authorization: key=' . $apiKey,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the URL, number of POST vars, POST data
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, json_encode($fields));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($ch, CURLOPT_POST, true);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
// print the result if you really need to print else neglate thi
echo $result;
//print_r($result);
//var_dump($result);
?>
को भी शुरुआती के लिए एक अच्छा पोस्ट Android Push Notifications नहीं है।
स्रोत
2015-08-20 04:28:46
यहाँ आप कर रहे हैं [GitHub पर Google क्लाउड संदेश सेवा] (https://github.com/google/gcm के लिए उत्तर पोस्ट का फैसला किया है) – BNK