feat: 微信自动关闭功能

This commit is contained in:
2025-03-02 18:17:37 +08:00
parent 2b7c7a8642
commit 96f75907d4
7 changed files with 41 additions and 26 deletions

View File

@@ -32,6 +32,7 @@
<div class="loading">Loading...</div>
<script type="module">
import { config } from './config.js'
import { closePage } from './is-wechat.js'
const demo = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect`
const appid = config.appid
const redirect_uri = encodeURIComponent(config.redirect_uri)
@@ -40,9 +41,7 @@
const state = url.searchParams.get('state')
if (!state) {
alert('Invalid state. Please try again later.');
setTimeout(() => {
window.close();
}, 2000);
closePage();
}
const link = demo.replace('APPID', appid).replace('REDIRECT_URI', redirect_uri).replace('SCOPE', scope).replace('STATE', state);
window.location.href = link
@@ -50,9 +49,7 @@
// Add a timeout for loading
setTimeout(() => {
alert('Loading timeout. Please try again later.');
setTimeout(() => {
window.close();
}, 2000);
closePage()
}, 60000); // 60 seconds timeout
</script>
</body>