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给后端

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

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

相关推荐
2501_9151063216 小时前
iOS数据采集技术详解:从性能监控到崩溃分析的全链路实践
android·ios·小程序·https·uni-app·iphone·webview
我爱写代码i1 天前
AI对话绘画数字人源码 - uniapp前端
前端·人工智能·uni-app
ModyQyW1 天前
vite-plugin-uni-pages 更新了什么
前端·uni-app
2501_915918412 天前
Flutter项目配置iOS混淆的详细步骤与工具推荐
android·flutter·ios·小程序·uni-app·cocoa·iphone
梦曦i2 天前
create-uni-app v1.2.0:交互体验优化
前端·uni-app
lhldsg2 天前
智慧场馆解决方案小程序开发实战:从架构设计到部署指南
java·小程序·uni-app
skiyee2 天前
🚀 用 17 行代码给 UniApp 加上全局登录拦截
前端·uni-app
Mark108592 天前
【踩坑】Uni-app微信小程序自定义组件在 Flex 布局中未铺满整行
微信小程序·小程序·uni-app
梦曦i3 天前
create-uni-app v1.1.0:结构化生成,工程骨架更规范
前端·uni-app
2501_916007474 天前
Flutter与游戏App加固避坑指南:如何为混合开发与高交互应用选对安全方案?
安全·flutter·游戏·ios·小程序·uni-app·iphone