uniapp引入cloudflare人机验证
https://developers.cloudflare.com/turnstile/get-started/client-side-rendering/
使用cloudflare需要注册个账号,并添加网站域名
获取站点密钥与密钥
1.index.html引入
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit"></script>
2.登录页面使用 id需要 唯一
<div id="example-container1" style="width: 90%; margin: 0 auto;" data-size="flexible"></div>
//人机验证相关代码
const turnstileToken = ref("");
onMounted(() => {
turnstile.ready(function() {
turnstile.render("#example-container1", {
sitekey: "", //站点密钥
callback: function(token) {
turnstileToken.value = token;
},
});
});
})
3.登录时验证turnstileToken是否存在
登录提交turnstileToken给后端
后端使用的是密钥,用来验证前端传递来的站点密钥
使用的网站域名要与添加的网站域名一致;