chore: workspace management
This commit is contained in:
55
sdgb-api/src/all_net/mod.rs
Normal file
55
sdgb-api/src/all_net/mod.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
use std::backtrace::Backtrace;
|
||||
|
||||
use nyquest::{AsyncClient, Body, Request};
|
||||
|
||||
mod model;
|
||||
use model::{GetResponse, GetUserId};
|
||||
|
||||
pub struct QRCode<'a> {
|
||||
qrcode_content: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Debug, snafu::Snafu)]
|
||||
pub enum QRLoginError {
|
||||
QRCodeExpired10,
|
||||
QRCodeExpired30,
|
||||
BadSingature,
|
||||
Unknown {
|
||||
error_kind: i64,
|
||||
},
|
||||
|
||||
#[snafu(context(false))]
|
||||
NyquestError {
|
||||
source: nyquest::Error,
|
||||
backtrace: Backtrace,
|
||||
},
|
||||
|
||||
#[snafu(context(false))]
|
||||
JSONError {
|
||||
source: serde_json::error::Error,
|
||||
backtrace: Backtrace,
|
||||
},
|
||||
}
|
||||
|
||||
impl QRCode<'_> {
|
||||
pub async fn login(self, client: &AsyncClient) -> Result<i64, QRLoginError> {
|
||||
let qr_code = &self.qrcode_content.as_bytes()[self.qrcode_content.len() - 64..];
|
||||
let qr_code = String::from_utf8_lossy(qr_code);
|
||||
|
||||
let req = Request::post("http://ai.sys-allnet.cn/wc_aime/api/get_data")
|
||||
.with_body(Body::json(&GetUserId::new(qr_code))?);
|
||||
|
||||
let resp = client.request(req).await?;
|
||||
let resp: GetResponse = resp.json().await?;
|
||||
|
||||
let user_id = resp.user_id;
|
||||
|
||||
match resp.error_id {
|
||||
0 => return Ok(user_id),
|
||||
2 => Err(QRLoginError::QRCodeExpired10),
|
||||
1 => Err(QRLoginError::QRCodeExpired30),
|
||||
50 => Err(QRLoginError::BadSingature),
|
||||
error_kind @ _ => Err(QRLoginError::Unknown { error_kind }),
|
||||
}
|
||||
}
|
||||
}
|
||||
52
sdgb-api/src/all_net/model.rs
Normal file
52
sdgb-api/src/all_net/model.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use chrono::{FixedOffset, Utc};
|
||||
use digest::Digest as _;
|
||||
use hmac_sha256::WrappedHash;
|
||||
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,
|
||||
}
|
||||
|
||||
impl GetUserId {
|
||||
pub fn new(qr_code: impl Into<String>) -> Self {
|
||||
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(×tamp);
|
||||
hash.update("XcW5FW4cPArBXEk4vzKz3CIrMuA5EVVW");
|
||||
let key = format!("{:X}", hash.finalize());
|
||||
|
||||
GetUserId {
|
||||
qr_code: qr_code.into(),
|
||||
chip_id,
|
||||
open_game_id: "MAID",
|
||||
key,
|
||||
timestamp,
|
||||
}
|
||||
}
|
||||
}
|
||||
2
sdgb-api/src/lib.rs
Normal file
2
sdgb-api/src/lib.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod title;
|
||||
pub mod all_net;
|
||||
1
sdgb-api/src/title/mod.rs
Normal file
1
sdgb-api/src/title/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user