Skip to content

Instantly share code, notes, and snippets.

@benigumocom
Created August 21, 2012 18:31
Show Gist options
  • Save benigumocom/3418190 to your computer and use it in GitHub Desktop.
Save benigumocom/3418190 to your computer and use it in GitHub Desktop.
PHPでGCMに投げる(PHP5 native)
<?php
define('API_KEY', 'your-api_key');
define('GOOGLE_URL', 'https://android.googleapis.com/gcm/send');
//$regId = 'your_registration_id';
$regId = trim(file_get_contents('register.txt'));
$data = array('registration_id' => $regId,
'collapse_key' => 'update',
'data.message' => 'Hello, GCM');
$data = http_build_query($data, '', '&');
$header = array('Content-Type: application/x-www-form-urlencoded;charset=UTF-8',
'Authorization: key=' . API_KEY,
'Content-Length: ' . strlen($data));
$context = array(/**/'http'/**/ => array('method' => 'POST',
'header' => implode("\r\n", $header),
'content' => $data));
$response_body = file_get_contents(GOOGLE_URL, false, stream_context_create($context));
var_dump($context);
var_dump($http_response_header);
var_dump($response_body);
@brexis
Copy link

brexis commented Oct 17, 2014

Nice. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment