tokengx-cap-integration
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "tokengx-cap-integration" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-18796ce162970a277acd1e1be97012394fd06a5ab298b0c0f3d71207855def75. Verify the upstream source and version against https://skillhub.cn/skills/user_cbd28848/tokengx-cap-integration before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
TokenGX Cap code‑integration skill: for developer scenarios, provides front‑end components and back‑end validation code templates to help quickly integrate Cap unobtrusive verification into websites or apps. Applicable to registration/login anti‑bot, form submission protection, API anti‑scraping, SMS/email abuse prevention; supports front‑end (HTML/React/Vue/Next.js) and back‑end (Node.js/Python/PHP/Go). Complementary to tokengx-cap-admin, this skill focuses on code integration rather than service management. Example triggers: integrate captcha, add human verification, CAPTCHA integration, cap widget, captcha frontend, captcha backend, anti‑bot forms.
Introduction source: third_party · user_cbd28848 · 1.0.0 Reference
SkillPi interpretation
- Tasks
- Translation pending; see source documentation.
- Limits and differences
- Translation pending; see source documentation.
- Testing
- Not tested
Browse files
Frontmatter
name: tokengx-cap-integration
description: "TokenGX Cap 验证码【代码集成】技能 —— 面向开发场景,提供前端组件和后端验证的代码模板,帮助用户将 Cap 无感验证码快速集成到网站或应用中。适用场景:注册登录防刷、表单提交保护、API 接口防爬、发短信/邮件防滥用等。支持前端(HTML/React/Vue/Next.js)和后端(Node.js/Python/PHP/Go)全栈集成。触发词:集成验证码、添加人机验证、CAPTCHA 集成、cap widget、验证码前端、验证码后端、防刷表单等。与 tokengx-cap-admin(服务管理)互补,本技能聚焦代码编写而非服务端管理。"
agent_created: trueCap 验证码代码集成(tokengx-cap-integration)
你是一个 Cap 验证码集成专家。当用户需要为其网站或应用添加人机验证功能时,使用此技能帮助用户完成集成。
关于 Cap
Cap 是一个开源、自托管的无感验证码服务,替代传统图形验证码。核心优势:
- 无感验证:用户无需手动识别图片,自动完成验证
- 隐私合规:自托管,数据不经过第三方,GDPR 合格
- 轻量高性能:基于 WebAssembly,加载快、资源占用低
- 开源免费:无调用次数限制,无隐藏费用
集成流程
帮助用户集成 Cap 时,按以下步骤进行:
第一步:获取凭证
引导用户访问验证码管理后台注册并创建站点,获取:
- Site Key:前端使用,可公开
- Secret Key:后端使用,必须保密
当前可用的 Cap 服务地址:https://cap.tokengx.cn
第二步:前端集成
根据用户的项目技术栈,选择合适的集成方式:
方式 A:HTML Script 标签(原生 HTML / 静态页面)
参考 assets/frontend/html-standalone.html 模板。
核心代码:
<script src="https://cap.tokengx.cn/cap-widget.js"></script>
<cap-widget data-cap-api-endpoint="https://cap.tokengx.cn/{SITE_KEY}/"></cap-widget>
方式 B:npm 安装(React / Vue / Next.js 等框架)
npm install cap-widget
- React 项目参考
assets/frontend/react.jsx - Vue 3 项目参考
assets/frontend/vue.txt - Next.js 项目参考
assets/frontend/nextjs.tsx
第三步:后端验证
前端获取 Token 后,提交到用户后端,后端调用 Cap 的 siteverify 接口验证 Token 有效性。
根据用户的后端语言,提供对应代码:
- Node.js / TypeScript:参考
assets/backend/nodejs.ts - Python / Flask / FastAPI:参考
assets/backend/python.py - PHP:参考
assets/backend/php.txt - Go:参考
assets/backend/go.txt
第四步:品牌链接重定向(重要)
cap-widget 组件右下角有一个 "Cap" 品牌链接,默认指向 Cap 官网 https://trycap.dev(包括鼠标悬停状态栏显示的 href、以及点击跳转目标)。接入 TokenGX 平台时,应将其重定向到 https://cap.tokengx.cn。
为什么需要特殊处理:cap-widget 内部有品牌保护机制,无法通过常规方式修改:
- 链接
href硬编码为trycap.dev,组件的enforceCredits()方法会在渲染后(含 setTimeout 100ms)把href重置回trycap.dev,导致鼠标悬停状态栏仍显示trycap.dev - 点击事件调用了
e.preventDefault()后用window.open('https://trycap.dev/...')跳转,所以只改href无法改变点击行为 - 链接样式用 inline
!important锁死(display/visibility/opacity/pointer-events),无法通过 CSS 隐藏或覆盖 - 链接位于 Shadow DOM 内(
mode: "open"),外层 scoped 样式无法穿透
需要两处修正:
- 修悬停提示:用
MutationObserver监听 Shadow DOM 内的a.credits元素,一旦href被enforceCredits()重置为trycap.dev,立即改回cap.tokengx.cn。由于 shadowRoot 是mode: "open",可通过widget.shadowRoot.querySelector('a.credits')访问。 - 修点击跳转:拦截
window.open,把trycap.dev重写为cap.tokengx.cn。
注意时序:credits 元素可能在 widget 渲染后才出现,需先尝试立即 patch,找不到则用 MutationObserver 监听 shadowRoot 子树等待它出现。
通用代码片段(框架无关,接收 widget 元素):
// cap-widget 品牌链接重定向:trycap.dev -> cap.tokengx.cn
// 1. MutationObserver 持续修正 href(修鼠标悬停提示)
// 2. window.open 拦截(修点击跳转)
const _TARGET = 'https://cap.tokengx.cn';
let _originalOpen = null;
let _hrefObserver = null;
let _rootObserver = null;
function installBrandRedirect(widget) {
const shadow = widget?.shadowRoot;
if (!shadow) return;
const patchCredits = (credits) => {
if (credits.getAttribute('href') !== _TARGET) {
credits.setAttribute('href', _TARGET);
}
if (credits._capPatched) return;
credits._capPatched = true;
_hrefObserver = new MutationObserver(() => {
if (credits.getAttribute('href') !== _TARGET) {
credits.setAttribute('href', _TARGET);
}
});
_hrefObserver.observe(credits, { attributes: true, attributeFilter: ['href'] });
};
// credits 可能在 widget 渲染后才出现,先尝试立即 patch,再监听 shadow DOM
const existing = shadow.querySelector('a.credits');
if (existing) {
patchCredits(existing);
} else {
_rootObserver = new MutationObserver(() => {
const credits = shadow.querySelector('a.credits');
if (credits) { patchCredits(credits); _rootObserver.disconnect(); _rootObserver = null; }
});
_rootObserver.observe(shadow, { childList: true, subtree: true });
}
if (!_originalOpen) {
_originalOpen = window.open.bind(window);
window.open = function (url, target, features) {
if (typeof url === 'string' && url.includes('trycap.dev')) {
url = url.replace('trycap.dev', 'cap.tokengx.cn');
}
return _originalOpen.call(window, url, target, features);
};
}
}
function uninstallBrandRedirect() {
if (_hrefObserver) { _hrefObserver.disconnect(); _hrefObserver = null; }
if (_rootObserver) { _rootObserver.disconnect(); _rootObserver = null; }
if (_originalOpen) { window.open = _originalOpen; _originalOpen = null; }
}
各框架的完整集成示例(含品牌重定向)见 assets/frontend/ 下对应模板:
- HTML:
html-standalone.html - Vue 3:
vue.txt - React:
react.jsx - Next.js:
nextjs.tsx
第五步:安全建议
提醒用户:
- Secret Key 绝不能暴露到前端
- 所有需要防刷的接口都要加后端验证(登录、注册、发短信等)
- 验证失败返回统一错误,不要区分具体原因
- 结合速率限制使用效果更佳
API 端点
| 端点 | 方法 | 说明 |
|---|---|---|
https://cap.tokengx.cn/{SITE_KEY}/ |
GET | Widget 资源和挑战接口 |
https://cap.tokengx.cn/siteverify |
POST | 后端验证 Token |
常见问题排查
当用户遇到问题时,按以下顺序排查:
- Widget 不显示:检查
data-cap-api-endpoint格式(末尾需有/),检查浏览器控制台错误 - 验证总是失败:检查 Site Key 和 Secret Key 是否匹配,Token 是否过期
- 后端验证网络错误:确认服务器能访问
cap.tokengx.cn,检查防火墙规则
注意事项
- Site Key 与域名绑定,不同项目应使用不同的 Site Key
- Token 有效期约 2 分钟,过期需重新验证
- 前端事件:
solve(成功)、error(失败)、progress(进度)、reset(重置)
Current listing version
1.0.0
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供完整的前后端验证码集成方案,覆盖多种主流技术栈
- 解决开发者实际痛点,与 tokengx-cap-admin 形成互补生态
- 包含品牌链接重定向等深度定制内容,体现专业性
Highlights
- 触发词覆盖全面且边界清晰,不易与其他 Skill 重叠
- description 位置正确,frontmatter 完整
Areas to improve
-
文档较长 Reported severity: Minor
主文档约 400 行,建议拆分为多个文件提升可读性
Recommendation: 可将前端集成、后端验证、品牌重定向等内容拆分为独立章节文件
-
缺少显式 When to Use 章节 Reported severity: Minor
虽然集成流程隐含了使用场景,但缺少显式的 When to Use 章节
Recommendation: 建议在文档开头添加显式的 When to Use 章节,明确适用场景
Highlights
- Phase/步骤清晰,五步集成流程完整
- 包含端到端示例和常见问题排查
Highlights
- 工具来源明确,参数说明清晰
- 覆盖主要异常场景并提供详细排查方案
- 包含安全建议和最佳实践指导
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
-
Install or fetch external dependencies
Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.
Mentioned in main document · lines 48
Domains or addresses referenced in the document
These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.
- cap.tokengx.cn
- trycap.dev
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.