feat: initial commit for TheFarmer project

This commit is contained in:
Karriis
2026-02-18 13:52:06 +08:00
commit 8ceb5fa9db
420 changed files with 61918 additions and 0 deletions

52
server/src/qrlib/utils.js Normal file
View File

@@ -0,0 +1,52 @@
const axios = require('axios');
/**
* Cookie handling utilities
*/
class CookieUtils {
static parse(cookieStr) {
if (!cookieStr) return {};
return cookieStr.split(';').reduce((acc, curr) => {
const [key, value] = curr.split('=');
if (key) acc[key.trim()] = value ? value.trim() : '';
return acc;
}, {});
}
static getValue(cookies, key) {
if (!cookies) return null;
if (Array.isArray(cookies)) cookies = cookies.join('; ');
const match = cookies.match(new RegExp(`(?:^|;\\s*)${key}=([^;]*)`));
return match ? match[1] : null;
}
static getUin(cookies) {
const uin = this.getValue(cookies, 'wxuin') || this.getValue(cookies, 'uin') || this.getValue(cookies, 'ptui_loginuin');
if (!uin) return null;
// Remove leading 'o' if present (common in QQ cookies like 'o123456')
return uin.replace(/^o0*/, '');
}
}
/**
* Hashing utilities for QQ login
*/
class HashUtils {
static hash(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash += (hash << 5) + str.charCodeAt(i);
}
return 2147483647 & hash;
}
static getGTk(pskey) {
let gtk = 5381;
for (let i = 0; i < pskey.length; i++) {
gtk += (gtk << 5) + pskey.charCodeAt(i);
}
return gtk & 0x7fffffff;
}
}
module.exports = { CookieUtils, HashUtils };