静默与交互验证码
按业务动作选择验证码。评论、发帖等操作可在提交时静默验证,表单无需验证码组件。
为站点开通 captcha 权限,并在 Rekit 后台「站点来源」登记页面域名。静默模式需要平台提供的 Cloudflare Turnstile Invisible 公开 sitekey,页面域名也需加入该 widget 的域名配置。
浏览器在提交时取 token
html
<script src="https://api.rekitdev.com/api/v1/captcha/silent.js"></script>
<script>
const captcha = ReKitCaptchaSilent.init({
site: "your-slug", siteKey: "YOUR_PUBLIC_SITEKEY"
});
async function submitComment(content) {
const token = await captcha.execute("comment");
const response = await fetch("/api/comments", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ content, captcha_token: token })
});
if (!response.ok) throw new Error("评论提交失败");
}
</script>服务端校验后再写入
http
POST https://api.rekitdev.com/api/v1/captcha/verify
X-Api-Key: <REKIT_SITE_API_KEY>
Content-Type: application/json
{"mode":"silent","action":"comment","token":"<captcha_token>"}业务后端固定 mode 和 action,成功返回 ok: true 才写入。评论可用 comment,发帖可用 create_post。验证绑定站点、页面主机名及动作,token 仅能消费一次,最长有效 5 分钟。失败时保留草稿并提示重试,每次重试获取新的 token。
配置 CSP 时,允许从 Rekit API 域名加载 SDK,并在 script-src 和 frame-src 放行 https://challenges.cloudflare.com。站点隐私政策应引用 Cloudflare Turnstile Privacy Addendum。
交互验证码
需要显示验证码时,使用 /rc/v1/rekit.min.js 渲染交互组件,后端调用同一个校验接口,mode 可省略。托管登录使用交互验证码。完整示例和错误码见《AI 对接 Skill》。