---
title: Web SDK
---
# Web SDK
Web SDK hỗ trợ mọi trình duyệt hiện đại với nhiều cách tích hợp.
::: tip Xem nó hoạt động trong 30 giây
[demo-v1.captcha.la](https://demo-v1.captcha.la) — HTML + PHP thuần, giấy phép MIT, có thể view-source mọi trang.
- [popup.html](https://demo-v1.captcha.la/popup.html) — chế độ popup
- [float.html](https://demo-v1.captcha.la/float.html) — widget nổi
- [bind.html](https://demo-v1.captcha.la/bind.html) — gắn vào nút
- [inline.html](https://demo-v1.captcha.la/inline.html) — nhúng trong dòng
- [server-token.html](https://demo-v1.captcha.la/server-token.html) — token do máy chủ phát hành (chống replay)
:::
## Bắt đầu nhanh
```html
```
## Cài đặt
### CDN
```html
```
### NPM
```bash
npm install captchala
# or framework wrappers
npm install @captcha-la/vue
npm install @captcha-la/react
```
```js
import Captchala from 'captchala';
import 'captchala/dist/captchala.css';
```
## Các chế độ
### Chế độ popup
```js
Captchala.init({ appKey: 'YOUR_APP_KEY', product: 'popup', action: 'login' })
.bindTo('#login-btn')
.onSuccess(res => sendToBackend(res.token));
```
### Chế độ nổi
```js
Captchala.init({ appKey: 'YOUR_APP_KEY', product: 'float', action: 'browse' })
.appendTo('#captcha-container')
.onSuccess(res => sendToBackend(res.token));
```
### Chế độ bind
```js
Captchala.init({ appKey: 'YOUR_APP_KEY', product: 'bind', action: 'login' })
.bindTo('#submit-button')
.onSuccess(res => submitForm(res.token)); // fires only after challenge passes
```
### Chế độ nhúng
```js
Captchala.init({ appKey: 'YOUR_APP_KEY', product: 'embed', action: 'register' })
.appendTo('#captcha-container')
.onSuccess(res => sendToBackend(res.token));
```
## Tùy chọn phổ biến
| Tham số | Kiểu | Mặc định | Mô tả |
| --- | --- | --- | --- |
| `appKey` | string | — | Application Key (bắt buộc) |
| `product` | string | `popup` | Chế độ hiển thị: popup | float | embed | bind |
| `action` | string | `default` | Ngữ cảnh nghiệp vụ (ví dụ: login, register, pay). Server áp dụng chính sách bảo mật khác nhau theo từng scene. |
| `lang` | string | `en` | Ngôn ngữ được hỗ trợ: zh-CN / zh-TW / en / ja / ko / ms / vi / id |
| `serverToken` | string | — | Token dùng một lần (sct_xxx) do server của bạn cấp. Rất nên dùng trong production để tránh lạm dụng refresh challenge không giới hạn. |
| `onServerTokenExpired` | `() => Promise` | — | Được gọi khi serverToken hết hạn; trả về token mới để SDK tiếp tục mà không làm gián đoạn luồng. |
| `enableVoice` | boolean | `true` | Hiển thị điểm vào audio captcha (hỗ trợ trợ năng cho người khiếm thị). |
## Xác thực phía máy chủ
After `onSuccess`, send `res.token` (prefix `pt_`) to your own backend, then validate it server-side:
```bash
POST https://apiv1.captcha.la/v1/validate
X-App-Key: YOUR_APP_KEY
X-App-Secret: YOUR_APP_SECRET
Content-Type: application/json
{ "pass_token": "" }
```
Xem [Tham chiếu API](./api-reference) để biết endpoint xác thực đầy đủ.