initial commit

This commit is contained in:
mokurin000
2025-07-29 01:14:58 +08:00
commit 7eebb2e224
6 changed files with 1457 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

1345
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

28
Cargo.toml Normal file
View File

@@ -0,0 +1,28 @@
[package]
name = "sdgb-utils-rs"
version = "0.1.0"
edition = "2024"
[dependencies]
digest = "0.10.7"
hmac-sha256 = { version = "1.1.12", features = ["digest010", "traits010"] }
chrono = "0.4.41"
nyquest = { version = "0.2.0", features = ["async", "json"] }
nyquest-preset = { version = "0.2.0", features = ["async"] }
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.141"
snafu = "0.8.6"
compio = { version = "0.15.0", default-features = false, features = [
"runtime",
"macros",
] }
[profile.release]
lto = true
strip = true
codegen-units = 1
panic = "abort"

1
src/lib.rs Normal file
View File

@@ -0,0 +1 @@
pub mod model;

58
src/main.rs Normal file
View File

@@ -0,0 +1,58 @@
use std::env;
use chrono::{FixedOffset, Utc};
use digest::Digest;
use hmac_sha256::WrappedHash;
use nyquest::{Body, ClientBuilder, Request};
use sdgb_utils_rs::model::{GetResponse, GetUserId};
#[compio::main]
async fn main() -> Result<(), Box<dyn snafu::Error>> {
nyquest_preset::register();
let qr_code = env::args().nth(1).expect("missing argument: QRCode");
let qr_code = String::from_utf8_lossy(&qr_code.as_bytes()[qr_code.len() - 64..]).into_owned();
let chip_id = "A63E-01E54389854".to_string();
let timestamp = Utc::now()
.with_timezone(&FixedOffset::east_opt(8 * 60 * 60).unwrap())
.format("%y%m%d%H%M%S")
.to_string();
let mut hash = WrappedHash::new();
hash.update(&chip_id);
hash.update(&timestamp);
hash.update("XcW5FW4cPArBXEk4vzKz3CIrMuA5EVVW");
let key = format!("{:X}", hash.finalize());
let get_user_id = GetUserId {
chip_id,
open_game_id: "MAID",
qr_code,
key,
timestamp,
};
let client = ClientBuilder::default()
.user_agent("WC_AIME_LIB")
.build_async()
.await?;
let req = Request::post("http://ai.sys-allnet.cn/wc_aime/api/get_data")
.with_body(Body::json(&get_user_id)?);
let resp = client.request(req).await?;
let resp: GetResponse = resp.json().await?;
let user_id = resp.user_id;
match resp.error_id {
0 => println!("{user_id}"),
1 => eprintln!("[30min] QRCode Expired"),
2 => eprintln!("[10min] QRCode Expired"),
50 => eprintln!("Bad keychip"),
_ => eprintln!("{resp:#?}"),
}
Ok(())
}

24
src/model.rs Normal file
View File

@@ -0,0 +1,24 @@
use serde::{Deserialize, Serialize};
#[derive(Default, Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetUserId {
#[serde(rename = "chipID")]
pub chip_id: String,
#[serde(rename = "openGameID")]
pub open_game_id: &'static str,
pub key: String,
pub qr_code: String,
pub timestamp: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GetResponse {
pub key: String,
pub timestamp: String,
#[serde(rename = "errorID")]
pub error_id: i64,
#[serde(rename = "userID")]
pub user_id: i64,
}