uniapp引入cloudflare人机验证

https://developers.cloudflare.com/turnstile/get-started/client-side-rendering/

使用cloudflare需要注册个账号,并添加网站域名

获取站点密钥与密钥

1 .index.html引入

javascript 复制代码
 <script src="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit"></script>

2.登录页面使用 id需要 唯一

html 复制代码
<div id="example-container1" style="width: 90%; margin: 0 auto;" data-size="flexible"></div>
javascript 复制代码
	//人机验证相关代码
	const turnstileToken = ref("");
	onMounted(() => {
		turnstile.ready(function() {
			turnstile.render("#example-container1", {
				sitekey: "",   //站点密钥
				callback: function(token) {
					turnstileToken.value = token;
				},
			});
		});
	})

3 .登录时验证turnstileToken是否存在

登录提交turnstileToken给后端

后端使用的是密钥,用来验证前端传递来的站点密钥

使用的网站域名要与添加的网站域名一致;

相关推荐
Geek_Vison12 小时前
2026 跨端框架横评:FinClip、Taro、uni-app、Remax、mPaaS 五款工具技术+业务双维度测评
小程序·uni-app·taro·mpaas·小程序容器
RuoyiOffice16 小时前
从 0 到 1 搭建 RuoyiOffice:30 分钟跑通后端+前端+移动端
前端·spring boot·uni-app·开源·oa·ruoyioffice·hrm
Geek_Vison17 小时前
APP集成了50多个小程序后,如何搭建一个小程序管理平台来管理这些小程序~
小程序·uni-app·apache·mpaas·小程序容器
梦曦i1 天前
uni-router v1.1.1发布:守卫超时保护+路由监听
前端·uni-app
梦曦i1 天前
全面解析uni-router v1.2.0功能
前端·uni-app
不如摸鱼去1 天前
Wot UI 2.1.0 发布:ConfigProvider 全局配置能力升级
ui·小程序·uni-app
PedroQue992 天前
uni-router:uni-app路由管理新选择
前端·uni-app
这是个栗子2 天前
微信小程序开发(九)- uni-app微信小程序商城
微信小程序·小程序·uni-app·vue·vuex
中犇科技2 天前
2026商城APP开发公司 TOP5(电商垂直版)
uni-app
扁豆的主人2 天前
Uniapp如何构建和部署
uni-app