星空云rust webapi 查询科目名称

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

星空云rust webapi  查询科目名称

use reqwest::header::CONTENT_TYPE;
use reqwest::{redirect::Policy};
use kd_test1::{LoginRequest,Paramskd,Data};
use serde::{Deserialize, Serialize};
use serde_json::Value;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let url = "http://192.168.0.85/k3cloud/Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc";
    let client = reqwest::Client::builder()
        .redirect(Policy::limited(2))
        .cookie_store(true)
        .build()
        .unwrap();
    // 构造请求参数
    let parameters = LoginRequest {
        // acctID: "600979bb86e6ac".to_string(),
        //6400279d8606d6
        acctID: "643ce9f1372ab5".to_string(),
        username: "Administrator".to_string(),
        password: "k_888888".to_string(),
        lcid: 2052,
    };
 
    let body = serde_json::to_string(&parameters).unwrap();
    println!("用户传参:{}", &body);
    let response = client
        //  .redirect(Policy::limited(2))
        // .cookie_store(true)
        .post(url)
        //.text_with_charset("utf-8")
        .header(CONTENT_TYPE, "application/json;charset=UTF-8")
        .body(body)
        .send()
        .await?
        .text()
        .await?;

    let result = serde_json::from_str::<Value>(&response)?;
    let i_result = result["LoginResultType"].as_i64().unwrap_or(0);

    if i_result == 1 {  
    println!("登录验证成功,处理业务");
    }
 
    let aata = Data::data {
        CreateOrgId: 0,
        Number: "1001".to_string(),
        Id: "".to_string(),
        IsSortBySeq: false,
    };
    let paramskd = Paramskd {
        formid: "BD_Account".to_string(),
        data: aata,
    };

    let ejson3 = serde_json::to_string(&paramskd).unwrap();
    println!("data传参{:?}", &ejson3);

    let Response2=client
       .post("http://192.168.0.85/K3Cloud/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.View.common.kdsvc")
       .header(CONTENT_TYPE, "application/json")  
       .body(ejson3)
       .send()
       .await?
       .text()
       .await?;
    println!("{:#?}", Response2);
    Ok(())

}


==============crate kd_test1kd_test1======

use serde::{Deserialize, Serialize};
#[derive(Serialize, Debug)]
pub struct LoginRequest {
    pub username: String,
    pub password: String,
    pub acctID: String,
    pub lcid: i32,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Paramskd {
   pub formid: String,
  pub  data: Data,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(untagged)] //对此枚举使用未标记的枚举表示形式
pub enum Data {
   data {
        CreateOrgId: i32,
        Number: String,
        Id: String,
        IsSortBySeq: bool,
    },
}




异步的哟

星空云rust webapi 查询科目名称

use reqwest::header::CONTENT_TYPE;use reqwest::{redirect::Policy};use kd_test1::{LoginRequest,Paramskd,Data};use serde::{Deser...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息