阅读我的服务器的示例代码后:
// Replace with real BROWSER API key from Google APIs
$apiKey = "123456";
// Replace with real client registration IDs
$registrationIDs = array( "123", "456" );
// Message to be sent
$message = "x";
// 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 ) );
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
需要知道服务器的registration_ids才能推送信息。
如何从我的个人服务器获取 GCM 服务器中的注册设备列表(registration_ids)。
如何向 GCM 中注册的所有设备发送广播消息。
谢谢 !