最近,我已将 FCM 集成到我的应用程序最新版本中,但我以前版本的应用程序使用的是 GCM。关于我们是否需要为 GCM 和 FCM 分离后台 cron 的写入有什么想法吗?
我的先前版本 MY App 4.0 使用了 GCM,当前版本 My App 4.1 并集成了 FCM。我想向版本和用户发送推送通知。那么我们是否需要为GCM和FCM编写服务器端程序呢?关于这种整合的任何想法。
FCM 服务器端 API :https://fcm.googleapis.com/fcm/send https://fcm.googleapis.com/fcm/sendGCM 服务器端 API:https://android.googleapis.com/gcm/send https://android.googleapis.com/gcm/send
我们还可以通过 FCM 服务器端程序发送通知吗?还是需要分别为GCM和FCM编写程序?
PHP 中的 FCM 示例代码
<?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 );
}
?>