From 8804a16ad9432e516b05bafc04ca5e1db347adc5 Mon Sep 17 00:00:00 2001 From: Wxw-Gu <84499436+Wxw-Gu@users.noreply.github.com> Date: Sat, 31 Oct 2026 00:20:39 +0800 Subject: [PATCH] =?UTF-8?q?fix(wechat-send):=20HTTP=20=E5=8F=91=E9=80=81?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E4=B8=BA=E8=AF=AD=E9=9F=B3=E8=A1=A5=20self?= =?UTF-8?q?=20wxid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Windows hook 的语音对象需要发送者 wxid,IPC 路径(UI 点发送)会用 chat.getSelfAccountInfoAsync() 塞进 metadata.fromId,HTTP 路由漏了这一步, 表现为 type=voice 一律 SEND_FAILED「无法识别当前微信账号 wxid」。 - createWechatSendRoute 内懒加载 chat-service 取 self wxid(避免静态循环依赖) - 仅在 contentType === 'voice' 时解析,其它类型不加开销 - 命中则并入 metadata.fromId,由 wechat-action-gateway 映射成 fromWxid 下发 --- src/main/http-server.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/http-server.ts b/src/main/http-server.ts index bcafe40..9e2427d 100644 --- a/src/main/http-server.ts +++ b/src/main/http-server.ts @@ -755,6 +755,19 @@ function createWechatSendRoute( pathname: string, deps: WechatSendApiDependencies ): RouteHandler | undefined { + // 语音发送必须带「当前账号 wxid」:Windows hook 的语音对象需要它。 + // IPC 路径一直有(index.ts 里的 chat.getSelfAccountInfoAsync),HTTP 路径漏了, + // 表现为 type=voice 一律 SEND_FAILED「无法识别当前微信账号 wxid」。 + // 懒加载,避免 http-server 与 chat-service 形成静态循环依赖。 + const resolveSelfWxid = async (): Promise => { + try { + const chat = await import('./services/chat-service') + const self = await chat.getSelfAccountInfoAsync() + return String(self?.wxid || '').trim() + } catch { + return '' + } + } if (pathname !== WECHAT_SEND_ROUTE) return undefined return withMethods(['POST'], async ({ res, body }) => { @@ -815,13 +828,15 @@ function createWechatSendRoute( let result: WechatActionResult try { + const fromId = contentType === 'voice' ? await resolveSelfWxid() : '' result = await deps.execute({ origin: 'http_api', purpose: `api_${contentType}` as WechatActionRequest['purpose'], triggerType: 'user', recipient: parsed.recipient, content: parsed.content, - ...(parsed.idempotencyKey ? { idempotencyKey: parsed.idempotencyKey } : {}) + ...(parsed.idempotencyKey ? { idempotencyKey: parsed.idempotencyKey } : {}), + ...(fromId ? { metadata: { fromId } } : {}) }) } catch (error) { return sendWechatSendError(res, 500, 'INTERNAL_ERROR', '微信发送执行失败', {