fix: resolve Feishu cross-app notification routing bug
Implement per-app open_id storage via user_feishu_open_ids table with union_id-based cross-app user identification. WS handlers now auto-capture open_id+union_id and resolve/associate user accounts. Schedule notifications route through the correct bot's open_id instead of always falling back to 苹果. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -89,9 +89,16 @@ async def bind_feishu(
|
||||
if not data.open_id or not data.open_id.strip():
|
||||
raise HTTPException(status_code=400, detail="open_id 不能为空")
|
||||
|
||||
current_user.feishu_open_id = data.open_id.strip()
|
||||
open_id = data.open_id.strip()
|
||||
current_user.feishu_open_id = open_id
|
||||
db.commit()
|
||||
logger.info("飞书绑定成功: user=%s open_id=%s", current_user.id, data.open_id)
|
||||
# 同步写入多应用 open_id 表(含 union_id 用于跨应用识别)
|
||||
from app.services.feishu_open_id_service import save_open_id
|
||||
from app.services.feishu_app_service import lookup_union_id_by_open_id
|
||||
from app.core.config import settings
|
||||
union_id = lookup_union_id_by_open_id(open_id)
|
||||
save_open_id(db, app_id=settings.FEISHU_APP_ID or "", open_id=open_id, user_id=current_user.id, union_id=union_id)
|
||||
logger.info("飞书绑定成功: user=%s open_id=%s union_id=%s", current_user.id, open_id, union_id)
|
||||
return {"message": "飞书账号绑定成功"}
|
||||
|
||||
|
||||
@@ -132,7 +139,13 @@ async def lookup_and_bind(
|
||||
|
||||
current_user.feishu_open_id = open_id
|
||||
db.commit()
|
||||
logger.info("飞书自动绑定成功: user=%s email=%s open_id=%s", current_user.id, current_user.email, open_id)
|
||||
# 同步写入多应用 open_id 表(含 union_id 用于跨应用识别)
|
||||
from app.services.feishu_open_id_service import save_open_id
|
||||
from app.services.feishu_app_service import lookup_union_id_by_open_id
|
||||
from app.core.config import settings
|
||||
union_id = lookup_union_id_by_open_id(open_id)
|
||||
save_open_id(db, app_id=settings.FEISHU_APP_ID or "", open_id=open_id, user_id=current_user.id, union_id=union_id)
|
||||
logger.info("飞书自动绑定成功: user=%s email=%s open_id=%s union_id=%s", current_user.id, current_user.email, open_id, union_id)
|
||||
|
||||
# 发送测试消息
|
||||
from app.services.feishu_app_service import send_message_to_user
|
||||
@@ -176,6 +189,12 @@ async def bind_pending(
|
||||
open_id = ids[-1]
|
||||
current_user.feishu_open_id = open_id
|
||||
db.commit()
|
||||
# 同步写入多应用 open_id 表(含 union_id 用于跨应用识别)
|
||||
from app.services.feishu_open_id_service import save_open_id
|
||||
from app.services.feishu_app_service import lookup_union_id_by_open_id
|
||||
from app.core.config import settings
|
||||
union_id = lookup_union_id_by_open_id(open_id)
|
||||
save_open_id(db, app_id=settings.FEISHU_APP_ID or "", open_id=open_id, user_id=current_user.id, union_id=union_id)
|
||||
clear_pending_open_ids()
|
||||
|
||||
logger.info("飞书事件绑定成功: user=%s open_id=%s", current_user.id, open_id)
|
||||
|
||||
Reference in New Issue
Block a user