zhitong.yu
2025-02-06 b8422a40b61a308d102af1e4d9cea24fa461e163
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
 
    <link  rel="stylesheet" href="/css/tac.css">
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="/js/tac.min.js"></script>
 
    <style>
        ul li {
            list-style: none;
        }
        * {
            margin: 0;
            padding: 0;
        }
        .top{
            overflow: auto;
        }
        .top li:hover{
            cursor: pointer;
        }
        .top li{
            float: left;
            height: 40px;
            width: 120px;
            margin-right: 5px;
            line-height: 40px;
            text-align: center;
            background-color: #409eff;
            color: #fff;
            font-size: 15px;
            box-sizing: border-box;
            border: 1px solid #409eff;
        }
        .captcha-iframe {
            width: 300px;
            height: 320px;
            border: none;
        }
        .after {
            color: #88949d;
        }
    </style>
</head>
 
<body>
<div>
    <ul class="top">
        <li onclick="openCaptcha('RANDOM')">随机</li>
        <li onclick="openCaptcha('SLIDER')">滑块验证码</li>
        <li onclick="openCaptcha('ROTATE')">旋转验证码</li>
        <li onclick="openCaptcha('CONCAT')">滑动还原验证码</li>
        <li onclick="openCaptcha('WORD_IMAGE_CLICK')">点选验证码</li>
    </ul>
    <div id="captcha-box"></div>
</div>
<script>
    let globalTAC;
    const config = {
        // 生成接口
        requestCaptchaDataUrl: "/gen?type=RANDOM",
        // 验证接口
        validCaptchaUrl: "/check",
        // 验证码绑定的div块
        bindEl: "#captcha-box",
        // 验证成功回调函数
        validSuccess: (res, c, tac) => {
            // 销毁验证码服务
            tac.destroyWindow();
            // 调用登录方法
            this.login(res.data.id);
        }
    }
    const style = {
        // 配置样式, logoURL地址
        logoUrl: "/images/logo.png"
    }
    function login(token) {
        // 在执行登录时,将验证码token传过去进行二次校验
        $.get("/check2?id=" + token,  (res) => {
            alert("登录成功")
        })
    }
    $(function () {
        // 创建 TAC 启动验证码服务
        globalTAC = new TAC(config, style).init();
    })
    function openCaptcha(type) {
        if (globalTAC) {
            globalTAC.destroyWindow();
        }
        config.requestCaptchaDataUrl = "/gen?type="+type
        globalTAC = new TAC(config, style).init();
    }
</script>
</body>
</html>