jpush

Crates.iojpush
lib.rsjpush
version0.1.3
sourcesrc
created_at2024-11-05 06:22:06.948496
updated_at2024-11-05 06:22:06.948496
description简单集成极光App推送
homepage
repositoryhttps://global:global123456@gitea.1000duo.cn/qianduo/jpush.git
max_upload_size
id1436073
size19,646
尹旭 (yinxu46)

documentation

README

JPush for Rust

App Push SDK for Rust

config toml

[jpush]
url = "https:// api. jpush. cn/ v3/ push"
app_key = "your app key"
secret = "your secret"

use demo

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)
        }
    }
}

depends on spring-rs use demo

[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)
        }
    }
}


Commit count: 0

cargo fmt