开始
复制一个包含安装步骤和该插件的完整 Markdown 指南的设置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-recaptcha`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/recaptcha/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
安装
安装您可以使用我们的AI辅助设置来安装插件。使用以下命令将Capgo技能添加到您的AI工具中:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-recaptcha` plugin in my project.如果您prefer Manual Setup,安装插件并运行以下命令,按照以下平台特定的说明:
npm install @capgo/capacitor-recaptchanpx cap sync配置站点密钥
标题为“配置站点密钥”的部分在Google Cloud reCAPTCHA中创建平台密钥,然后将它们添加到 capacitor.config.ts.
import type { CapacitorConfig } from '@capacitor/cli';import '@capgo/capacitor-recaptcha';
const config: CapacitorConfig = { appId: 'com.example.app', appName: 'Example', webDir: 'dist', plugins: { Recaptcha: { androidSiteKey: 'ANDROID_SITE_KEY', iosSiteKey: 'IOS_SITE_KEY', webSiteKey: 'WEB_SITE_KEY', enterprise: true, }, },};
export default config;androidSiteKey, iosSiteKey,和 webSiteKey 覆盖共享 siteKey.您也可以直接传递 siteKey 直接传递到 load() 或 execute() 当密钥取决于您的环境时
生成令牌
标题为“生成令牌”import { Recaptcha } from '@capgo/capacitor-recaptcha';
const { token } = await Recaptcha.execute({ action: 'login',});
await fetch('/api/recaptcha-assessment', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ token, action: 'login' }),});execute() 调用 load() 当客户端未准备好时,会自动调用,因此显式预加载步骤是可选的
Web标准 reCAPTCHA v3
Web Standard reCAPTCHA v3(Web标准reCAPTCHA v3)设置 enterprise: false 加载Google的标准Web reCAPTCHA v3脚本
const { token } = await Recaptcha.execute({ siteKey: 'WEB_V3_SITE_KEY', enterprise: false, action: 'signup',});在Android和iOS上,Google的原生移动SDK路径仅限企业版。 enterprise: false 在原生平台上传递会被拒绝,因此不会意外使用标准Web v3密钥。
迁移说明
迁移说明插件接受旧版Cordova选项别名 sitekeyAndroid 和 sitekeyWeb 在调用选项和Capacitor配置中接受 sitekeyIos 和 sitekeyIOS 作为 iOS 迁移别名。 优先使用 Capacitor 配置名称为新 code。
继续 Getting Started
Getting Started 的继续部分如果您正在使用 Getting Started 来规划身份验证和帐户流程,连接它与 使用 @capgo/capacitor-recaptcha 为 native 能力在使用 @capgo/capacitor-recaptcha 中 @capgo/capacitor-social-login 为实现细节在 @capgo/capacitor-social-login 中 @capgo/capacitor-passkey 为实现细节在 @capgo/capacitor-passkey 中 @capgo/capacitor-native-biometric 为 @capgo/capacitor-native-biometric 的实现细节, 双因素认证 为双因素认证的实现细节,