修复h5记事本不显示问题

This commit is contained in:
2026-08-18 09:25:51 +08:00
parent aed71d237d
commit 0e797c39f4
11 changed files with 911 additions and 452 deletions
+111 -45
View File
@@ -8,67 +8,133 @@
html, body {
margin: 0;
padding: 0;
background: rgba(0, 0, 0, 0.45);
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 params = new URLSearchParams(window.location.search);
var captchaId = params.get('captchaId') || '';
var finished = false;
var started = false;
function postToUni(payload) {
if (window.uni && typeof uni.postMessage === 'function') {
uni.postMessage({ data: payload })
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;
function closePage() {
if (window.uni && typeof uni.navigateBack === 'function') {
setTimeout(function () { uni.navigateBack() }, 120)
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();
});
}
if (!captchaId || typeof initGeetest4 !== 'function') {
postToUni({ type: 'fail', msg: '极验初始化失败' })
closePage()
return
}
window.__startGeetest = startCaptcha;
initGeetest4({
captchaId: captchaId,
product: 'bind',
language: 'zh-CN'
}, function (instance) {
instance.onSuccess(function () {
var result = instance.getValidate() || {}
postToUni({
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 || ''
}
})
closePage()
})
instance.onFail(function () {
postToUni({ type: 'fail', msg: '人机验证未通过' })
closePage()
})
instance.onError(function () {
postToUni({ type: 'fail', msg: '人机验证加载失败' })
closePage()
})
instance.showCaptcha()
})
})()
if (captchaId) {
startCaptcha(captchaId);
} else if (window.plus) {
startCaptcha();
} else {
document.addEventListener('plusready', function () {
startCaptcha();
}, false);
}
})();
</script>
</body>
</html>
+10 -3
View File
@@ -174,8 +174,9 @@ var loadScript = function (url, cb, timeout) {
script.charset = "UTF-8";
script.async = true;
// 对geetestçš„é™æ€èµ„æºæ·»åŠ crossOrigin
if ( /static\.geetest\.com/g.test(url)) {
// 对geetest的静态资源添加 crossOrigin。
// file:// 本地页(App web-view)带 crossOrigin 会触发 CORS,必须跳过。
if ( /static\.geetest\.com/g.test(url) && window.location.protocol !== 'file:') {
script.crossOrigin = "anonymous";
}
@@ -381,7 +382,13 @@ window.initGeetest4 = function (userConfig,callback) {
if (userConfig.https) {
config.protocol = 'https://';
} else if (!userConfig.protocol) {
config.protocol = window.location.protocol + '//';
var locProtocol = window.location.protocol;
// file:// / app:// 不能沿用当前协议,否则会请求 file://static.geetest.com
if (locProtocol === 'http:' || locProtocol === 'https:') {
config.protocol = locProtocol + '//';
} else {
config.protocol = 'https://';
}
}
+10 -3
View File
@@ -174,8 +174,9 @@ var loadScript = function (url, cb, timeout) {
script.charset = "UTF-8";
script.async = true;
// 对geetestçš„é™æ€èµ„æºæ·»åŠ crossOrigin
if ( /static\.geetest\.com/g.test(url)) {
// 对geetest的静态资源添加 crossOrigin。
// file:// 本地页(App web-view)带 crossOrigin 会触发 CORS,必须跳过。
if ( /static\.geetest\.com/g.test(url) && window.location.protocol !== 'file:') {
script.crossOrigin = "anonymous";
}
@@ -381,7 +382,13 @@ window.initGeetest4 = function (userConfig,callback) {
if (userConfig.https) {
config.protocol = 'https://';
} else if (!userConfig.protocol) {
config.protocol = window.location.protocol + '//';
var locProtocol = window.location.protocol;
// file:// / app:// 不能沿用当前协议,否则会请求 file://static.geetest.com
if (locProtocol === 'http:' || locProtocol === 'https:') {
config.protocol = locProtocol + '//';
} else {
config.protocol = 'https://';
}
}