diff --git a/index.html b/index.html
index 99ecd41..1d2bf82 100755
--- a/index.html
+++ b/index.html
@@ -1382,6 +1382,8 @@
console.log("✅ vConsole 已经启动");
+
+
@@ -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 = `
+
+ `;
+
+ 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)
diff --git a/middle.html b/middle.html
index ba7e734..0ca1cad 100644
--- a/middle.html
+++ b/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;
+ }