Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Môi trường máy chủ của bạn và FCM
Phía máy chủ của Firebase Cloud Messaging bao gồm 2 thành phần:
Phần phụ trợ FCM do Google cung cấp.
Máy chủ ứng dụng hoặc môi trường máy chủ đáng tin cậy khác nơi logic máy chủ của bạn chạy, chẳng hạn như Cloud Functions cho Firebase hoặc các môi trường đám mây khác do Google quản lý.
Máy chủ ứng dụng hoặc môi trường máy chủ đáng tin cậy của bạn sẽ gửi yêu cầu tin nhắn đến phần phụ trợ FCM. Sau đó, phần phụ trợ này sẽ định tuyến tin nhắn đến các ứng dụng khách đang chạy trên thiết bị của người dùng.
Yêu cầu đối với môi trường máy chủ đáng tin cậy
Môi trường máy chủ ứng dụng của bạn phải đáp ứng các tiêu chí sau:
Có thể gửi các yêu cầu về tin nhắn được định dạng đúng đến phần phụ trợ FCM.
Có thể lưu trữ an toàn thông tin xác thực uỷ quyền máy chủ và mã thông báo đăng ký ứng dụng.
Chọn một lựa chọn về máy chủ
Bạn cần quyết định cách tương tác với các máy chủ FCM: sử dụng Firebase Admin SDK hoặc giao thức thô.
Vì hỗ trợ các ngôn ngữ lập trình phổ biến và các phương thức thuận tiện để xử lý việc xác thực và uỷ quyền, nên Firebase Admin SDK là phương thức được đề xuất.
Sau đây là các lựa chọn để tương tác với máy chủ FCM:
FCM HTTP v1 API, một API REST có khả năng uỷ quyền bảo mật và nhắn tin linh hoạt trên nhiều nền tảng (Firebase Admin SDK dựa trên giao thức này và cung cấp tất cả các lợi thế vốn có của giao thức).
Firebase Admin SDK cho FCM
Admin FCM API xử lý việc xác thực với phần phụ trợ, đồng thời hỗ trợ gửi thông báo và quản lý việc đăng ký theo chủ đề. Với Firebase Admin SDK, bạn có thể:
Gửi thông báo đến từng thiết bị
Gửi thông báo đến các chủ đề và câu lệnh điều kiện khớp với một hoặc nhiều chủ đề.
Đăng ký và huỷ đăng ký thiết bị theo dõi chủ đề
Tạo tải trọng thông báo phù hợp với nhiều nền tảng mục tiêu
Admin Node.js SDK cung cấp các phương thức để gửi thông báo đến các nhóm thiết bị.
FCM cung cấp FCM HTTP v1 API cho những nhà phát triển muốn dùng giao thức máy chủ thô.
Để gửi một thông báo, máy chủ ứng dụng sẽ đưa ra một yêu cầu POST có tiêu đề HTTP và nội dung HTTP bao gồm các cặp khoá-giá trị JSON.
Để biết thông tin chi tiết về các lựa chọn tiêu đề và nội dung, hãy xem phần Tạo yêu cầu gửi của máy chủ ứng dụng
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-09-03 UTC."],[],[],null,["\u003cbr /\u003e\n\nYour server environment and FCM\n\nThe server side of Firebase Cloud Messaging consists of two components:\n\n- The **FCM backend** provided by Google.\n- Your **app server** or other **trusted server environment** where your server logic runs, such as [Cloud Functions for Firebase](/docs/functions) or other cloud environments managed by Google.\n\n\u003cbr /\u003e\n\nYour app server or trusted server environment sends message requests to the FCM\nbackend, which then routes messages to client apps running on users' devices.\n\nRequirements for the trusted server environment\n\nYour app server environment must meet the following criteria:\n\n- Able to send properly formatted message requests to the FCM backend.\n- Able to handle requests and resend them using [exponential back-off.](https://developers.google.com/api-client-library/java/google-http-java-client/backoff)\n- Able to securely store server authorization credentials and client registration tokens.\n\nChoosing a server option\n\nYou'll need to decide on a way to interact with FCM servers: either using the\n[Firebase Admin SDK](/docs/cloud-messaging/server#firebase-admin-sdk-for-fcm) or the raw protocol.\nBecause of its support across popular programming languages and its convenience methods for\nhandling authentication and authorization, the Firebase Admin SDK is the recommended method.\n\nOptions for interacting with FCM servers include the following:\n\n- The Firebase Admin SDK, which has support for [Node](/docs/reference/admin/node/firebase-admin.messaging), [Java](/docs/reference/admin/java/reference/com/google/firebase/messaging/package-summary), [Python](/docs/reference/admin/python/firebase_admin.messaging), [C#](/docs/reference/admin/dotnet/namespace/firebase-admin/messaging), and [Go](//godoc.org/firebase.google.com/go/messaging).\n- The [FCM HTTP v1 API](/docs/reference/fcm/rest/v1/projects.messages), a REST API with secure authorization and flexible [cross-platform messaging capabilities](/docs/cloud-messaging/send-message#customize_messages_across_platforms) (the Firebase Admin SDK is based on this protocol and provides all of its inherent advantages).\n\nFirebase Admin SDK for FCM\n\nThe Admin FCM API handles authenticating with the backend and facilitates sending\nmessages and managing topic subscriptions. With the Firebase Admin SDK, you can:\n\n- Send messages to individual devices\n- Send messages to topics and condition statements that match one or more topics.\n- Subscribe and unsubscribe devices to and from topics\n- Construct message payloads tailored to different target platforms\n\nThe Admin Node.js SDK provides\nmethods for sending messages to device groups.\n\nTo set up the Firebase Admin SDK, see [Add the\nFirebase Admin SDK to Your Server](/docs/admin/setup). If you already have a Firebase project,\nstart with [Add the SDK](/docs/admin/setup#add-sdk). Also, make sure to enable the\nCloud Messaging API in the\n[Cloud Messaging settings page](//console.firebase.google.com/project/_/settings/cloudmessaging/)\nfor your project. Then, once the Firebase Admin SDK is installed, you can start writing logic to\n[build send requests](/docs/cloud-messaging/send-message).\n| The Firebase Admin SDK provides an API for subscribing and unsubscribing devices to and from FCM topics. These operations can subscribe or unsubscribe up to 1000 device registration tokens at a time. For more information, see [Manage topics from the server](/docs/cloud-messaging/manage-topics).\n\nFCM server protocol\n\nFCM provides the [FCM HTTP v1 API](/docs/reference/fcm/rest/v1/projects.messages) for developers who prefer a raw server protocol.\n\nTo send a message, the app server issues a POST request with\nan HTTP header and an HTTP body comprised of JSON key value pairs.\nFor details on the header and body options, see\n[Build App Server Send Requests](/docs/cloud-messaging/send-message)"]]