Crates.io | jpush |
lib.rs | jpush |
version | 0.1.3 |
source | src |
created_at | 2024-11-05 06:22:06.948496 |
updated_at | 2024-11-05 06:22:06.948496 |
description | 简单集成极光App推送 |
homepage | |
repository | https://global:global123456@gitea.1000duo.cn/qianduo/jpush.git |
max_upload_size | |
id | 1436073 |
size | 19,646 |
App Push SDK for Rust
[jpush]
url = "https:// api. jpush. cn/ v3/ push"
app_key = "your app key"
secret = "your secret"
use jpush::JPushClient;
use jpush::config::JPushConfig;
use jpush::msg::{JPushMessage, AndroidNotification, HarmonyOSNotification, IosNotification, Message, Platform, PlatformType};
async fn push() {
let config = JPushConfig {
url: "https://api.jpush.cn/v3/push".to_string(),
app_key: "your app key".to_string(),
secret: "your secret".to_string(),
};
let client = JPushClient::new(config);
let mut message = jpush::msg::JPushMessage::default();
message
.set_platform(Platform::VecString(vec![PlatformType::Ios, PlatformType::Android, PlatformType::HarmonyOS]))
// .set_platform(Platform::String(PlatformType::All))
.add_alias(vec![1135])
.set_notification_alert("hello world".to_string())
.set_ios_notification(IosNotification::new("hello world".to_string(), None))
.set_android_notification(AndroidNotification::new("hello ".to_string(), "world".to_string(), None))
.set_hmos_notification(HarmonyOSNotification::new("hello ".to_string(), "world".to_string(), "im".to_string(), None))
.set_message(Message::new("hello ".to_string(), "world".to_string(), None))
.set_options(jpush::msg::Options::new(86400, true, 1));
println!("{:?}", message);
let res = client.send(message).await;
match res {
Ok(res) => {
println!("{:?}", res)
}
Err(e) => {
println!("{}", e)
}
}
}
[dependencies]
jpush = { version = "0.1.2", features = ["spring-rs"] }
use jpush::JPushPlugin;
use jpush::client::JPushClient;
use jpush::msg::{JPushMessage, AndroidNotification, HarmonyOSNotification, IosNotification, Message, Platform, PlatformType};
use spring::App;
#[tokio::main]
async fn main() {
App::new()
.config_file("./config/job.toml")
.add_plugin(JPushPlugin)
.run()
.await;
}
async fn push(Component(client): Component<JPushClient>) -> Result<(), Box<dyn std::error::Error>> {
let mut message = jpush::msg::JPushMessage::default();
message
.set_platform(Platform::VecString(vec![PlatformType::Ios, PlatformType::Android, PlatformType::HarmonyOS]))
// .set_platform(Platform::String(PlatformType::All))
.add_alias(vec![1135])
.set_notification_alert("hello world".to_string())
.set_ios_notification(IosNotification::new("hello world".to_string(), None))
.set_android_notification(AndroidNotification::new("hello ".to_string(), "world".to_string(), None))
.set_hmos_notification(HarmonyOSNotification::new("hello ".to_string(), "world".to_string(), "im".to_string(), None))
.set_message(Message::new("hello ".to_string(), "world".to_string(), None))
.set_options(jpush::msg::Options::new(86400, true, 1));
println!("{:?}", message);
let res = client.send(message).await;
match res {
Ok(res) => {
println!("{:?}", res)
}
Err(e) => {
println!("{}", e)
}
}
}