Skip to content

Commit

Permalink
add: cloudflare turnstile invisible and non-interactive demo
Browse files Browse the repository at this point in the history
  • Loading branch information
TRHX committed Feb 3, 2024
1 parent ebb0740 commit 5bf0829
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 94 deletions.
126 changes: 126 additions & 0 deletions docs/.vuepress/components/captcha/turnstile-invisible-challenge.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<template>
<div style="text-align: center">
<br>
<h1>Cloudflare Turnstile Demo <Badge text="Invisible Challenge" type="tip" vertical="top"/></h1>
<br>
<div>
<input type="text" :placeholder="'\ue614 请输入账号'" id="username" maxlength="" class="iconfont cf-input">
</div>
<br>
<div>
<input type="text" :placeholder="'\ue69c 请输入密码'" id="password" maxlength="" class="iconfont cf-input">
</div>
<br>
<div id="cf-captcha">
<p id="cf-wait" class="cf-show">正在加载验证码......<br>(若长时间未加载,请刷新网页并科学访问)</p>
</div>
<br>
<input class="cf-submit2" id="submit" type="submit" value="立即登录">
</div>
</template>
<script>
export default {
mounted() {
const script1 = document.createElement('script');
script1.src = 'https://challenges.cloudflare.com/turnstile/v0/api.js?onload=onloadTurnstileCallback';
// script1.async = true;
script1.defer = true;
document.head.appendChild(script1);
window.onloadTurnstileCallback = function () {
// const cfWaitParagraph = document.querySelector('#cf-wait');
// cfWaitParagraph.textContent = '无感模式加载完毕<br>Invisible Challenge';
$('#cf-wait').html('无感模式加载完毕<br>Cloudflare Turnstile Invisible Challenge')
turnstile.render('#cf-captcha', {
sitekey: '0x4AAAAAAARMkXOUcO6uqu14',
callback: function(token) {
console.log(`Challenge Success ${token}`);
window.turnstileManagedToken = token;
},
});
};
$('#submit').click(function (e) {
if (!window.turnstileManagedToken) {
e.preventDefault();
return alert('请先完成验证!');
}
let result = {};
result['username'] = $('#username').val();
result['password'] = $('#password').val();
result['cf-turnstile-response'] = window.turnstileManagedToken;
$.ajax({
url: 'https://api.spiderapi.cn/turnstile-invisible/login',
type: 'post',
dataType: 'json',
data: result,
success: function (data) {
if (data.status === 'success') {
alert('登录成功!');
} else {
alert('登录失败,请刷新页面重新验证!');
}
}
});
});
},
};
</script>

<style>
h1 span {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
font-weight: normal;
}
.cf-submit2 {
background: #347eff;
border-radius: 4px;
margin-bottom: 20px;
display: inline-block;
width: 300px;
height: 50px;
box-sizing: border-box;
border: 1px solid #ccc;
color: #fff;
cursor: pointer;
font-size: 14px;
line-height: 49px;
}
.cf-submit2:hover {
background: #1A73E8;
}
.cf-input {
display: inline-block;
width: 300px;
padding: 12px;
border: 1px solid #d1d6e0;
background-color: #fff;
position: relative;
cursor: pointer;
-webkit-box-sizing: border-box;
box-sizing: border-box;
border-radius: 3px;
color: #292f3a;
font-size: 14px;
line-height: 20px;
}
#cf-captcha {
width: 300px;
height: 50px;
margin-bottom: 30px;
display: inline-block;
}
#cf-captcha p {
text-align: center;
}
.cf-show {
display: block;
}
#cf-wait {
text-align: left;
color: #666;
margin: 0;
font-size: 14px;
}
</style>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<div style="text-align: center">
<br>
<h1>Cloudflare Turnstile Demo <Badge text="Managed Challenge" type="tip" vertical="top"/></h1>
<br>
<div>
Expand Down Expand Up @@ -55,8 +56,8 @@ export default {
success: function (data) {
if (data.status === 'success') {
alert('登录成功!');
} else if (data.result === 'fail') {
alert('登录失败,请重新验证');
} else {
alert('登录失败,请刷新页面重新验证');
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<template>
<div style="text-align: center">
<br>
<h1>Cloudflare Turnstile Demo <Badge text="Non-Interactive Challenge" type="tip" vertical="top"/></h1>
<br>
<div>
<input type="text" :placeholder="'\ue614 请输入账号'" id="username" maxlength="" class="iconfont cf-input">
</div>
<br>
<div>
<input type="text" :placeholder="'\ue69c 请输入密码'" id="password" maxlength="" class="iconfont cf-input">
</div>
<br>
<div id="cf-captcha">
<p id="cf-wait" class="cf-show">正在加载验证码......<br>(若长时间未加载,请刷新网页并科学访问)</p>
</div>
<br>
<input class="cf-submit2" id="submit" type="submit" value="立即登录">
</div>
</template>
<script>
export default {
mounted() {
const script1 = document.createElement('script');
script1.src = 'https://challenges.cloudflare.com/turnstile/v0/api.js?onload=onloadTurnstileCallback';
// script1.async = true;
script1.defer = true;
document.head.appendChild(script1);
window.onloadTurnstileCallback = function () {
$('#cf-wait').hide();
turnstile.render('#cf-captcha', {
sitekey: '0x4AAAAAAARMZX7AASUic4J4',
callback: function(token) {
console.log(`Challenge Success ${token}`);
window.turnstileManagedToken = token;
},
});
};
$('#submit').click(function (e) {
if (!window.turnstileManagedToken) {
e.preventDefault();
return alert('请先完成验证!');
}
let result = {};
result['username'] = $('#username').val();
result['password'] = $('#password').val();
result['cf-turnstile-response'] = window.turnstileManagedToken;
$.ajax({
url: 'https://api.spiderapi.cn/turnstile-non-interactive/login',
type: 'post',
dataType: 'json',
data: result,
success: function (data) {
if (data.status === 'success') {
alert('登录成功!');
} else {
alert('登录失败,请刷新页面重新验证!');
}
}
});
});
},
};
</script>

<style>
h1 span {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
font-weight: normal;
}
.cf-submit2 {
background: #347eff;
border-radius: 4px;
margin-bottom: 20px;
display: inline-block;
width: 300px;
height: 50px;
box-sizing: border-box;
border: 1px solid #ccc;
color: #fff;
cursor: pointer;
font-size: 14px;
line-height: 49px;
}
.cf-submit2:hover {
background: #1A73E8;
}
.cf-input {
display: inline-block;
width: 300px;
padding: 12px;
border: 1px solid #d1d6e0;
background-color: #fff;
position: relative;
cursor: pointer;
-webkit-box-sizing: border-box;
box-sizing: border-box;
border-radius: 3px;
color: #292f3a;
font-size: 14px;
line-height: 20px;
}
#cf-captcha {
width: 300px;
height: 50px;
margin-bottom: 30px;
display: inline-block;
}
#cf-captcha p {
text-align: center;
}
.cf-show {
display: block;
}
#cf-wait {
text-align: left;
color: #666;
margin: 0;
font-size: 14px;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Demo 样例(随时有可能变化,以实际情况为准):
- cfschl.peet.ws:[https://cfschl.peet.ws/](https://cfschl.peet.ws/)<Badge text="Managed Challenge" type="tip" vertical="middle"/>
- nopecha.com:[https://nopecha.com/demo/cloudflare](https://nopecha.com/demo/cloudflare)<Badge text="Managed Challenge" type="tip" vertical="middle"/>
- gleam.io:[https://gleam.io/0Kbee/rolex-oyster-perpetual](https://gleam.io/0Kbee/rolex-oyster-perpetual)<Badge text="Managed Challenge" type="tip" vertical="middle"/>
- peet.ws:[https://peet.ws/turnstile-test/managed.html](https://peet.ws/turnstile-test/managed.html)<Badge text="Managed Challenge" type="tip" vertical="middle"/> <Badge text="本页使用" type="error" vertical="middle"/>
- peet.ws:[https://peet.ws/turnstile-test/managed.html](https://peet.ws/turnstile-test/managed.html)<Badge text="Managed Challenge" type="tip" vertical="middle"/>
- peet.ws:[https://peet.ws/turnstile-test/non-interactive.html](https://peet.ws/turnstile-test/non-interactive.html)<Badge text="Non-Interactive Challenge" type="tip" vertical="middle"/>
- emload.com:[https://www.emload.com/v2](https://www.emload.com/v2)<Badge text="Non-Interactive Challenge" type="tip" vertical="middle"/>
- peet.ws:[https://peet.ws/turnstile-test/invisible.html](https://peet.ws/turnstile-test/invisible.html)<Badge text="Invisible Challenge" type="tip" vertical="middle"/>
Expand All @@ -34,92 +34,5 @@ Demo 样例(随时有可能变化,以实际情况为准):
:::

<!-- <iframe src="https://peet.ws/turnstile-test/managed.html" height="350px"></iframe> -->
<!--<style>
h1 span {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
font-weight: normal;
}
.gt-submit2 {
background: #347eff;
border-radius: 4px;
margin-bottom: 20px;
display: inline-block;
width: 300px;
height: 50px;
box-sizing: border-box;
border: 1px solid #ccc;
color: #fff;
cursor: pointer;
font-size: 14px;
line-height: 49px;
}
.gt-submit2:hover {
background: #1A73E8;
}
.gt-input {
display: inline-block;
width: 300px;
padding: 12px;
border: 1px solid #d1d6e0;
background-color: #fff;
position: relative;
cursor: pointer;
-webkit-box-sizing: border-box;
box-sizing: border-box;
border-radius: 3px;
color: #292f3a;
font-size: 14px;
line-height: 20px;
}
#gt-captcha {
width: 300px;
height: 50px;
margin-bottom: 30px;
display: inline-block;
}
.gt-show {
display: block;
}
#gt-wait {
text-align: left;
color: #666;
margin: 0;
font-size: 14px;
}
</style>
<div style="text-align: center">
<h1>极验验证 2.0 Demo <Badge text="离线验证" type="tip" vertical="top"/></h1>
<form id="form">
<br>
<div>
<input type="text" :placeholder="'\ue614 请输入账号'" id="username" maxlength="" class="iconfont gt-input">
</div>
<br>
<div>
<input type="text" :placeholder="'\ue69c 请输入密码'" id="password" maxlength="" class="iconfont gt-input">
</div>
<br>
<div id="gt-captcha">
<p id="gt-wait" class="gt-show">正在加载验证码......</p>
</div>
<br>
<input class="gt-submit2" id="submit" type="submit" value="立即登录">
</form>
</div>
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit"></script>
<script>
setTimeout(function() {
turnstile.ready(function () {
$('#gt-wait').hide();
turnstile.render('#example-container', {
sitekey: '0x4AAAAAAARHeKJh3hsrBCbZ',
callback: function(token) {
console.log(`Challenge Success ${token}`);
},
});
});
}, 500);
</script> -->
<!--<div class="cf-turnstile" data-sitekey="0x4AAAAAAARHeKJh3hsrBCbZ" data-theme="light"></div>-->

<captcha-turnstile-managed-challenge></captcha-turnstile-managed-challenge>
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ Demo 样例(随时有可能变化,以实际情况为准):
- nopecha.com:[https://nopecha.com/demo/cloudflare](https://nopecha.com/demo/cloudflare)<Badge text="Managed Challenge" type="tip" vertical="middle"/>
- gleam.io:[https://gleam.io/0Kbee/rolex-oyster-perpetual](https://gleam.io/0Kbee/rolex-oyster-perpetual)<Badge text="Managed Challenge" type="tip" vertical="middle"/>
- peet.ws:[https://peet.ws/turnstile-test/managed.html](https://peet.ws/turnstile-test/managed.html)<Badge text="Managed Challenge" type="tip" vertical="middle"/>
- peet.ws:[https://peet.ws/turnstile-test/non-interactive.html](https://peet.ws/turnstile-test/non-interactive.html)<Badge text="Non-Interactive Challenge" type="tip" vertical="middle"/> <Badge text="本页使用" type="error" vertical="middle"/>
- peet.ws:[https://peet.ws/turnstile-test/non-interactive.html](https://peet.ws/turnstile-test/non-interactive.html)<Badge text="Non-Interactive Challenge" type="tip" vertical="middle"/>
- emload.com:[https://www.emload.com/v2](https://www.emload.com/v2)<Badge text="Non-Interactive Challenge" type="tip" vertical="middle"/>
- peet.ws:[https://peet.ws/turnstile-test/invisible.html](https://peet.ws/turnstile-test/invisible.html)<Badge text="Invisible Challenge" type="tip" vertical="middle"/>

::: right
访问 [Cloudflare 官网](https://www.cloudflare.com/zh-cn/products/turnstile/)
:::

<iframe src="https://peet.ws/turnstile-test/non-interactive.html" height="350px"></iframe>
<!-- <iframe src="https://peet.ws/turnstile-test/non-interactive.html" height="350px"></iframe> -->

<captcha-turnstile-non-interactive-challenge></captcha-turnstile-non-interactive-challenge>
Loading

0 comments on commit 5bf0829

Please sign in to comment.