Created
August 21, 2012 18:31
-
-
Save benigumocom/3418190 to your computer and use it in GitHub Desktop.
PHPでGCMに投げる(PHP5 native)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
利用登録時にGoogleから発行されるが API_KEY。
Androidアプリ起動時に、ユーザーサーバで取得する $regId。
Nice. Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
コンテキストのスキーム部分ではまる。