Php 使用Kreait的Firebase推送通知

Php 使用Kreait的Firebase推送通知,php,json,firebase,firebase-cloud-messaging,Php,Json,Firebase,Firebase Cloud Messaging,我正在使用Kreait发送firebase推送通知。我成功地实现了它,但每次我尝试发送请求时,我都会收到一个404 url不存在的错误(客户端错误:POSThttps://fcm.googleapis.com/v1/projects/project-id/messages:send导致“404未找到”)。我的google认证json文件与php文件位于同一目录中 代码: 使用->withDatabaseUri('https://INSERT_YOUR_PROJECT_ID_HERE.fireba

我正在使用Kreait发送firebase推送通知。我成功地实现了它,但每次我尝试发送请求时,我都会收到一个404 url不存在的错误(客户端错误:
POSThttps://fcm.googleapis.com/v1/projects/project-id/messages:send
导致“404未找到”)。我的google认证json文件与php文件位于同一目录中

代码:


使用
->withDatabaseUri('https://INSERT_YOUR_PROJECT_ID_HERE.firebaseio.com)
。。。虽然看起来,
\uu DIR\uu.'/google.json'
(通常称为
google services.json
)很可能不存在,因此项目URL将是未知的。在任何情况下,URL中的
projectid
都必须替换为实际的
project\u id
。。。如果(!file_exists(uu DIR_u.'/google.json'){die('config缺席');}?

仍然不起作用,可以使用
检查该文件是否存在。我的文件命名为so
project-id-firebase-adminsdk-qum3e-5ee10de5e7.json
。我还可以检查什么?@AbdulMirza使用
\uuuuu DIR\uuuuuuuuuuu.'/project-id-firebase-adminsdk-qum3e-5ee10de5e7.json'
,或者简单地将该文件重命名为
\uuuuu DIR\uuuuuuuuuuuuuuuuuuuu.'./google.json'
-实际的
项目id
也将包含在该文件中,无论其文件名如何。我使用的是project-id-firebase-adminsdk-qum3e-qum3e-5ee10de5e5e。在我的示例代码中,出于安全原因,我没有编写文件名。但我向你保证,我是这样做的。
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google.json');

$firebase = (new Factory)
        ->withServiceAccount($serviceAccount)
        // The following line is optional if the project id in your credentials file
        // is identical to the subdomain of your Firebase project. If you need it,
        // make sure to replace the URL with the URL of your project.
        //->withDatabaseUri('https://my-project.firebaseio.com')
        ->create();

$messaging = $firebase->getMessaging();

$deviceToken = 'token';

$notification = Notification::create("test", "body");
$data = [
   'first_key' => 'First Value',
   'second_key' => 'Second Value',
];

$message = CloudMessage::withTarget('token', $deviceToken)
     ->withNotification($notification) // optional
     ->withData($data);

// error here
// 404 Client error: `POST https://fcm.googleapis.com/v1/projects/projectid/messages:send` resulted in a `404 Not Found
$messaging->send($message);