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;
}