调用google fcm HTTP v1接口给安卓设备群发推送收到411错误
调用google fcm HTTP v1接口给安卓设备群发推送收到411, http header不带content-length错误,但是我在curl里指定了content-length了呀。
$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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$this->getFcmApiAccessToken(),可以看你这里怎么获取token的吗?