easy-sms-rust/src/main.rs

38 lines
1.1 KiB
Rust
Raw Normal View History

2023-01-14 10:04:15 +00:00
#[macro_use] extern crate rocket;
use rocket::serde::json::Json;
use rocket::fs::FileServer;
use easy_sms::Message;
use easy_sms::telecom;
use std::collections::HashMap;
#[get("/")]
async fn index() -> &'static str {
let body = reqwest::get("http://192.168.88.5:8888").await.unwrap().text().await.unwrap();
println!("{}", body);
"Hello, world!"
}
#[post("/send_msg", format="application/json", data="<message>")]
async fn send_msg(message: Json<Message<'_>>) -> String {
const API_URL: &'static str = "http://www.js139.com.cn:8022/hysms/SendMsg";
let client = reqwest::Client::new();
let mut ps: HashMap<&str, &str> = HashMap::new();
ps.insert("userId", message.userid);
ps.insert("password", message.password);
ps.insert("mobile", message.mobile);
ps.insert("content", message.content);
let body = client.post(API_URL)
.query(&ps)
.send().await.unwrap()
.text().await.unwrap();
format!("{}", &body)
}
#[launch]
fn rocket() -> _ {
rocket::build()
.mount("/", routes![index])
.mount("/", routes![send_msg])
}