0.1.0 |
|
---|
#12 在 #fcm
10KB
72 行
Firebase云消息API v1 Rust包
此Rust包提供了一种方便的方式来使用Firebase云消息(FCM)API v1发送通知。它利用async/await进行异步操作,并支持从JSON文件中加载服务账户凭证。
安装
将此包添加到您的 Cargo.toml
[dependencies]
fcm_rust = "0.1.0"
用法
以下是如何使用此包发送通知的示例
use fcm_rust::{ client::FcmClient, models::{ Message, Notification } };
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let service_account_path = "path/to/service_account";
let project_id = "your_project_id".to_string();
// Create a new FCM client
let client = FcmClient::new(service_account_path, project_id).await?;
// Define the message with the target device token and notification details
let message = Message {
token: Some("your_device_token".to_string()),
notification: Some(Notification {
title: Some("Hello from Rust!".to_string()),
body: Some("This is a test notification.".to_string()),
}),
data: None,
};
// Send the message and handle the response
let response = client.send(message).await?;
println!("FCM response: {:?}", response);
Ok(())
}
贡献
欢迎贡献!请随时提交问题或拉取请求。
联系方式
如有任何疑问或建议,请在此GitHub仓库上创建一个问题。
依赖项
~12–24MB
fcm-rs 包提供了一个方便的方式来使用Firebase云消息(FCM)API v1发送通知。它利用async/await进行异步操作,并支持从JSON文件中加载服务账户凭证。