feat: initial support of method call
This commit is contained in:
@@ -1,17 +1,67 @@
|
||||
use crate::title::error::ApiError;
|
||||
use std::fmt::Display;
|
||||
|
||||
use crate::title::methods::APIMethod;
|
||||
|
||||
pub mod encryption;
|
||||
pub mod methods;
|
||||
pub mod model;
|
||||
|
||||
mod error;
|
||||
pub use error::ApiError;
|
||||
use nyquest::{
|
||||
Body,
|
||||
r#async::Request,
|
||||
header::{ACCEPT_ENCODING, CONTENT_ENCODING, EXPECT, USER_AGENT},
|
||||
};
|
||||
use serde::Serialize;
|
||||
|
||||
pub trait MaiVersion {
|
||||
const AES_KEY: &[u8; 32];
|
||||
const AES_IV: &[u8; 16];
|
||||
const OBFUSECATE_PARAM: &str;
|
||||
const OBFUSECATE_SUFFIX: &str;
|
||||
const VERSION: &str;
|
||||
}
|
||||
|
||||
pub trait MaiVersionExt: MaiVersion {
|
||||
fn encode(data: impl AsRef<[u8]>) -> Result<Vec<u8>, ApiError>;
|
||||
fn decode(data: impl AsMut<[u8]>) -> Result<Vec<u8>, ApiError>;
|
||||
|
||||
fn api_hash(api: APIMethod) -> String {
|
||||
let api_name: &str = api.into();
|
||||
|
||||
let mut md5 = md5::Context::new();
|
||||
md5.consume(api_name);
|
||||
md5.consume(Self::OBFUSECATE_SUFFIX);
|
||||
let digest = md5.finalize();
|
||||
|
||||
format!("{digest:x}")
|
||||
}
|
||||
|
||||
fn api_request<D>(
|
||||
api: APIMethod,
|
||||
agent_extra: impl Display,
|
||||
data: D,
|
||||
) -> Result<Request, ApiError>
|
||||
where
|
||||
D: Serialize,
|
||||
{
|
||||
let json = serde_json::to_vec(&data)?;
|
||||
let payload = Self::encode(json)?;
|
||||
|
||||
let api_hash = Self::api_hash(api);
|
||||
let req = Request::post(format!(
|
||||
"https://maimai-gm.wahlap.com:42081/Maimai2Servlet/{api_hash}"
|
||||
))
|
||||
.with_body(Body::json_bytes(payload))
|
||||
.with_header(USER_AGENT, format!("{api_hash}#{agent_extra}"))
|
||||
.with_header("Mai-Encoding", Self::VERSION)
|
||||
.with_header(ACCEPT_ENCODING, "")
|
||||
.with_header("Charset", "UTF-8")
|
||||
.with_header(CONTENT_ENCODING, "deflate")
|
||||
.with_header(EXPECT, "100-continue");
|
||||
|
||||
Ok(req)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Sdgb1_40;
|
||||
@@ -20,10 +70,14 @@ pub struct Sdgb1_50;
|
||||
impl MaiVersion for Sdgb1_40 {
|
||||
const AES_KEY: &[u8; 32] = b"n7bx6:@Fg_:2;5E89Phy7AyIcpxEQ:R@";
|
||||
const AES_IV: &[u8; 16] = b";;KjR1C3hgB1ovXa";
|
||||
const OBFUSECATE_PARAM: &str = "BEs2D5vW";
|
||||
const OBFUSECATE_SUFFIX: &str = "MaimaiChnBEs2D5vW";
|
||||
|
||||
const VERSION: &str = "1.40";
|
||||
}
|
||||
impl MaiVersion for Sdgb1_50 {
|
||||
const AES_KEY: &[u8; 32] = b"a>32bVP7v<63BVLkY[xM>daZ1s9MBP<R";
|
||||
const AES_IV: &[u8; 16] = b"d6xHIKq]1J]Dt^ue";
|
||||
const OBFUSECATE_PARAM: &str = "B44df8yT";
|
||||
const OBFUSECATE_SUFFIX: &str = "MaimaiChnB44df8yT";
|
||||
|
||||
const VERSION: &str = "1.50";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user