<?php
error_reporting(0);
$qq = isset($_GET['qq'])?trim($_GET['qq']):null;
$hkurl = isset($_GET['hkurl'])?trim($_GET['hkurl']):null;
$orderno = isset($_GET['orderno'])?trim($_GET['orderno']):null;
$type = isset($_GET['type'])?trim($_GET['type']):'normal';
$aid = isset($_GET['aid'])?trim($_GET['aid']):'549000912';
$sid = isset($_GET['sid'])?trim($_GET['sid']):'0';
$cap_cd = isset($_GET['vcode'])?trim($_GET['vcode']):'';

// 随机QQ设备UA
$qq_uas = [
    'Mozilla/5.0 (Linux; Android 16; RMX5010 Build/BP2A.250605.015; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/121.0.6167.71 MQQBrowser/6.2 TBS/047925 Mobile Safari/537.36 V1_AND_SQ_9.2.60_12660_YYB_D QQ/9.2.60.32730 NetType/WIFI WebP/0.3.0 AppId/537339359 Pixel/1264 StatusBarHeight/140 SimpleUISwitch/0 QQTheme/1103 QQExt/1 StudyMode/0 CurrentMode/0 CurrentFontScale/1.0 GlobalDensityScale/0.9028572 AllowLandscape/false InMagicWin/0',
    'Mozilla/5.0 (Linux; Android 15; V2334A Build/TP1A.220905.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/120.0.6099.210 MQQBrowser/6.2 TBS/047820 Mobile Safari/537.36 V1_AND_SQ_9.2.60_12660_YYB_D QQ/9.2.60.32730 NetType/WIFI WebP/0.3.0 AppId/537339359 Pixel/1080 StatusBarHeight/96 SimpleUISwitch/0 QQTheme/1002 QQExt/1 StudyMode/0 CurrentMode/0 CurrentFontScale/1.0 GlobalDensityScale/0.9876543 AllowLandscape/false InMagicWin/0',
    'Mozilla/5.0 (Linux; Android 14; SM-G998B Build/UP1A.231004.007; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/119.0.6045.193 MQQBrowser/6.2 TBS/047715 Mobile Safari/537.36 V1_AND_SQ_9.2.60_12660_YYB_D QQ/9.2.60.32730 NetType/4G WebP/0.3.0 AppId/537339359 Pixel/1440 StatusBarHeight/108 SimpleUISwitch/0 QQTheme/1001 QQExt/1 StudyMode/0 CurrentMode/0 CurrentFontScale/1.0 GlobalDensityScale/1.0543210 AllowLandscape/false InMagicWin/0',
];
$random_ua = $qq_uas[array_rand($qq_uas, 1)];

// 参数验证
if(empty($qq)) $qq = '0';
if(empty($orderno)) $orderno = $qq;

// 如果有hkurl，尝试从hkurl中提取参数覆盖
if(!empty($hkurl)) {
    if(strpos($hkurl, '?') !== false){
        $url_parts = parse_url($hkurl);
        if(isset($url_parts['query'])){
            parse_str($url_parts['query'], $params);
            if(isset($params['sid'])) $sid = $params['sid'];
            if(isset($params['aid'])) $aid = $params['aid'];
            if(isset($params['cap_cd'])) $cap_cd = $params['cap_cd'];
        }
    }
}

// 如果是身份验证，使用身份验证专用的aid
if($type == 'verify') {
    $aid = '2090581062';
}
?>
<!DOCTYPE html>
<html>
<head lang="zh-CN">
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <title>滑块验证码</title>
    <style>
        body {
            margin: 0;
            padding: 10px 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            background-color: transparent;
        }
        #captcha-container {
            width: 300px;
            margin: 0 auto;
        }
        #status {
            margin-top: 10px;
            font-size: 13px;
            color: #666;
        }
    </style>
    <!-- 引入腾讯滑块验证SDK -->
    <script src="https://ssl.captcha.qq.com/TCaptcha.js"></script>
</head>
<body>
    <div id="captcha-container"></div>
    <div id="status">正在加载验证码...</div>
    
    <script>
        var randomUA = '<?php echo $random_ua;?>';
        
        // 初始化腾讯滑块验证
        var captcha = new TencentCaptcha('<?php echo $aid;?>', function(res) {
            if (res.ret === 0) {
                // 验证成功
                document.getElementById('status').innerHTML = '验证成功，正在提交...';
                
                // 根据验证类型调用不同的回调函数
                if (window.parent) {
                    var verifyData = {
                        qq: '<?php echo $qq;?>',
                        randstr: res.randstr,
                        ticket: res.ticket,
                        orderno: '<?php echo $orderno;?>',
                        ua: randomUA
                    };
                    
                    // 检查是否是身份验证
                    <?php if($type == 'verify'):?>
                    // 身份验证，调用submit_verify_1函数
                    if (window.parent.submit_verify_1) {
                        window.parent.submit_verify_1(verifyData);
                    } else if (window.parent.getticket) {
                        window.parent.getticket(verifyData);
                    }
                    <?php else:?>
                    // 普通滑块验证，调用getticket函数
                    if (window.parent.getticket) {
                        window.parent.getticket(verifyData);
                    } else {
                        document.getElementById('status').innerHTML = '错误：父窗口没有getticket函数';
                    }
                    <?php endif;?>
                } else {
                    document.getElementById('status').innerHTML = '错误：无法访问父窗口';
                }
            } else if (res.ret === 2) {
                // 用户关闭
                if (window.parent && window.parent.hideCapModal) {
                    window.parent.hideCapModal();
                } else if (window.parent && window.parent.layer) {
                    var index = window.parent.layer.getFrameIndex(window.name);
                    window.parent.layer.close(index);
                }
            } else {
                // 验证失败
                document.getElementById('status').innerHTML = '验证失败，请重试';
            }
        }, {
            // 配置选项
            enableDarkMode: false,
            needFeedBack: false,
            type: 'popup',
            capcd: '<?php echo $cap_cd; ?>',
            uin: '<?php echo $qq; ?>',
            sid: '<?php echo $sid; ?>'
        });
        
        // 显示验证码
        captcha.show();
        
        // 更新状态
        document.getElementById('status').innerHTML = '请完成滑块验证';
        
        // 监听窗口关闭事件
        window.onbeforeunload = function() {
            // 销毁验证码实例
            if (captcha) {
                captcha.destroy();
            }
        };
    </script>
</body>
</html>