141 lines
3.4 KiB
HTML
141 lines
3.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
|
<title>人机验证</title>
|
|
<style>
|
|
html, body {
|
|
margin: 0;
|
|
padding: 0;
|
|
background: #f5f7fa;
|
|
height: 100%;
|
|
overflow: hidden;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
.loading-text {
|
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
font-size: 14px;
|
|
color: #909399;
|
|
letter-spacing: 0.5px;
|
|
}
|
|
</style>
|
|
<script src="./gt4.js"></script>
|
|
<script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.4.js"></script>
|
|
</head>
|
|
<body>
|
|
<div class="loading-text" id="tipText">正在加载安全验证...</div>
|
|
<script>
|
|
(function () {
|
|
var params = new URLSearchParams(window.location.search);
|
|
var captchaId = params.get('captchaId') || '';
|
|
var finished = false;
|
|
var started = false;
|
|
|
|
if (!captchaId && window.plus && plus.storage) {
|
|
try {
|
|
captchaId = plus.storage.getItem('__geetest_captcha_id__') || '';
|
|
} catch (e) {}
|
|
}
|
|
|
|
function notifyResult(payload) {
|
|
if (finished) return;
|
|
finished = true;
|
|
|
|
// 1. plus.storage 共享存储
|
|
try {
|
|
if (window.plus && plus.storage) {
|
|
plus.storage.setItem('__geetest_payload__', JSON.stringify(payload));
|
|
}
|
|
} catch (e) {}
|
|
|
|
// 2. uni.postMessage
|
|
try {
|
|
if (window.uni && typeof uni.postMessage === 'function') {
|
|
uni.postMessage({ data: payload });
|
|
}
|
|
} catch (e) {}
|
|
}
|
|
|
|
function failAndNotify(msg) {
|
|
notifyResult({ type: 'fail', msg: msg || '人机验证未通过' });
|
|
}
|
|
|
|
function startCaptcha(id) {
|
|
if (started) return;
|
|
if (id) captchaId = id;
|
|
if (!captchaId && window.plus && plus.storage) {
|
|
try {
|
|
captchaId = plus.storage.getItem('__geetest_captcha_id__') || '';
|
|
} catch (e) {}
|
|
}
|
|
if (!captchaId) return;
|
|
started = true;
|
|
|
|
if (typeof initGeetest4 !== 'function') {
|
|
failAndNotify('极验初始化失败');
|
|
return;
|
|
}
|
|
|
|
initGeetest4({
|
|
captchaId: captchaId,
|
|
product: 'bind',
|
|
language: 'zh-CN',
|
|
https: true,
|
|
protocol: 'https://',
|
|
onError: function () {
|
|
failAndNotify('人机验证加载失败');
|
|
}
|
|
}, function (instance) {
|
|
var tip = document.getElementById('tipText');
|
|
if (tip) tip.style.display = 'none';
|
|
|
|
instance.onSuccess(function () {
|
|
var result = instance.getValidate() || {};
|
|
notifyResult({
|
|
type: 'success',
|
|
result: {
|
|
captcha_id: result.captcha_id || captchaId,
|
|
lot_number: result.lot_number || '',
|
|
pass_token: result.pass_token || '',
|
|
gen_time: result.gen_time || '',
|
|
captcha_output: result.captcha_output || ''
|
|
}
|
|
});
|
|
try {
|
|
if (typeof instance.destroy === 'function') instance.destroy();
|
|
} catch (e) {}
|
|
});
|
|
instance.onFail(function () {
|
|
failAndNotify('人机验证未通过');
|
|
});
|
|
instance.onError(function () {
|
|
failAndNotify('人机验证加载失败');
|
|
});
|
|
instance.onClose(function () {
|
|
setTimeout(function () {
|
|
if (!finished) failAndNotify('已取消人机验证');
|
|
}, 300);
|
|
});
|
|
instance.showCaptcha();
|
|
});
|
|
}
|
|
|
|
window.__startGeetest = startCaptcha;
|
|
|
|
if (captchaId) {
|
|
startCaptcha(captchaId);
|
|
} else if (window.plus) {
|
|
startCaptcha();
|
|
} else {
|
|
document.addEventListener('plusready', function () {
|
|
startCaptcha();
|
|
}, false);
|
|
}
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|