pub mod user; pub mod area; pub mod auth; pub mod device; pub mod flow_task; pub mod ability; #[cfg(target_arch = "x86_64")] #[cfg(target_os = "windows")] mod code_helper; use rand::Rng; use crate::datasource::Datasource; #[derive(serde::Deserialize)] pub struct Ident{ token: String } #[derive(serde::Serialize)] pub struct JsonBack{ pub errcode: i16, #[serde(skip_serializing_if = "Option::is_none")] pub errmsg: Option } #[derive(serde::Serialize)] pub struct DataBack{ pub errcode: i16, #[serde(skip_serializing_if = "Option::is_none")] pub errmsg: Option, #[serde(skip_serializing_if = "Option::is_none")] pub data: Option } #[derive(serde::Deserialize)] pub struct Page{ page: usize, size: usize } pub fn token_fail() ->axum::Json {axum::Json(JsonBack{ errcode: 2000, errmsg: Some("鉴权失败: token无效".to_string()) })} pub fn errcode0() ->axum::Json {axum::Json(JsonBack{ errcode: 0, errmsg: None })} #[allow(dead_code)] pub async fn example(axum::extract::State(_): axum::extract::State) -> axum::Json { axum::Json(JsonBack{ errcode: 0, errmsg: None }) } pub async fn check_token(state: &crate::AppState, token: String) -> Result<(u64,String),()>{ state.db_lite.query( "select id,mqid from user where token=? and isdelete=0", [token], // 这里不能写作 rusqlite::params![token] |r|{Ok((r.get::(0)?,r.get::(1)?))}).await.map_err(|e| println!("{e}")) } pub async fn check_openid(state: &crate::AppState, openid: String) -> Result<(u64,String),()>{ state.db_lite.query( "select id,mqid from user where openid=? and isdelete=0", [openid], // 这里不能写作 rusqlite::params![token] |r|{Ok((r.get::(0)?,r.get::(1)?))}).await.map_err(|e| println!("{e}")) } pub fn token(s: usize) -> String{ rand::rng().sample_iter(&rand::distr::Alphanumeric).take(s).map(char::from).collect() } pub fn md5(payload: String) -> String{ format!("{:x}",md5::compute(payload)) } #[cfg(test)] mod tests{ #[test] fn test_token(){ use super::token; println!("{}",token(32)); } #[test] fn test_md5(){ use super::md5; println!("{}",md5("123456".to_string())); } }