call the google fcm HTTP v1 API to send a group push to Android devices and receive 411. Http header does not have a content-length error, but I specified content-length in curl.
$topic = "topic";
$projectId = "projectid";
$title = "hahaha";
$content = "lol";
$payload = array(
"message" => array(
"topic" => $topic,
"notification" => array(
"title" => $title,
"body" => $content,
)
)
);
$json = json_encode(trim($payload));
$headers = array(
"Authorization:Bearer ".$this->getFcmApiAccessToken(),
"Content-Type: application/json; UTF-8",
"Content-length:".strlen($json),//"Content-length:0"
);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"https://fcm.googleapis.com/v1/projects/{$projectId}/messages:send");
curl_setopt($ch,CURLOPT_POST, true );
curl_setopt($ch,CURLOPT_HEADER, 1);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch,CURLOPT_POSTFIELDS, $json);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
var_dump($result);exit;