PHP GCM appengine

2 views
Skip to first unread message

Manoj Sharma via StackOverflow

unread,
Dec 20, 2014, 5:39:07 AM12/20/14
to google-appengin...@googlegroups.com

This is tested code.

public function sendAndroidPushNotification($registration_ids, $message) { $registrationIds = array($registration_ids); $msg = array( 'message' => $message, 'title' => 'notification center', 'tickerText' => $message, 'vibrate' => 1, 'sound' => 1, );

    $fields = array(
        'registration_ids' => $registrationIds,
        'data' => $msg
    );
    $fields = json_encode($fields);
    $arrContextOptions=array(
        "http" => array(
            "method" => "POST",
            "header" =>
                'Authorization: key = <YOUR_APP_KEY>'. "\r\n" .
                'Content-Type: application/json'. "\r\n",
            "content" => $fields,
        ),
        "ssl"=>array(
            "allow_self_signed"=>true,
            "verify_peer"=>false,
        ),
    );
    $arrContextOptions = stream_context_create($arrContextOptions);
    $result = file_get_contents('https://android.googleapis.com/gcm/send', false, $arrContextOptions);

    return $result;
}


Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/17977712/php-gcm-appengine/27579316#27579316
Reply all
Reply to author
Forward
0 new messages