Преглед на файлове

将appsecret改为配置文件配置

zii преди 1 месец
родител
ревизия
8977bf0876
променени са 2 файла, в които са добавени 17 реда и са изтрити 10 реда
  1. 4 3
      src/api/auth.rs
  2. 13 7
      src/main.rs

+ 4 - 3
src/api/auth.rs

@@ -4,8 +4,9 @@ use crate::{AppState, datasource::Datasource, log, LogLevel::*};
 use serde::Deserialize;
 
 const APPID: &str = "wx664469117500d259";
-const APPSECRET : &str = "11ec6e6d4b9062f00a4fc08c529293be";
-// const APPSECRET : &str = "wx664469117500d259";
+// // const APPSECRET : &str = "11ec6e6d4b9062f00a4fc08c529293be";
+// const APPSECRET : &str = "a78ad639142e34447bdff5054b2f35a8";
+// // const APPSECRET : &str = "wx664469117500d259";
 
 #[derive(serde::Deserialize)]
 pub struct QueryParams {
@@ -68,7 +69,7 @@ pub async fn auth(
         "https://api.weixin.qq.com/sns/oauth2/access_token?appid={}&secret={}&code={}&grant_type=authorization_code",
         // "https://iotplatform.worldflying.cn/api/wx/auth?appid={}&secret={}&code={}&state={}&grant_type=authorization_code",
             APPID,
-            APPSECRET,
+            state.appsecret,
             q.code,
             // q.state
         )).send().await {

+ 13 - 7
src/main.rs

@@ -9,7 +9,7 @@ use tower_http::cors::{Any, CorsLayer}; // 添加Any和CorsLayer的引用
 
 const WEBP: &str =
  "https://www.worldflying.cn/tools/webapps/4gplc/"
-// "http://124.222.106.170/plc_ctrl"
+// "http://1    24.222.106.170/plc_ctrl"
 ;
 
 
@@ -49,6 +49,7 @@ struct MqDetail{
 struct AppState{
     db_lite: sqlite::SqlitePool,
     mq_detail: Option<MqDetail>,
+    appsecret: String,
 }
 
 #[derive(Clone)]
@@ -90,6 +91,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
         // mqtt: String,
         ssl_cert: Option<String>,
         ssl_key: Option<String>,
+        appsecret: String
     }
     let conf:Conf =match serde_json::from_reader(match std::fs::File::open(CFGPATH){
         Ok(f) => f,
@@ -101,6 +103,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
                 // mqtt: "/vat/lib/mosquitto.db".to_string(), 
                 ssl_cert: None,
                 ssl_key: None,
+                appsecret: String::new(),
         }).unwrap();
             f}
     }){
@@ -112,7 +115,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
                 // mqtt: " /var/lib/mosquitto/data.db".to_string(),
                 ssl_cert:None,
                 ssl_key:None,
-                ssl:None
+                ssl:None,
+                appsecret: String::new(),
              }},
     };
 
@@ -126,7 +130,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
                 sqlite::init_sqlite_pool("/var/lib/mosquitto/db/acl.db", 10).await,
             ){
                 Some(MqDetail { db_mq_user: a, db_mq_latest: b, db_mq_map: c })
-             } else{None}
+             } else{None},
+        appsecret: conf.appsecret
     };
 
     // let monitor = Counter::new();
@@ -138,11 +143,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
         .with_state(appstat.clone())
          // 应用完整的CORS配置
         .nest("/apilite", axum::Router::new()
-        // .nest("/api", axum::Router::new()
-            // .route("/wx/auth", get(api::auth::auth))
-        .route("/mq", post(api::ability::get_mqtt))
+            .route("/hello", get(async||{"hi"}))
+            // .nest("/api", axum::Router::new()
+                // .route("/wx/auth", get(api::auth::auth))
+            .route("/mq", post(api::ability::get_mqtt))
 
-        .route("/loggin", post(api::user::u_loggin))
+            .route("/loggin", post(api::user::u_loggin))
 
             .route("/device", post(api::device::d_all))