You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

开发Kolotibablo多账号打码软件:解决验证码超时消失问题

解决方案

核心逻辑

网站的验证码消失机制大概率是检测输入框的用户交互事件(而非单纯的value值变更),你直接修改输入框value的操作无法触发网站的活跃检测。需要模拟真实的输入动作,同时定时维持输入状态,让网站判定用户一直在操作。

具体实现步骤

1. 模拟真实输入事件(替代直接修改value)

直接赋值输入框value不会触发input、keyup等核心交互事件,必须手动触发这些事件才能让网站感知到输入行为。可以通过注入JS脚本实现:

function simulateRealInput(inputId, text) {
    const input = document.getElementById(inputId);
    if (!input) return;
    
    // 清空输入框
    input.value = '';
    // 逐个字符输入,模拟真实打字节奏
    text.split('').forEach((char, index) => {
        setTimeout(() => {
            input.value += char;
            // 触发input事件(网站核心检测的事件之一)
            input.dispatchEvent(new Event('input', { bubbles: true }));
            // 触发keyup事件,还原真实输入流程
            input.dispatchEvent(new Event('keyup', { bubbles: true }));
        }, 100 * index); // 每个字符间隔100ms,避免被判定为机器人
    });
}

在JavaFX中调用该函数:

webView.getWebEngine().executeScript("simulateRealInput('guesstext', 'RANDOM')");

2. 定时维持活跃状态

如果需要长时间保持验证码不消失,每隔1-2秒触发一次微小的输入动作(比如追加空格再删除),同时触发交互事件:

let keepAliveTimer;

function startKeepAlive(inputId) {
    // 先停止之前的定时任务(防止重复启动)
    if (keepAliveTimer) clearInterval(keepAliveTimer);
    
    keepAliveTimer = setInterval(() => {
        const input = document.getElementById(inputId);
        if (!input) return;
        
        const currentVal = input.value;
        // 追加空格再删除,模拟输入动作
        input.value = currentVal + ' ';
        input.dispatchEvent(new Event('input', { bubbles: true }));
        setTimeout(() => {
            input.value = currentVal;
            input.dispatchEvent(new Event('input', { bubbles: true }));
        }, 50);
    }, 1500); // 每1.5秒执行一次,平衡活跃检测和反爬风险
}

function stopKeepAlive() {
    if (keepAliveTimer) clearInterval(keepAliveTimer);
}

在JavaFX中,页面加载完成后注入脚本并启动维持:

webView.getWebEngine().getLoadWorker().stateProperty().addListener((obs, oldState, newState) -> {
    if (newState == Worker.State.SUCCEEDED) {
        // 注入上面的JS函数
        webView.getWebEngine().executeScript("/* 粘贴simulateRealInput、startKeepAlive、stopKeepAlive的代码 */");
        // 启动活跃维持
        webView.getWebEngine().executeScript("startKeepAlive('guesstext')");
    }
});

3. 自动检测验证码输入框

如果验证码是动态加载的(页面初始不存在),可以用DOM监听自动检测输入框出现并启动维持:

const domObserver = new MutationObserver((mutations) => {
    mutations.forEach((mutation) => {
        if (mutation.addedNodes.length > 0) {
            const input = document.getElementById('guesstext');
            if (input) {
                startKeepAlive('guesstext');
                domObserver.disconnect(); // 找到输入框后停止监听,节省资源
            }
        }
    });
});

// 监听整个页面的DOM变化
domObserver.observe(document.body, { childList: true, subtree: true });

将这段代码和前面的JS函数一起注入WebView即可。

额外注意事项

  • 不要设置过短的定时间隔,容易被网站判定为机器人,1-2秒是比较安全的区间。
  • 完成验证码输入后,务必调用stopKeepAlive()停止定时任务,避免不必要的资源消耗。
  • 如果上述方法无效,可以在定时任务中额外模拟鼠标移动到输入框的动作:
function simulateMouseMove(element) {
    const rect = element.getBoundingClientRect();
    const moveEvent = new MouseEvent('mousemove', {
        bubbles: true,
        clientX: rect.x + 10,
        clientY: rect.y + 10
    });
    element.dispatchEvent(moveEvent);
}

把这个动作加入到startKeepAlive的定时逻辑中即可。

内容的提问来源于stack exchange,提问作者autosync

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 09:00:50