From 5b205ce1e0b4f589d8bc5409d76c65ba3f23db49 Mon Sep 17 00:00:00 2001 From: jane400 Date: Tue, 17 Sep 2024 11:53:33 +0200 Subject: [PATCH] fix: add more paramters to tracking (fingers crossed) --- libpaket/src/constants.rs | 8 ++++++++ libpaket/src/tracking.rs | 23 ++++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/libpaket/src/constants.rs b/libpaket/src/constants.rs index cc8f476..d1db197 100644 --- a/libpaket/src/constants.rs +++ b/libpaket/src/constants.rs @@ -15,6 +15,14 @@ pub fn device_string() -> &'static str { "OnePlus 6T Build/RQ3A.211001.001" } +pub fn okhttp_user_agent() -> String { + format!( + "okhttp/4.11.0 Post & DHL/{} ({})", + app_version(), + linux_android_version() + ) +} + pub fn web_user_agent() -> String { format!("Mozilla/5.0 ({}; {}; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/117.0.0.0 Mobile Safari/537.36", linux_android_version(), device_string()) diff --git a/libpaket/src/tracking.rs b/libpaket/src/tracking.rs index b910556..6db6418 100644 --- a/libpaket/src/tracking.rs +++ b/libpaket/src/tracking.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::{login::DHLIdToken, LibraryResult}; +use crate::{login::DHLIdToken, LibraryError, LibraryResult}; #[derive(Default)] pub struct TrackingParams { @@ -32,15 +32,16 @@ impl crate::WebClient { endpoint_data_search, query(&query_parameters_data_search(¶ms, ids)), header(api_key.0, api_key.1), - header("Cookie", cookie_value) + header("cookie", cookie_value), + header("x-requested-with", "de.dhl.paket"), + header("sec-ch-ua-platform", "\"Android\""), + header("sec-ch-ua", r#""Chromium";v="122", "Not(A:Brand";v="24", "Android WebView";v="122""#), + header("sec-ch-ua-mobile", "?1"), + header("content-type", "application/json"), + header("accept", "application/json") ) } else { - request!( - self.web_client, - endpoint_data_search, - query(&query_parameters_data_search(¶ms, ids)), - header(api_key.0, api_key.1) - ) + return Err(LibraryError::InvalidArgument("only supported with a logged-in session".to_string())); }; let resp = parse_json_response!(res, Response); @@ -414,13 +415,17 @@ fn query_parameters_data_search( params: &TrackingParams, mut shippingnumbers: Vec, ) -> Vec<(String, String)> { - let mut out = vec![("noRedirect".to_string(), "true".to_string())]; + let mut out = vec![ + ("noRedirect".to_string(), "true".to_string()), + ("cid".to_string(), "app".to_string()), + ]; if let Some(lang) = params.language.as_ref() { out.push(("language".to_string(), lang.clone())); } if shippingnumbers.len() > 0 { + out.push(("inputSearch".to_string(), "true".to_string())); let mut shippingnumbers_string = shippingnumbers.pop().unwrap(); for number in shippingnumbers { shippingnumbers_string = format!(",{}", number);