优化公众号
This commit is contained in:
91
index.html
91
index.html
@@ -1382,6 +1382,8 @@
|
||||
|
||||
console.log("✅ vConsole 已经启动");
|
||||
</script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js"></script>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1417,8 +1419,8 @@
|
||||
function handleCode(code) {
|
||||
if (code) {
|
||||
console.log(code, "code");
|
||||
fetch(`https://servicestream.satabot.com/api/wechat/access_token?code=${code}`)
|
||||
.then(res => res.json())
|
||||
retryFetch(`https://servicestream.satabot.com/api/wechat/access_token?code=${code}`)
|
||||
|
||||
.then(res => {
|
||||
console.log(res.nickname)
|
||||
document.querySelectorAll('.username').forEach((e) => {
|
||||
@@ -2104,12 +2106,97 @@
|
||||
img.style.marginTop = content ? "8px" : "0"; // 如果有文字,图片加一点间距
|
||||
msg.appendChild(img);
|
||||
}
|
||||
// 如果是 assistant,添加分享按钮
|
||||
if (role === "assistant") {
|
||||
const shareSpan = document.createElement("span");
|
||||
shareSpan.style.display = "inline-flex";
|
||||
shareSpan.style.alignItems = "center";
|
||||
shareSpan.style.cursor = "pointer";
|
||||
shareSpan.style.marginTop = "8px";
|
||||
shareSpan.style.opacity = "0.75";
|
||||
shareSpan.style.transition = "opacity .2s";
|
||||
shareSpan.title = "分享";
|
||||
|
||||
shareSpan.onmouseenter = () => shareSpan.style.opacity = "1";
|
||||
shareSpan.onmouseleave = () => shareSpan.style.opacity = "0.75";
|
||||
|
||||
shareSpan.innerHTML = `
|
||||
<svg t="1764059839985" class="icon" viewBox="0 0 1236 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5667" width="20" height="20"><path d="M741.743 1018.343c-28.287 0-50.917-11.315-73.547-28.288-22.63-22.63-39.602-50.917-39.602-84.862V792.044c-124.464 0-328.133 33.945-435.624 181.039-16.973 28.287-56.575 45.26-90.52 50.917H85.478C28.903 1012.685-5.042 961.768 0.616 905.193c28.287-243.27 113.15-418.652 260.243-537.458 107.492-84.862 231.956-130.122 367.735-141.437V118.807c0-50.917 22.63-96.177 67.89-113.15C736.086-5.657 781.345 0 815.29 33.945l362.077 367.735c28.288 22.63 45.26 56.574 50.918 96.176 5.657 39.603-5.658 79.205-33.945 107.492-5.658 5.658-11.315 16.972-22.63 22.63l-350.762 356.42c-22.63 22.63-50.918 33.945-79.205 33.945z m-90.52-339.448h90.52v226.298l356.42-367.734 5.658-5.658c5.657-5.657 5.657-16.972 5.657-22.63 0-11.315-5.657-16.972-11.315-22.63l-5.657-5.657-356.42-362.077V333.79l-79.205 5.658c-118.806 0-231.956 39.602-328.132 113.149-113.15 90.519-186.696 237.613-209.326 429.967 141.436-175.382 390.364-203.669 531.8-203.669z" p-id="5668"></path></svg>
|
||||
`;
|
||||
|
||||
shareSpan.onclick = () => {
|
||||
generatePoster(content, imgUrl);
|
||||
};
|
||||
|
||||
msg.appendChild(shareSpan);
|
||||
}
|
||||
|
||||
// 如果有时间,可以显示
|
||||
|
||||
chatMessages.appendChild(msg);
|
||||
chatMessages.scrollTop = chatMessages.scrollHeight;
|
||||
}
|
||||
|
||||
function generatePoster(text, imgUrl) {
|
||||
// 创建一个隐藏的海报容器
|
||||
const poster = document.createElement("div");
|
||||
poster.style.width = "750px";
|
||||
poster.style.padding = "40px";
|
||||
poster.style.background = "#ffffff";
|
||||
poster.style.borderRadius = "20px";
|
||||
poster.style.fontFamily = "sans-serif";
|
||||
poster.style.color = "#333";
|
||||
poster.style.boxSizing = "border-box";
|
||||
|
||||
// 标题
|
||||
const title = document.createElement("div");
|
||||
title.textContent = "飒沓 · 智能助理";
|
||||
title.style.fontSize = "32px";
|
||||
title.style.fontWeight = "bold";
|
||||
title.style.marginBottom = "20px";
|
||||
poster.appendChild(title);
|
||||
|
||||
// 内容文本
|
||||
const content = document.createElement("div");
|
||||
content.style.fontSize = "26px";
|
||||
content.style.lineHeight = "40px";
|
||||
content.style.whiteSpace = "pre-wrap";
|
||||
content.textContent = text.replace(/<\/?[^>]+(>|$)/g, ""); // 去除 html 标签
|
||||
poster.appendChild(content);
|
||||
|
||||
// 如果有图片
|
||||
if (imgUrl) {
|
||||
const img = document.createElement("img");
|
||||
img.src = imgUrl;
|
||||
img.style.width = "100%";
|
||||
img.style.marginTop = "30px";
|
||||
img.style.borderRadius = "12px";
|
||||
poster.appendChild(img);
|
||||
}
|
||||
|
||||
|
||||
// 放到 body(隐藏)
|
||||
poster.style.position = "fixed";
|
||||
poster.style.top = "-9999px";
|
||||
document.body.appendChild(poster);
|
||||
|
||||
// ⭐ 开始使用 html2canvas 生成海报
|
||||
html2canvas(poster, {
|
||||
scale: 2, // 高清
|
||||
useCORS: true
|
||||
}).then(canvas => {
|
||||
document.body.removeChild(poster);
|
||||
|
||||
// 生成图片
|
||||
const dataURL = canvas.toDataURL("image/png");
|
||||
|
||||
// 下载到相册(浏览器下载)
|
||||
const a = document.createElement("a");
|
||||
a.href = dataURL;
|
||||
a.download = "海报.png";
|
||||
a.click();
|
||||
});
|
||||
}
|
||||
function uuid() {
|
||||
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
||||
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
||||
|
||||
80
middle.html
80
middle.html
@@ -177,17 +177,95 @@
|
||||
var vConsole = new VConsole();
|
||||
// wx364b8ebf17fe45fe wx0eeb7556d60121db
|
||||
console.log("✅ vConsole 已经启动");
|
||||
const url = encodeURIComponent("https://ai.satabot.com?userid=6353rf")
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
|
||||
|
||||
const code = params.get("code");
|
||||
|
||||
handlelogin()
|
||||
function handlelogin() {
|
||||
const APP_ID = 'wxa957108dae7d9048';
|
||||
const REDIRECT_URI = encodeURIComponent("https://ai.satabot.com");
|
||||
// const REDIRECT_URI = encodeURIComponent("https://ai.satabot.com/middle.html");
|
||||
const STATE = Math.random().toString(36).substring(2, 12);
|
||||
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}&state=${STATE}&connect_redirect=1#wechat_redirect`
|
||||
}
|
||||
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)
|
||||
|
||||
openId = res.openid;
|
||||
userId = res.openid;
|
||||
getUserByOpenId(res.openid)
|
||||
|
||||
});
|
||||
} else {
|
||||
return; // ✅ 没问题,直接退出函数
|
||||
}
|
||||
}
|
||||
|
||||
function getUserByOpenId(id) {
|
||||
const data = {
|
||||
sourceType: 5,
|
||||
openId: id,
|
||||
phonenumber: '',
|
||||
smsCode: '',
|
||||
}
|
||||
retryFetch("https://serviceri.satabot.com/login", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
.then(res => {
|
||||
if (res.code == 300) {
|
||||
showpop(); // 弹出验证码
|
||||
} else if (res.code == 200) {
|
||||
setCookie('token', res.token);
|
||||
userId = res.userId;
|
||||
getSessionList();
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error("登录请求失败(重试10次后):", err);
|
||||
showToast("网络异常,请稍后再试");
|
||||
})
|
||||
.finally(() => {
|
||||
if (!document.querySelector(".weixin-loading").classList.contains("none")) {
|
||||
document.querySelector(".weixin-loading").classList.add("none");
|
||||
}
|
||||
console.log("登录请求结束");
|
||||
});
|
||||
}
|
||||
|
||||
async function retryFetch(url, options, maxRetry = 10) {
|
||||
let lastError;
|
||||
for (let i = 0; i < maxRetry; i++) {
|
||||
try {
|
||||
console.log(`登录请求第 ${i + 1} 次尝试...`);
|
||||
const response = await fetch(url, options);
|
||||
return await response.json();
|
||||
} catch (err) {
|
||||
lastError = err;
|
||||
console.warn(`第 ${i + 1} 次尝试失败:`, err);
|
||||
|
||||
// 最后一次重试失败 → 抛出错误
|
||||
if (i === maxRetry - 1) throw err;
|
||||
|
||||
// 重试前延迟 300ms
|
||||
await new Promise(res => setTimeout(res, 1000));
|
||||
}
|
||||
}
|
||||
throw lastError;
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
|
||||
Reference in New Issue
Block a user