-1
誰能告訴我怎樣才能獲得 「$ registrationIDs =陣列( 」REG ID1「,」 REG ID2 「);」,在下面的代碼中提到,這是張貼在這裏GCM with PHP (Google Cloud Messaging)如何從使用php的客戶端獲取註冊ID?
<?php
// Replace with real server API key from Google APIs
$apiKey = "your api key";
// Replace with real client registration IDs
$registrationIDs = array("reg id1","reg id2");
// Message to be sent
$message = "hi Shailesh";
// 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);
echo $result;
//print_r($result);
//var_dump($result);
?>
非常感謝!我已經解決了這個問題。這是我第一次在這裏寫一篇文章,也是我編碼生活的開始。 – Susheng