公众号授权成功!!!!!!!!

This commit is contained in:
2025-11-25 16:10:56 +08:00
parent 9905263fc3
commit 17a5abd399
4 changed files with 213 additions and 28 deletions

View File

@@ -0,0 +1 @@
77gnINv8gXADzpb9

View File

@@ -13,7 +13,7 @@
<!-- </script> -->
<script src="./marked.min.js"></script>
<!-- <script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script> -->
<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
<style>
* {
@@ -1376,12 +1376,12 @@
</div>
<!-- <script>
<script>
// 开启 vConsole 调试面板
var vConsole = new VConsole();
console.log("✅ vConsole 已经启动");
</script> -->
</script>
@@ -1411,14 +1411,28 @@
const encodedUserId = params.get("userId");
const from = params.get("from");
const code = params.get("code");
if (code) {
console.log(code, "code")
// console.log(window.location);
fetch(`/api/wechat/oauth/access-token?code=${code}`).then(res => res.json()).then(res => {
console.log(res, '获取accesstoken')
})
}
function handleCode(code) {
if (code) {
console.log(code, "code");
fetch(`https://servicestream.satabot.com/api/wechat/access_token?code=${code}`)
.then(res => res.json())
.then(res => {
console.log(res.nickname)
document.querySelectorAll('.username').forEach((e) => {
e.textContent = res.nickname;
})
openId = res.openid;
userId = res.openid;
getUserByOpenId(userId)
});
} else {
return; // ✅ 没问题,直接退出函数
}
}
const appid = "wx364b8ebf17fe45fe";
// 回调地址(必须和公众号后台配置的网页授权域名一致)
const redirect_uri = encodeURIComponent("http://ai.satabot.com");
@@ -1430,16 +1444,21 @@
// ✅ 先 URL 解码,再 Base64 解码,再 UTF-8 解码
let userId;
if (from == "weixin") {
userId = encodedUserId;
openId = encodedUserId;
setCookie('openId', openId)
document.querySelector('.userinfo-panel .logout').style.display = 'none';
document.querySelectorAll('.logout').forEach(el => {
el.style.display = 'none';
});
} else {
userId = decodeURIComponent(Number(escape(atob(encodedUserId))));
}
// 微信授权的码
handleCode(code);
if (userId && userId != "NaN") {
setCookie("userId", userId);
}
@@ -1475,7 +1494,8 @@
// }
// } else {
if (getCookie("userId") && getCookie("userId") != "NaN") {
if (getCookie("userId") && getCookie("userId") != "NaN" && !code) {
if (from == "weixin") {
getUserByOpenId(userId)
} else {
@@ -1483,6 +1503,7 @@
}
} else {
// deleteCookie('userId');
if (from == "weixin") {
@@ -1769,6 +1790,7 @@
const questions = document.querySelectorAll(".question");
// 获取到用户名称
function getUserName(userId) {
if (code) return;
if (from == "weixin") {
document.querySelectorAll('.username').forEach((e) => {
e.textContent = userId;
@@ -2187,7 +2209,7 @@
sessId = sendParam.sessionId;
sendParam.imageBase64 = img;
// sendParam.userId= encodedUserId;
if (from != "weixin") {
if (from != "weixin" && !code) {
sendParam.userId = decodeURIComponent(Number(escape(atob(encodedUserId))));
} else {
sendParam.userId = userId;

View File

@@ -7,24 +7,186 @@
<title>Document</title>
<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
<style>
:root {
--bg1: #eaf6ff;
--card-bg: rgba(255, 255, 255, 0.85);
--green: #1ac167;
--muted: #6b7280;
--shadow: 0 18px 50px rgba(16, 64, 92, 0.08);
font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft Yahei", Arial, sans-serif;
}
* {
box-sizing: border-box
}
html,
body {
height: 100%;
margin: 0
}
body {
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(180deg, #f3fbff 0%, #e9f5ff 60%);
padding: 28px;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.wrap {
width: 100%;
max-width: 560px;
background: var(--card-bg);
border-radius: 14px;
padding: 56px 48px;
box-shadow: var(--shadow);
text-align: center
}
.logo {
width: 92px;
height: 92px;
border-radius: 18px;
overflow: hidden;
margin: 0 auto 18px;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(180deg, #ffffff, rgba(255, 255, 255, 0.6));
box-shadow: 0 8px 20px rgba(12, 75, 40, 0.06);
}
.logo img {
width: 72px;
height: 72px;
object-fit: contain;
display: block
}
h1 {
margin: 6px 0 24px;
font-size: 22px;
color: #0f1724;
font-weight: 600
}
.agree {
display: flex;
align-items: center;
gap: 12px;
justify-content: flex-start;
margin: 22px auto 28px;
max-width: 420px;
color: var(--muted);
font-size: 14px
}
.agree input {
width: 18px;
height: 18px
}
.agree a {
color: #0b84b5;
text-decoration: none
}
.btn {
display: inline-block;
padding: 14px 48px;
border-radius: 40px;
background: linear-gradient(90deg, var(--green), #12b06c);
color: white;
font-weight: 700;
border: 0;
cursor: pointer;
font-size: 16px;
box-shadow: 0 12px 30px rgba(26, 193, 103, 0.18);
transition: transform .12s ease, opacity .12s ease;
}
.btn:active {
transform: translateY(1px)
}
.btn[disabled] {
opacity: 0.6;
cursor: not-allowed;
box-shadow: none
}
.subtle {
font-size: 13px;
color: var(--muted);
margin-top: 18px
}
@media (max-width:520px) {
.wrap {
padding: 36px 20px
}
.agree {
justify-content: center
}
}
</style>
</head>
<body>
<button onclick="handlelogin()">微信登录</button>
<!-- <div class="wrap" role="main" aria-labelledby="title">
<div class="logo" aria-hidden>
<img src="./img/logo.png" alt="飒沓 logo">
</div>
<h1 id="title">欢迎来到飒沓</h1>
<div style="height:8px"></div> -->
<!-- <label class="agree" for="agreeChk">
<input type="checkbox" id="agreeChk" />
<div style="line-height:1.35">已阅读并同意
<a href="#" onclick="return false">服务协议</a>、
<a href="#" onclick="return false">隐私政策</a>
</div>
</label> -->
<!-- <div>
<button id="loginBtn" class="btn" onclick="handlelogin()">授权登录</button>
</div> -->
<!-- <div class="subtle">使用微信扫码或微信内授权登录。为保障账号安全,请勿在不信任的设备上授权。</div> -->
<!-- </div> -->
<script>
// 开启 vConsole 调试面板
var vConsole = new VConsole();
// wx364b8ebf17fe45fe wx0eeb7556d60121db
console.log("✅ vConsole 已经启动");
const url = encodeURIComponent("https://ai.satabot.com?userid=6353rf")
handlelogin()
function handlelogin() {
const APP_ID = 'wx364b8ebf17fe45fe';
const APP_ID = 'wxa957108dae7d9048';
const REDIRECT_URI = encodeURIComponent("https://ai.satabot.com");
const STATE = Math.random().toString(36).substring(2, 12);
const SCOPE = 'snsapi_base';
const SCOPE = 'snsapi_userinfo';
// const authUrl = `https://open.weixin.qq.com/connect/qrconnect?appid=${APP_ID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=${SCOPE}&state=${STATE}#wechat_redirect`;
// window.location.href = authUrl; // 跳转后页面刷新,后续代码不执行
window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${APP_ID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=${SCOPE}&forcePopup=false&state=${STATE}&connect_redirect=1#wechat_redirect`
window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${APP_ID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=${SCOPE}&state=${STATE}&connect_redirect=1#wechat_redirect`
}
</script>

View File

@@ -256,18 +256,18 @@ async function createMenu() {
"name": "资料下载",
"url": "http://www.jsmaibu.com/Support/Download.html"
},
{
"type": "click",
"name": "AI智能体",
"key": "AI_INTELLIGENT"
}
// {
// "type": "view",
// "name": "AI智能体",
// // "url":`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx364b8ebf17fe45fe&redirect_uri= encodeURIComponent("https://ai.satabot.com/?from=weixin")&response_type=code&scope=snsapi_login&state=123#wechat_redirect`,
// "url": "https://ai.satabot.com/middle.html"
// {
// "type": "click",
// "name": "AI智能体",
// "key": "AI_INTELLIGENT"
// }
{
"type": "view",
"name": "AI智能体",
// "url":`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx364b8ebf17fe45fe&redirect_uri= encodeURIComponent("https://ai.satabot.com/?from=weixin")&response_type=code&scope=snsapi_login&state=123#wechat_redirect`,
"url": "https://ai.satabot.com/middle.html"
}
]
},
{