From 7d32ef97c0a570e4e26730bd0081f27373a67163 Mon Sep 17 00:00:00 2001 From: Default User Date: Wed, 4 Feb 2026 16:01:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=8C=E7=BB=B4=E7=A0=81?= =?UTF-8?q?=E5=90=88=E9=9B=86=E9=A1=B5=E9=9D=A2=E5=92=8C=E7=9B=B8=E5=85=B3?= =?UTF-8?q?API=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- invite.html | 1 + qr-collection.html | 428 +++++++++++++++++++++++++++++++++++++++++++++ server.js | 62 ++++++- 3 files changed, 486 insertions(+), 5 deletions(-) create mode 100644 qr-collection.html diff --git a/invite.html b/invite.html index a71f077..2bfd123 100644 --- a/invite.html +++ b/invite.html @@ -186,6 +186,7 @@
+
diff --git a/qr-collection.html b/qr-collection.html new file mode 100644 index 0000000..80e8e38 --- /dev/null +++ b/qr-collection.html @@ -0,0 +1,428 @@ + + + + + + 二维码合集 + + + +
+
+

二维码合集

+
+ +
+
+ +
+

筛选

+
+ + + +
+
+ +
+
+ 空状态 +

暂无二维码

+

请先生成邀请二维码

+
+
+ +
+ + +
+ + +
+ + + + \ No newline at end of file diff --git a/server.js b/server.js index d92b9f4..238b5fa 100644 --- a/server.js +++ b/server.js @@ -90,11 +90,12 @@ const server = http.createServer(async (req, res) => { const formData = new URLSearchParams(body); const userName = formData.get('userName'); const password = formData.get('password'); + const projectName = formData.get('projectName'); - console.log('接收到的登录请求:', { userName }); + console.log('接收到的登录请求:', { userName, projectName }); // 验证输入 - if (!userName || !password) { + if (!userName || !password || !projectName) { res.writeHead(400, { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*', @@ -103,7 +104,7 @@ const server = http.createServer(async (req, res) => { }); res.end(JSON.stringify({ success: false, - error: '请输入用户名和密码' + error: '请输入用户名、密码和职位名称' })); return; } @@ -117,7 +118,7 @@ const server = http.createServer(async (req, res) => { // 验证用户名、密码和职位名称 const [loginRows] = await userloginPool.execute( 'SELECT * FROM login WHERE userName = ? AND password = ? AND projectName = ?', - [userName, password, formData.get('projectName')] + [userName, password, projectName] ); if (loginRows.length === 0) { @@ -129,7 +130,7 @@ const server = http.createServer(async (req, res) => { }); res.end(JSON.stringify({ success: false, - error: '用户名或密码错误' + error: '用户名、密码或职位名称错误' })); return; } @@ -208,6 +209,57 @@ const server = http.createServer(async (req, res) => { return; } + // 获取二维码合集接口 + if (req.method === 'GET' && req.url === '/getQrCollection') { + try { + // 从数据库获取所有的合格证信息 + const [rows] = await pool.execute( + 'SELECT inviter, inviter_phone as inviterPhone, projectName as inviterProjectName, sessionId, DATE_FORMAT(issueDate, "%Y-%m-%d %H:%i:%s") as createdAt FROM certificate GROUP BY sessionId ORDER BY issueDate DESC' + ); + + // 生成二维码URL列表 + const qrCodes = rows.map(row => { + // 生成包含会话ID的URL + const url = `http://8.137.125.67:3008/certificate.html?sessionId=${encodeURIComponent(row.sessionId)}&inviter=${encodeURIComponent(row.inviter)}&inviterPhone=${encodeURIComponent(row.inviterPhone)}&inviterProjectName=${encodeURIComponent(row.inviterProjectName)}`; + + return { + inviter: row.inviter, + inviterPhone: row.inviterPhone, + inviterProjectName: row.inviterProjectName, + sessionId: row.sessionId, + createdAt: row.createdAt, + url: url + }; + }); + + console.log('获取二维码合集成功,数量:', qrCodes.length); + + res.writeHead(200, { + 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'POST, GET, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type' + }); + res.end(JSON.stringify({ + success: true, + qrCodes: qrCodes + })); + } catch (error) { + console.error('获取二维码合集失败:', error.message); + res.writeHead(500, { + 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'POST, GET, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type' + }); + res.end(JSON.stringify({ + success: false, + error: '获取二维码合集失败,请重试' + })); + } + return; + } + // 处理GET请求,获取最新的合格证信息 if (req.method === 'GET' && req.url.startsWith('/getLatestCertificate')) { try {