temp
This commit is contained in:
1
mini-web/envision/MP_verify_NGWvli5lGpEkByyt.txt
Normal file
1
mini-web/envision/MP_verify_NGWvli5lGpEkByyt.txt
Normal file
@@ -0,0 +1 @@
|
||||
NGWvli5lGpEkByyt
|
||||
70
mini-web/envision/callback.html
Normal file
70
mini-web/envision/callback.html
Normal file
@@ -0,0 +1,70 @@
|
||||
<!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, maximum-scale=1, user-scalable=no">
|
||||
<title>登录中转</title>
|
||||
<style>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
</style>
|
||||
<style>
|
||||
.loading {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(255, 255, 255, 0.8);
|
||||
z-index: 9999;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 1.5em;
|
||||
/* Adjust font size for mobile */
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.loading {
|
||||
font-size: 1em;
|
||||
/* Smaller font size for smaller screens */
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="loading">Loading Code...</div>
|
||||
<script type="module">
|
||||
import { loginSuccessUrl } from './config.js';
|
||||
const url = new URL(window.location.href);
|
||||
const state = url.searchParams.get('state');
|
||||
const code = url.searchParams.get('code');
|
||||
// document.body.append(state + '-----------');
|
||||
// document.body.append(code);
|
||||
const orgin = url.origin;
|
||||
const res = await fetch(`${orgin}/api/router?path=wx&key=mplogin&state=${state}&code=${code}`)
|
||||
.then(res => res.json()).catch(err => {
|
||||
console.error(err);
|
||||
alert('登录失败,请稍后再试');
|
||||
document.body.append('登录失败,请稍后再试');
|
||||
setTimeout(() => {
|
||||
window.close();
|
||||
}, 2000);
|
||||
});
|
||||
// document.body.append(JSON.stringify(res, null, 2));
|
||||
if (res.code === 200) {
|
||||
localStorage.setItem('token', res.data.token);
|
||||
window.close()
|
||||
setTimeout(() => {
|
||||
window.open(loginSuccessUrl, '_blank');
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
9
mini-web/envision/config.js
Normal file
9
mini-web/envision/config.js
Normal file
@@ -0,0 +1,9 @@
|
||||
export const config = {
|
||||
appid: 'wxff97d569b1db16b6',
|
||||
redirect_uri: 'https://kevisual.xiongxiao.me/root/mini-web/callback.html',
|
||||
scope: 'snsapi_userinfo',
|
||||
};
|
||||
|
||||
export const loginUrl = `https://kevisual.xiongxiao.me/root/mini-web/login.html`;
|
||||
|
||||
export const loginSuccessUrl = `/ai/chat/`;
|
||||
92
mini-web/envision/index.html
Normal file
92
mini-web/envision/index.html
Normal file
@@ -0,0 +1,92 @@
|
||||
<!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, maximum-scale=1, user-scalable=no">
|
||||
<title>主页</title>
|
||||
<style>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#qrcode {
|
||||
width: 500px;
|
||||
height: 500px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- <canvas id="qrcode"></canvas> -->
|
||||
<img id="qrcode" />
|
||||
<script type="module">
|
||||
import { loginUrl, loginSuccessUrl } from './config.js'
|
||||
import QRCode from 'https://cdn.jsdelivr.net/npm/qrcode@1.5.4/+esm'
|
||||
const url = new URL(window.location.href)
|
||||
const redirect = url.searchParams.get('redirect')
|
||||
const redirectURL = redirect ? decodeURIComponent(redirect) : loginSuccessUrl
|
||||
var opts = {
|
||||
errorCorrectionLevel: 'H',
|
||||
type: 'image/jpeg',
|
||||
quality: 0.3,
|
||||
margin: 1,
|
||||
// color: {
|
||||
// dark: "#010599FF",
|
||||
// light: "#FFBF60FF"
|
||||
// }
|
||||
}
|
||||
let state = ''
|
||||
let timer = null
|
||||
const createQrcode = (state) => {
|
||||
const text = `${loginUrl}?state=${state}`
|
||||
QRCode.toDataURL(text, opts, function (err, url) {
|
||||
if (err) throw err
|
||||
var img = document.getElementById('qrcode')
|
||||
img.src = url
|
||||
})
|
||||
}
|
||||
const checkLogin = async () => {
|
||||
const res = await fetch(`/api/router?path=wx&key=checkLogin&state=${state}`).then(res => res.json())
|
||||
if (res.code === 200) {
|
||||
const token = res.data.token
|
||||
if (token) {
|
||||
localStorage.setItem('token', token)
|
||||
}
|
||||
document.body.innerHTML = `<h1>登录成功</h1>`
|
||||
setTimeout(() => {
|
||||
window.location.href = redirectURL
|
||||
}, 1000)
|
||||
} else {
|
||||
timer = setTimeout(() => {
|
||||
checkLogin()
|
||||
}, 1000)
|
||||
}
|
||||
}
|
||||
// 随机生成一个state
|
||||
state = Math.random().toString(36).substring(2, 15)
|
||||
createQrcode(state)
|
||||
checkLogin()
|
||||
setInterval(() => {
|
||||
state = Math.random().toString(36).substring(2, 15)
|
||||
clearTimeout(timer) // 清除定时器
|
||||
createQrcode(state) // 90秒后更新二维码
|
||||
checkLogin()
|
||||
}, 90000)
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
60
mini-web/envision/login.html
Normal file
60
mini-web/envision/login.html
Normal file
@@ -0,0 +1,60 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Envision</title>
|
||||
<style>
|
||||
.loading {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(255, 255, 255, 0.8);
|
||||
z-index: 9999;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 1.5em;
|
||||
/* Adjust font size for mobile */
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.loading {
|
||||
font-size: 1em;
|
||||
/* Smaller font size for smaller screens */
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="loading">Loading...</div>
|
||||
<script type="module">
|
||||
import { config } from './config.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)
|
||||
const scope = `snsapi_userinfo`
|
||||
const url = new URL(window.location.href)
|
||||
const state = url.searchParams.get('state')
|
||||
if (!state) {
|
||||
alert('Invalid state. Please try again later.');
|
||||
setTimeout(() => {
|
||||
window.close();
|
||||
}, 2000);
|
||||
}
|
||||
const link = demo.replace('APPID', appid).replace('REDIRECT_URI', redirect_uri).replace('SCOPE', scope).replace('STATE', state);
|
||||
window.location.href = link
|
||||
|
||||
// Add a timeout for loading
|
||||
setTimeout(() => {
|
||||
alert('Loading timeout. Please try again later.');
|
||||
setTimeout(() => {
|
||||
window.close();
|
||||
}, 2000);
|
||||
}, 60000); // 60 seconds timeout
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
20
mini-web/envision/vite.config.mjs
Normal file
20
mini-web/envision/vite.config.mjs
Normal file
@@ -0,0 +1,20 @@
|
||||
import { defineConfig } from 'vite';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [],
|
||||
|
||||
server: {
|
||||
host: '0.0.0.0',
|
||||
proxy: {
|
||||
'/system/lib': {
|
||||
target: 'https://kevisual.xiongxiao.me',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api': {
|
||||
target: 'https://kevisual.xiongxiao.me',
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/api/, '/api'),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
14
mini-web/package.json
Normal file
14
mini-web/package.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "mini-web",
|
||||
"version": "0.0.3",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"pub": "envision deploy ./envision -k mini-web -v 0.0.3 -y y",
|
||||
"ev": "npm run build && npm run deploy"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "abearxiong <xiongxiao@xiongxiao.me>",
|
||||
"license": "MIT",
|
||||
"type": "module"
|
||||
}
|
||||
9
mini-web/pnpm-lock.yaml
generated
Normal file
9
mini-web/pnpm-lock.yaml
generated
Normal file
@@ -0,0 +1,9 @@
|
||||
lockfileVersion: '9.0'
|
||||
|
||||
settings:
|
||||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
importers:
|
||||
|
||||
.: {}
|
||||
Reference in New Issue
Block a user