Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php firebase推送通知成功响应但未显示_Php_Firebase_Push Notification_Firebase Cloud Messaging - Fatal编程技术网

php firebase推送通知成功响应但未显示

php firebase推送通知成功响应但未显示,php,firebase,push-notification,firebase-cloud-messaging,Php,Firebase,Push Notification,Firebase Cloud Messaging,我使用PHP cURL作为iOS应用程序上推送通知的触发器。来自FCM端点的响应返回消息ID,我认为这是成功的,但设备上没有显示通知 当我尝试从云消息页面手动发送通知时,我可以在设备上接收通知 这就是我试图从PHP发送通知的方式。我正在使用firebase文档中的HTTP v1 API <?php $accessToken = 'ya29.this-is-the-oAuth-access-token'; $token = 'this-is-the-device-token'; $ur

我使用PHP cURL作为iOS应用程序上推送通知的触发器。来自FCM端点的响应返回消息ID,我认为这是成功的,但设备上没有显示通知

当我尝试从云消息页面手动发送通知时,我可以在设备上接收通知

这就是我试图从PHP发送通知的方式。我正在使用firebase文档中的HTTP v1 API

<?php

$accessToken = 'ya29.this-is-the-oAuth-access-token';

$token = 'this-is-the-device-token';

$url = 'https://fcm.googleapis.com/v1/projects/my-project-id/messages:send';

$notif = array(
    'title' => 'Test notification',
    'body' => 'Sample notification from FCM',
    'image' => "https://my-domain.com/images/favicon.png",
);

$fields = json_encode(['message' => ['token' => $token,'notification' => $notif]]);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($fields));

$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: Bearer '.$accessToken;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}else{
    echo $result;
}
curl_close($ch);

?>