2

最近我已经在我的应用程序最近的版本集成了FCM,但我的以前版本的应用程序使用GCM。关于我们是否需要分离为GCM和FCM编写背景cron的任何想法?Pushnotification服务器端执行

我的以前的版本我的应用程序4.0,并使用GCM和当前版本我的应用程序4.1并集成了FCM。我想为版本和用户发送推送通知。那么我们是否需要为GCM和FCM编写服务器端程序?关于这种整合的任何想法。

FCM服务器端API:https://fcm.googleapis.com/fcm/send GCM服务器端API:https://android.googleapis.com/gcm/send

任何其他possiblies可我们发送通过FCM服务器端程序的通知?或者单独编写GCM和FCM的程序?在PHP

<?php 

function sendFCM($mess,$id) { 
$url = 'https://fcm.googleapis.com/fcm/send'; 
$fields = array (
     'to' => $id, 
     'notification' => array (
       "body" => $mess, 
       "title" => "Title", 
       "icon" => "myicon" 
     ) 
); 
$fields = json_encode ($fields); 
$headers = array (
     'Authorization: key=' . "AIzaSyA9vpL9OuX6moOYw-4n3YTSXpoSGQVGnyM", 
     'Content-Type: application/json' 
); 

$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_POST, true); 
curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $fields); 

$result = curl_exec ($ch); 
curl_close ($ch); 
} 

?> 

回答

1

FCM为FCM

示例代码仍与GCM兼容,看到这是它的核心。因此,在发送通知时切换到FCM端点(https://fcm.googleapis.com/fcm/send)应仍适用于具有GCM的应用程序版本。无需编写单独的程序。

0

我已经在我的项目运行的代码,你可以使用谷歌的火力地堡尝试:0​​Firebase Tutorial

   $notification_send ="Message to be sent"; 

       $server_key = '****************************';//Authorization Key 
       $client = new Client(); 
       $client->setApiKey($server_key); 
       $client->injectGuzzleHttpClient(new \GuzzleHttp\Client()); 
       $message = new Message(); 
       $message->setPriority('high'); 
       $message->addRecipient(new Topic('test')); 
       $message 
        ->setNotification(new Notification('Reislivsmessen', $notification_send)) 
        ->setData(['key' => 'value']); 

       $response = $client->send($message); 

你必须制造话题,在这里它的“测试”。

我希望它也适合你。