Plan 01 - facade migration (ARCH-06/07):
- boss.py: import from spiderJobs.platforms.boss.{api,client,sign}
- qcwy.py: import from spiderJobs.platforms.job51.{api,client}
- zhilian.py: import from spiderJobs.platforms.zhilian.{api,client,sign}
- All 3 Service classes: +4 async_* methods via asyncio.to_thread()
Plan 02 - deprecation + cleanup (ARCH-08):
- 11 private copy files (_base, _http_client, _boss/job51/zhilian *): DEPRECATED header
- jobs_spider/ directory: fully deleted (user request)
Full regression: 106 passed in 0.61s
79 lines
2.0 KiB
Python
79 lines
2.0 KiB
Python
# ⚠️ DEPRECATED — 2026-03-21
|
|
# 此文件是内部手工复制文件,已废弃,不再由任何 facade 引用。
|
|
# 请改用 spiderJobs.platforms.* 或 crawler_core 中的对应模块。
|
|
# 将在下一里程碑中删除。
|
|
#
|
|
"""
|
|
Boss直聘 Traceid 生成算法
|
|
复制自 spiderJobs/platforms/boss/sign.py — import 改为本地引用
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import random
|
|
import time
|
|
|
|
|
|
_CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
|
|
def _to_u32(n: int) -> int:
|
|
return n & 0xFFFFFFFF
|
|
|
|
|
|
def _compute_checksum(uuid_str: str) -> str:
|
|
r = 0
|
|
for ch in uuid_str:
|
|
r = ((r << 5) - r + ord(ch)) & 0xFFFFFFFF
|
|
|
|
a = 0
|
|
for i in range(len(uuid_str) - 1, -1, -1):
|
|
a = ((a << 7) - a + ord(uuid_str[i]) * (i + 1)) & 0xFFFFFFFF
|
|
|
|
n = 0
|
|
mid = len(uuid_str) // 2
|
|
for i in range(len(uuid_str)):
|
|
n = ((n << 3) - n + ord(uuid_str[i]) * (abs(i - mid) + 1)) & 0xFFFFFFFF
|
|
|
|
s = _to_u32(r ^ a)
|
|
s = _to_u32(2654435761 * s)
|
|
s = _to_u32(s ^ (s >> 16))
|
|
s = _to_u32(2246822507 * s)
|
|
s = _to_u32(s ^ (s >> 13))
|
|
c1 = _CHARS[s % 62]
|
|
|
|
h = _to_u32(a ^ n)
|
|
h = _to_u32(3266489909 * h)
|
|
h = _to_u32(h ^ (h >> 16))
|
|
h = _to_u32(2654435761 * h)
|
|
h = _to_u32(h ^ (h >> 13))
|
|
c2 = _CHARS[h % 62]
|
|
|
|
v = _to_u32(n ^ r)
|
|
v = _to_u32(668265261 * v)
|
|
v = _to_u32(v ^ (v >> 16))
|
|
v = _to_u32(2246822507 * v)
|
|
v = _to_u32(v ^ (v >> 13))
|
|
c3 = _CHARS[v % 62]
|
|
|
|
return f"{c1}{c2}{c3}"
|
|
|
|
|
|
def _generate_uuid() -> str:
|
|
hex_ts = format(int(time.time() * 1000), "x").lower()
|
|
hex_ts = hex_ts[-13:].zfill(13)
|
|
rand_part = "".join(random.choice(_CHARS) for _ in range(6))
|
|
return hex_ts + rand_part
|
|
|
|
|
|
class BossSign:
|
|
def __init__(self, *, mpt: str = "", wt2: str = ""):
|
|
self.mpt = mpt
|
|
self.wt2 = wt2
|
|
|
|
@staticmethod
|
|
def generate_traceid(prefix: str = "M-W") -> str:
|
|
uuid_str = _generate_uuid()
|
|
checksum = _compute_checksum(uuid_str)
|
|
return f"{prefix}{uuid_str}{checksum}"
|