English | 简体中文
A TypeScript-based CAPTCHA generation module that provides a simple, reliable, and easy-to-integrate verification solution.
- 🚀 Developed with TypeScript, providing complete type support
- 🎨 Supports multiple CAPTCHA styles and custom configurations
- 🔒 Secure and reliable verification mechanism
- 🔧 Easy to integrate and use
- ⚡️ Built with Webpack 4 for stability
- 📦 Supports modular import
- 🛠 Provides complete development environment
mlVocdeProject/
├── vcode/ # Frontend CAPTCHA module
│ ├── src/ # Source code directory
│ │ ├── api/ # API interfaces
│ │ ├── config/ # Configuration files
│ │ ├── enum/ # Enum definitions
│ │ ├── interface/ # Interface definitions
│ │ ├── static/ # Static resources
│ │ ├── utils/ # Utility functions
│ │ ├── main.ts # Entry file
│ │ └── global.d.ts # Global type declarations
│ ├── webpack.config.js # Webpack configuration
│ └── tsconfig.json # TypeScript configuration
└── server/ # Backend service
- Node.js >= 16.0.0
- Yarn >= 1.22.0
- Clone the project
git clone git@github.com:mingle98/machine-vcode-ts.git
cd machine-vcode-ts- Install dependencies
cd mlVocdeProject/vcode
yarn install- Start development server
yarn serveServer will start at http://localhost:3000
- Build for production
yarn buildyarn serve: Start development serveryarn build: Build for productionyarn dev: Start in development mode (without auto-opening browser)
src/api: API interface encapsulationsrc/config: Project configuration filessrc/enum: Enum type definitionssrc/interface: TypeScript interface definitionssrc/static: Static resource filessrc/utils: Utility function collection
webpack.config.js: Webpack build configurationtsconfig.json: TypeScript compilation configurationtslint.json: TypeScript code standard configuration
- Import the built file:
<script src="path/to/api/built.js"></script>Note: If you want to use the online built.js, please refer to this documentation: https://luckycola.com.cn/public/docs/shares/sdk/ml-vcodes.html
- Initialize CAPTCHA:
<div id="myVcodeContainer"></div>
<script>
window.onload = function() {
const mlVcode = boostrapFn({
// CAPTCHA type: supports click verification(clickVcode), rotate verification(roateVcode), and puzzle verification(puzzleVcode)
vcodeType: ['puzzleVcode', 'clickVcode', 'roateVcode'],
// Mode: dialog(popup mode) or empty(embedded mode)
mode: 'dialog',
// CAPTCHA container ID
container: '#myVcodeContainer',
// Enable server verification (default false)
serverVerify: false,
// Success callback
successFn: (rsp) => {
console.log('Verification successful');
},
// Failure callback
failFn: (rsp) => {
console.log('Verification failed');
}
}).render();
}
</script>clickVcodeConfig: {
// CAPTCHA text
fontList: 'abcdefghijklmnopqrstuvwxyz',
// Background image list (URL array)
imgList: []
}puzzleVcodeConfig: {
// Puzzle shape: 'puzzle' | 'rect' | 'round' | 'triangle'
puZshape: 'puzzle',
// Operation tip
puZoperateTip: 'Please drag to complete the puzzle',
// Background image list (URL array)
puZimgList: []
}roateVcodeConfig: {
// Operation tip
roateOperateTip: 'Please drag to rotate the image upright',
// Image list (URL array)
roateimgList: []
}customTxt: {
// Header configuration
headerConfig: {
text: 'Security Verification',
url: 'https://your-website.com'
},
// Footer configuration
footerConfig: {
text: 'About Us',
url: 'https://your-website.com/about'
}
}If server verification is needed (serverVerify = true), you can customize the verification interface through the following configuration:
collectionDataOptios: {
// Enable custom server verification interface
open: true,
// Data reporting interface (POST)
postUrl: '/api/mlvcode',
// Data reporting callback
postUrlFn: function(resData) {
console.log('Data reporting response:', resData);
},
// Initialization interface (POST)
initpostUrl: '/api/initmlvcode',
// Initialization interface callback
postInitUrlFn: function(initSuccessHook, resData) {
if (resData.data.code === 0) {
initSuccessHook();
}
},
// Verification interface (POST)
verifypostUrl: '/api/verify',
// Verification interface callback
verifypostUrlFn: function(resData, verifySuccessHook, verifyFailHook) {
if (resData.data.code === 0) {
verifySuccessHook();
} else {
verifyFailHook();
}
},
// Request parameter pre-processing
apiDataPreFn: function(apiData) {
// You can encrypt request parameters here
return apiData;
}
}Visit Online Demo to see the CAPTCHA in action.
We welcome community contributions! If you'd like to contribute to the project, please:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Ensure code complies with TypeScript standards
- Add necessary comments and documentation
- Ensure all tests pass
- Follow existing code style
- v1.0.0 - Initial Release
- Basic CAPTCHA generation functionality
- TypeScript support
- Webpack 4 build support
This project is licensed under the MIT License - see the LICENSE file for details
