2024-09-16 10:36:26 +02:00
|
|
|
use std::collections::HashMap;
|
2024-08-16 19:40:14 +02:00
|
|
|
|
2024-09-16 10:36:26 +02:00
|
|
|
use reqwest::header::HeaderMap;
|
2024-08-16 19:40:14 +02:00
|
|
|
|
2024-09-16 10:36:26 +02:00
|
|
|
use crate::{
|
|
|
|
constants::{app_version, web_user_agent},
|
|
|
|
locker::LockerServiceUUID,
|
|
|
|
};
|
|
|
|
|
|
|
|
use super::{crypto::CustomerKeySeed, LockerDevice};
|
|
|
|
|
|
|
|
use serde::{self, Deserialize, Serialize};
|
|
|
|
|
|
|
|
pub struct LockerClient {
|
2024-08-16 19:40:14 +02:00
|
|
|
client: reqwest::Client,
|
|
|
|
}
|
|
|
|
|
2024-09-16 10:36:26 +02:00
|
|
|
pub struct LockerSession {
|
|
|
|
api_client: reqwest::Client,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl LockerClient {
|
|
|
|
pub async fn new() -> Self {
|
|
|
|
LockerClient {
|
2024-08-16 19:40:14 +02:00
|
|
|
client: reqwest::ClientBuilder::new()
|
|
|
|
.default_headers(headers())
|
|
|
|
.user_agent(user_agent())
|
|
|
|
.build()
|
|
|
|
.unwrap(),
|
|
|
|
}
|
|
|
|
}
|
2024-09-16 10:36:26 +02:00
|
|
|
|
|
|
|
pub async fn open_session(
|
|
|
|
&self,
|
|
|
|
device: LockerDevice,
|
|
|
|
seed: &CustomerKeySeed,
|
|
|
|
) -> LockerSession {
|
|
|
|
let request = LoginCustomerRequest {
|
|
|
|
device_id: seed.device_id.as_ref().unwrap().clone(),
|
|
|
|
firmware_version: todo!(),
|
|
|
|
postnumber: seed.postnumber.clone(),
|
|
|
|
signature: todo!(),
|
|
|
|
tlv_message: todo!(),
|
|
|
|
uuid: todo!(),
|
|
|
|
};
|
|
|
|
}
|
2024-08-16 19:40:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn user_agent() -> String {
|
|
|
|
format!("LPS Consumer SDK/2.1.0 okhttp/4.9.1 {}", web_user_agent())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn headers() -> HeaderMap {
|
|
|
|
let aaa = vec![
|
|
|
|
/* ("accept", "application/json") */
|
|
|
|
("app-version", app_version()),
|
|
|
|
("device-os", "Android"),
|
2024-08-18 18:10:20 +02:00
|
|
|
("device-key", ""), /* is the android id... */
|
2024-08-16 19:40:14 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
let mut map = HeaderMap::new();
|
|
|
|
for bbb in aaa {
|
|
|
|
map.append(bbb.0, bbb.1.parse().unwrap());
|
|
|
|
}
|
|
|
|
|
|
|
|
map
|
2024-09-16 10:36:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn endpoint_auth_login_customer() -> &'static str {
|
|
|
|
"https://packstation.de/lpsAuth/auth/loginCustomer"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn endpoint_service_session(locker_uuid: &str) -> String {
|
|
|
|
format!(
|
|
|
|
"https://packstation.de/lpsService/customer/v31/locker/{}/session",
|
|
|
|
locker_uuid
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct LoginCustomerRequest {
|
|
|
|
device_id: String,
|
|
|
|
firmware_version: String,
|
|
|
|
postnumber: String,
|
|
|
|
signature: String,
|
|
|
|
tlv_message: String,
|
|
|
|
uuid: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct LoginCustomerResponse {
|
|
|
|
access_token: String,
|
|
|
|
refresh_token: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct LockerMetadata {
|
|
|
|
firmware_version: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct Command {
|
|
|
|
lps_command_string: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct SessionRequest {
|
|
|
|
locker: LockerMetadata,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct LpsState {
|
|
|
|
open_compartments: Vec<u32>,
|
|
|
|
opened_compartments: Vec<u32>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct SessionResponse {
|
|
|
|
lps_command_string: String,
|
|
|
|
lps_state: LpsState,
|
|
|
|
response_required: bool,
|
|
|
|
}
|