Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sunnyluthra/760a8588464dfb5afd91 to your computer and use it in GitHub Desktop.
Save sunnyluthra/760a8588464dfb5afd91 to your computer and use it in GitHub Desktop.

Revisions

  1. sunnyluthra created this gist Aug 25, 2015.
    39 changes: 39 additions & 0 deletions verify_android_push_notification_token.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    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;
    }
    }