问题描述
最近我在我的应用程序最新版本中集成了 FCM,但我以前的应用程序版本使用 GCM.关于我们是否需要为 GCM 和 FCM 分离编写后台 cron 的任何想法?
Recently i have integreted the FCM in my app recent version but my previous version of app was using GCM. Any ideas about whether we need to segregate the write the background cron for GCM and FCM?.
My Previous version MY App 4.0 并使用 GCM 和 Current version My App 4.1 并集成了 FCM.我想为版本和用户发送推送通知.那么我们是否需要为 GCM 和 FCM 编写服务器端程序呢?有关此集成的任何想法.
My Previous version MY App 4.0 and used GCM and Current version My App 4.1 and integrated the FCM. I wants to send the pushnotification for both version and users. So whether we need to write the server side program for GCM and FCM right?. Any ideas about this integration.
FCM 服务器端 API:https://fcm.googleapis.com/fcm/sendGCM 服务器端 API:https://android.googleapis.com/gcm/send
FCM Server Side API : https://fcm.googleapis.com/fcm/send GCM Server Side API : https://android.googleapis.com/gcm/send
我们可以通过 FCM 服务器端程序发送通知吗?还是需要分别为 GCM 和 FCM 编写程序?
Any other possiblies can we send the notification via FCM Server side program? or seperately need to write the program for GCM and FCM?.
PHP 中 FCM 的示例代码
Sample Code for FCM in 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 );
}
?>
推荐答案
FCM 仍然与 GCM 兼容,因为它是它的核心.所以切换到 FCM 端点 (https://fcm.googleapis.com/fcm/send) 发送通知时,您的应用程序版本仍应适用于具有 GCM 的应用程序.无需编写单独的程序.
FCM is still compatible with GCM, seeing as it is it's core. So switching to the FCM endpoint (https://fcm.googleapis.com/fcm/send) when sending your notification should still work for your app versions that have GCM. No need to write separate programs.
这篇关于Pushnotification 服务器端实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!