Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunnyluthra/760a8588464dfb5afd91 to your computer and use it in GitHub Desktop.
Save sunnyluthra/760a8588464dfb5afd91 to your computer and use it in GitHub Desktop.
verify_android_push_notification_token.php
function verify_notification_token($token) {
$fields = array(
'dry_run' => true,
'to' => $token,
);
$headers = array(
'Authorization: key=' . GOOGLE_API_SERVER_KEY,
'Content-Type: application/json',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, GOOGLE_API_PUSH_URL);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result);
//Success
//([multicast_id] => -1
// [success] => 1
// [failure] => 0
// [canonical_ids] => 0
// [results] => Array
// (
// [0] => stdClass Object
// (
// [message_id] => fake_message_id
// )
// )
// )
if($result->success === 1){
return true;
}else{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment