From ab11283d9265201ea50c0c014790ed14f373e76e Mon Sep 17 00:00:00 2001 From: qihu-bot Date: Tue, 18 Aug 2026 13:47:07 +0800 Subject: [PATCH] =?UTF-8?q?#976=20=E5=BE=AE=E4=BF=A1=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E5=90=8C=E6=AD=A5WebClaw=E4=BF=AE=E5=A4=8D=20+=20admin?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=97=B6=E9=97=B4=E7=BB=9F=E4=B8=80=E5=8C=97?= =?UTF-8?q?=E4=BA=AC=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.mirror_to_ai_chat: _uuid→uuid(NameError被except吞了, 对话从未同步到webclaw) 2.im_bot_admin加_beijing_now并替换5处datetime.now()(容器UTC存naive时间前端按+08:00展示错位8小时) --- backend/python/app/api/admin/im_bot_admin.py | 16 ++++++++++++---- backend/python/app/api/im_bot_user.py | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/backend/python/app/api/admin/im_bot_admin.py b/backend/python/app/api/admin/im_bot_admin.py index a767a35..0985e75 100644 --- a/backend/python/app/api/admin/im_bot_admin.py +++ b/backend/python/app/api/admin/im_bot_admin.py @@ -14,7 +14,15 @@ import hmac import time import threading import requests -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone + +# #976 全平台统一使用北京时间(容器 UTC,前端按 +08:00 展示) +_TZ_BEIJING = timezone(timedelta(hours=8)) + + +def _beijing_now(): + """返回 naive 北京时间(容器 UTC 时区下,需显式转)""" + return datetime.now(_TZ_BEIJING).replace(tzinfo=None) from typing import Optional from fastapi import APIRouter, Depends, HTTPException, Query @@ -773,13 +781,13 @@ async def wechat_qrcode_status(qrcode: str = Query(...), user=Depends(get_curren (bot_token, ilink_bot_id, baseurl, status, connected_at, created_at, updated_at) VALUES (:bot_token, :ilink_bot_id, :baseurl, 'connected', :connected_at, :created_at, :updated_at)"""), {"bot_token": bot_token, "ilink_bot_id": ilink_bot_id, "baseurl": baseurl, - "connected_at": datetime.now(), "created_at": datetime.now(), "updated_at": datetime.now()}) + "connected_at": _beijing_now(), "created_at": _beijing_now(), "updated_at": _beijing_now()}) else: _execute_raw(db, text("""UPDATE im_bot_wechat_account SET bot_token=:bot_token, ilink_bot_id=:ilink_bot_id, baseurl=:baseurl, status='connected', connected_at=:connected_at, updated_at=:updated_at WHERE id=:id"""), {"bot_token": bot_token, "ilink_bot_id": ilink_bot_id, "baseurl": baseurl, - "connected_at": datetime.now(), "updated_at": datetime.now(), "id": _row_to_dict(row)["id"]}) + "connected_at": _beijing_now(), "updated_at": _beijing_now(), "id": _row_to_dict(row)["id"]}) row = _wechat_row(db) aid = _row_to_dict(row)["id"] if row else 1 _start_wechat_receiver(aid) @@ -821,7 +829,7 @@ async def wechat_disconnect(user=Depends(get_current_user)): row = _wechat_row(db) if row: _execute_raw(db, text("UPDATE im_bot_wechat_account SET bot_token=NULL, status='disconnected', updated_at=:updated_at WHERE id=:id"), - {"updated_at": datetime.now(), "id": _row_to_dict(row)["id"]}) + {"updated_at": _beijing_now(), "id": _row_to_dict(row)["id"]}) return {"success": True, "message": "已断开个人微信连接"} except Exception as e: raise HTTPException(status_code=500, detail=str(e)) diff --git a/backend/python/app/api/im_bot_user.py b/backend/python/app/api/im_bot_user.py index bd138a1..3932d49 100644 --- a/backend/python/app/api/im_bot_user.py +++ b/backend/python/app/api/im_bot_user.py @@ -551,7 +551,7 @@ def _get_or_create_wechat_conv(db: Session, user_id: str) -> str: ), {"uid": user_id}) if rows: return _row_to_dict(rows[0])["id"] - cid = str(_uuid.uuid4()) + cid = str(uuid.uuid4()) now = _beijing_now() _execute_raw(db, text( "INSERT INTO conversations " @@ -566,7 +566,7 @@ def _append_ai_message(db: Session, conv_id: str, role: str, content: str, creat "INSERT INTO messages (id, conversation_id, role, content, token_used, created_at) " "VALUES (:id, :cid, :role, :content, 0, :c)" ), { - "id": str(_uuid.uuid4()), "cid": conv_id, "role": role, + "id": str(uuid.uuid4()), "cid": conv_id, "role": role, "content": content, "c": created or _beijing_now(), })