From 0cbcb89dd8c596afdc157d2f93c1c9fd1c91b430 Mon Sep 17 00:00:00 2001 From: yml2213 Date: Mon, 14 Sep 2026 14:03:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(pdd):=20add=20realistic=20B=C3=A9zier=20mo?= =?UTF-8?q?use=20trajectory=20simulation=20to=20generate=20700+=20char=20a?= =?UTF-8?q?nti-content=20tokens?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platforms/pdd/pdd-anti-content.test.ts | 7 ++- .../src/services/platforms/pdd/pdd_anti.cjs | 62 ++++++++++++++++++- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/apps/backend/src/services/platforms/pdd/pdd-anti-content.test.ts b/apps/backend/src/services/platforms/pdd/pdd-anti-content.test.ts index daf6c21e..68070e44 100644 --- a/apps/backend/src/services/platforms/pdd/pdd-anti-content.test.ts +++ b/apps/backend/src/services/platforms/pdd/pdd-anti-content.test.ts @@ -51,12 +51,15 @@ test('PurePddAntiContent executes with ultra-low latency (< 1ms per token)', () assert.ok(avg < 2, `Average generation time should be < 2ms (actual: ${avg.toFixed(3)}ms)`) }) -test('PurePddAntiContent.getTokenAsync generates valid tokens via official JS engine', async () => { +test('PurePddAntiContent.getTokenAsync generates valid high-credibility tokens with simulated trajectory', async () => { const token = await pddAntiContentEngine.getTokenAsync({ cookies: '_nano_fp=42e47e06a644482087; api_uid=rBQ51234', serverTimeMs: 1726119845000, }) assert.ok(token.startsWith('0as'), 'Async token must start with 0as prefix') - assert.ok(token.length > 200, `Async token length should be > 200 (actual: ${token.length})`) + assert.ok( + token.length > 600, + `High-credibility token length should be > 600 chars (actual: ${token.length})`, + ) }) diff --git a/apps/backend/src/services/platforms/pdd/pdd_anti.cjs b/apps/backend/src/services/platforms/pdd/pdd_anti.cjs index f1d34ec3..fbc86d70 100644 --- a/apps/backend/src/services/platforms/pdd/pdd_anti.cjs +++ b/apps/backend/src/services/platforms/pdd/pdd_anti.cjs @@ -44,10 +44,67 @@ function createSandbox(cookies, options = {}) { documentElement: { clientWidth: 1920, clientHeight: 950, scrollTop: 0 }, body: { clientWidth: 1920, clientHeight: 950, scrollTop: 0 }, cookie: cookies || "", - addEventListener: ()=>{}, + addEventListener: (name, handler) => { + if (!sandbox._handlers) sandbox._handlers = {}; + sandbox._handlers[name] = handler; + }, removeEventListener: ()=>{}, createElement: (tag) => ({ getContext: () => null }) }; + sandbox.addEventListener = sandbox.document.addEventListener; + + sandbox._simulateTrajectory = () => { + const handlers = sandbox._handlers || {}; + const count = 22 + Math.floor(Math.random() * 8); + const p0 = { x: 300 + Math.random() * 200, y: 200 + Math.random() * 150 }; + const p1 = { x: p0.x + (Math.random() - 0.5) * 300, y: p0.y + (Math.random() - 0.5) * 200 }; + const p2 = { x: p1.x + (Math.random() - 0.5) * 300, y: p1.y + (Math.random() - 0.5) * 200 }; + const p3 = { x: 600 + Math.random() * 250, y: 350 + Math.random() * 200 }; + const targets = ["order-list-table", "order-row-item", "order-search-filter", "btn-query", "app"]; + let tStamp = 50 + Math.floor(Math.random() * 50); + + const mm = handlers["mousemove"]; + const md = handlers["mousedown"]; + const clk = handlers["click"]; + + if (mm && typeof mm.handleEvent === "function") { + for (let i = 0; i <= count; i++) { + const t = i / count; + const cx = Math.pow(1 - t, 3) * p0.x + 3 * Math.pow(1 - t, 2) * t * p1.x + 3 * (1 - t) * Math.pow(t, 2) * p2.x + Math.pow(t, 3) * p3.x; + const cy = Math.pow(1 - t, 3) * p0.y + 3 * Math.pow(1 - t, 2) * t * p1.y + 3 * (1 - t) * Math.pow(t, 2) * p2.y + Math.pow(t, 3) * p3.y; + tStamp += Math.floor(25 + Math.random() * 45); + + mm.handleEvent({ + isTrusted: true, + clientX: Math.round(cx + (Math.random() - 0.5) * 2), + clientY: Math.round(cy + (Math.random() - 0.5) * 2), + timeStamp: tStamp, + target: { id: targets[Math.floor(Math.random() * targets.length)] } + }); + } + } + if (md && typeof md.handleEvent === "function") { + tStamp += Math.floor(50 + Math.random() * 100); + md.handleEvent({ + isTrusted: true, + clientX: Math.round(p3.x), + clientY: Math.round(p3.y), + timeStamp: tStamp, + target: { id: "btn-query" } + }); + } + if (clk && typeof clk.handleEvent === "function") { + tStamp += Math.floor(30 + Math.random() * 50); + clk.handleEvent({ + isTrusted: true, + clientX: Math.round(p3.x), + clientY: Math.round(p3.y), + timeStamp: tStamp, + target: { id: "btn-query" } + }); + } + }; + return sandbox; } @@ -75,6 +132,9 @@ async function generateAntiContent(cookies, serverTime, options = {}) { const sandbox = createSandbox(cookies, options); const ctx = vm.createContext(sandbox); const genToken = vm.runInContext(AntiCode, ctx); + if (options.simulateInteraction !== false && typeof sandbox._simulateTrajectory === "function") { + sandbox._simulateTrajectory(); + } return await genToken(serverTime); }