let currentCaptcha = ""; // ======================= // 🎯 生成验证码 // ======================= function generateCaptcha() { const canvas = document.getElementById("captchaCanvas"); const ctx = canvas.getContext("2d"); const width = 120; const height = 40; canvas.width = width; canvas.height = height; ctx.clearRect(0, 0, width, height); // 背景 ctx.fillStyle = "#f5f5f5"; ctx.fillRect(0, 0, width, height); // 字符 const chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"; currentCaptcha = ""; for (let i = 0; i < 5; i++) { const char = chars[Math.floor(Math.random() * chars.length)]; currentCaptcha += char; ctx.font = "bold 20px Arial"; ctx.fillStyle = "#222"; const x = 10 + i * 20; const y = 25 + Math.random() * 5; const angle = (Math.random() - 0.5) * 0.5; ctx.save(); ctx.translate(x, y); ctx.rotate(angle); ctx.fillText(char, 0, 0); ctx.restore(); } // 干扰线 for (let i = 0; i < 2; i++) { ctx.strokeStyle = "#999"; ctx.beginPath(); ctx.moveTo(Math.random() * width, Math.random() * height); ctx.lineTo(Math.random() * width, Math.random() * height); ctx.stroke(); } // 干扰点 for (let i = 0; i < 15; i++) { ctx.fillStyle = "#ccc"; ctx.fillRect(Math.random() * width, Math.random() * height, 1, 1); } } // ======================= // 🎯 验证验证码(替代 checking_icaptcha) // ======================= function checking_icaptcha() { const input = document.getElementById("secure").value; if (!input) return "empty"; if (input.toUpperCase() === currentCaptcha) { return "ok=True"; } else { generateCaptcha(); document.getElementById("secure").value = ""; return "Wrong Code"; } } // ======================= // 🎯 登录提交(保留你原逻辑) // ======================= async function login_submit() { let validate = await checking_icaptcha(); if (validate.trim() === "ok=True") { $('#submit_login').submit(); } else { alert("Secure Code Invalid"); } }