feat: qrlogin command

This commit is contained in:
mokurin000
2025-07-29 20:16:04 +08:00
parent 084d4846d6
commit 097e332aa7
6 changed files with 339 additions and 20 deletions

View File

@@ -1,24 +1,27 @@
use std::backtrace::Backtrace;
use nyquest::{AsyncClient, Body, Request};
use nyquest::{AsyncClient, Body, Request, header::USER_AGENT};
mod model;
use model::{GetResponse, GetUserId};
pub struct QRCode<'a> {
qrcode_content: &'a str,
pub qrcode_content: &'a str,
}
#[derive(Debug, snafu::Snafu)]
pub enum QRLoginError {
#[snafu(display("QRCode expired [10mins]"))]
QRCodeExpired10,
#[snafu(display("QRCode expired [30mins]"))]
QRCodeExpired30,
#[snafu(display("Bad signature!"))]
BadSingature,
Unknown {
error_kind: i64,
},
#[snafu(display("unknown error: {error_kind}"))]
Unknown { error_kind: i64 },
#[snafu(context(false))]
#[snafu(display("request error: {source}"))]
NyquestError {
source: nyquest::Error,
backtrace: Backtrace,
@@ -37,7 +40,8 @@ impl QRCode<'_> {
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))?);
.with_body(Body::json(&GetUserId::new(qr_code))?)
.with_header(USER_AGENT, "WC_AIME_LIB");
let resp = client.request(req).await?;
let resp: GetResponse = resp.json().await?;