我已经浏览了 Github,但找不到任何相关的类或文档。
https://github.com/google/google-api-php-client-services/tree/master/src/Google/Service
我正在尝试从服务器向 Web 客户端发送 FCM 消息。以下是我目前如何实现这一目标。
<?php
header('Content-Type: text/json');
$data = array(
'message' => array(
'notification' => array(
'title' => 'FCM Message',
'body' => 'This is an FCM Message',
)
)
);
$server_key = 'ya29.ElqKBGN2Ri_Uz...HnS_uNreA';
$url = 'https://fcm.googleapis.com/fcm/send';
$headers = 'Authorization:key = '.$firebase_api_key."\r\n".'Content-Type: application/json'."\r\n".'Accept: application/json'."\r\n";
$registration_ids = array('bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...');
$fields = array('registration_ids' => $registration_ids, 'data' => $data);
$content = json_encode($fields);
$context = array('http' => array( 'method' => 'POST', 'header' => $headers, 'content' => $content));
$context = stream_context_create($context);
$response = …
Run Code Online (Sandbox Code Playgroud)