funpay_client/
utils.rs

1use once_cell::sync::Lazy;
2use regex::Regex;
3
4pub static RE_ORDER_ID: Lazy<Regex> = Lazy::new(|| Regex::new(r"#[A-Z0-9]{8}").unwrap());
5
6pub fn extract_phpsessid(set_cookies: &[String]) -> Option<String> {
7    for val in set_cookies {
8        if let Some(pos) = val.find("PHPSESSID=") {
9            let tail = &val[pos + "PHPSESSID=".len()..];
10            let sess = tail.split(';').next().unwrap_or("").to_string();
11            if !sess.is_empty() {
12                return Some(sess);
13            }
14        }
15    }
16    None
17}
18
19pub fn random_tag() -> String {
20    use rand::Rng;
21    let mut rng = rand::thread_rng();
22    let alphabet: &[u8] = b"0123456789abcdefghijklmnopqrstuvwxyz";
23    (0..10)
24        .map(|_| alphabet[rng.gen_range(0..alphabet.len())] as char)
25        .collect()
26}