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

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

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

相关推荐
林涧泣6 小时前
【Uniapp-Vue3】使用uni.$emit和$on页面通讯实现发布成功即时更新数据
前端·vue.js·uni-app
林涧泣6 小时前
【Uniapp-Vue3】uniCloud获取数据时限制字段
uni-app
会发光的猪。19 小时前
uniapp使用uv-popup弹出框隐藏底部导航tabbar方法
前端·小程序·uni-app·uv
—丫丫19 小时前
uniapp商城之用户模块【个人信息】
前端·uni-app
spring_007_9991 天前
在uniapp中修改打包路径
前端·uni-app
林涧泣1 天前
【Uniapp-Vue3】获取用户状态栏高度和胶囊按钮高度
前端·vue.js·uni-app
城沐小巷2 天前
springboot+vue+uniapp的校园二手交易小程序
vue.js·spring boot·uni-app
Flyfish20582 天前
uniapp小程序自定义中间凸起样式底部tabbar
前端·小程序·uni-app
林涧泣2 天前
【Uniapp-Vue3】从uniCloud中获取数据
数据库·uni-app