ncm_api_rs/api/
login_cellphone.rs1use super::Query;
2use crate::error::Result;
3use crate::request::{ApiClient, ApiResponse, CryptoType};
6use md5::{Digest, Md5};
7use serde_json::{json, Value};
8
9impl ApiClient {
10 pub async fn login_cellphone(&self, query: &Query) -> Result<ApiResponse> {
13 let mut data = json!({
14 "type": "1",
15 "https": "true",
16 "phone": query.get_or("phone", ""),
17 "countrycode": query.get_or("countrycode", "86"),
18 "remember": "true"
19 });
20
21 if let Some(captcha) = query.get("captcha") {
22 data["captcha"] = Value::String(captcha.to_string());
23 data["password"] = Value::String(captcha.to_string());
26 } else {
27 let password = if let Some(md5_pwd) = query.get("md5_password") {
28 md5_pwd.to_string()
29 } else if let Some(pwd) = query.get("password") {
30 format!("{:x}", Md5::digest(pwd.as_bytes()))
31 } else {
32 String::new()
33 };
34 data["password"] = Value::String(password);
35 }
36
37 self.request(
38 "/api/w/login/cellphone",
39 data,
40 query.to_option(CryptoType::Weapi),
41 )
42 .await
43 }
44}