This commit is contained in:
2025-09-10 18:10:40 +08:00
parent 8530e97ab6
commit d50290e8fe
27 changed files with 2025 additions and 3913 deletions

View File

@@ -2,12 +2,7 @@ const express = require('express');
const crypto = require('crypto');
const router = express.Router();
/**
* @swagger
* tags:
* name: Captcha
* description: 验证码API
*/
// 内存存储验证码生产环境建议使用Redis
@@ -107,35 +102,7 @@ function generateCaptchaSVG(text) {
return svg;
}
/**
* @swagger
* /captcha/generate:
* get:
* summary: 生成图形验证码
* tags: [Captcha]
* responses:
* 200:
* description: 成功生成验证码
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* data:
* type: object
* properties:
* captchaId:
* type: string
* description: 验证码唯一ID
* image:
* type: string
* description: Base64编码的SVG验证码图片
* 500:
* description: 服务器错误
*/
router.get('/generate', (req, res) => {
try {
// 生成验证码文本
@@ -169,58 +136,7 @@ router.get('/generate', (req, res) => {
}
});
/**
* @swagger
* /captcha/verify:
* post:
* summary: 验证用户输入的验证码
* tags: [Captcha]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - captchaId
* - captchaText
* properties:
* captchaId:
* type: string
* description: 验证码唯一ID
* captchaText:
* type: string
* description: 用户输入的验证码
* responses:
* 200:
* description: 验证码验证成功
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* message:
* type: string
* example: 验证码验证成功
* 400:
* description: 验证码错误或已过期
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: false
* message:
* type: string
* example: 验证码错误
* 500:
* description: 服务器错误
*/
router.post('/verify', (req, res) => {
try {
const { captchaId, captchaText } = req.body;