-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo.html
45 lines (40 loc) · 1.46 KB
/
demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>One Captcha Demo</title>
<script src="https://onecaptcha.us.kg/0/api_test.js"></script>
</head>
<body>
<div id="one-captcha" data-callback="CaptchaSuccess" data-lang="kr"></div>
<script>
async function CaptchaSuccess(token) {
// 获取名为 'OneCaptchaToken' 的 cookie 值
function getTokenCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
}
// 获取 OneCaptchaToken 的 cookie
const cookieToken = getTokenCookie('OneCaptchaToken');
// 哈希化 token
async function hashToken(token) {
const encoder = new TextEncoder();
const dataBuffer = encoder.encode(token);
const hashBuffer = await crypto.subtle.digest('SHA-512', dataBuffer);
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
return hashHex;
}
// 比较 token 和 cookieToken 是否相同
const hashedToken = await hashToken(token); // 对传入的token进行哈希
if (hashedToken === cookieToken) {
alert('Token matches the cookie!');
} else {
alert('Token does not match the cookie.');
}
}
</script>
</body>
</html>