From 98296fcec5824bf78509f416825db857309ed8e1 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sat, 23 May 2026 22:50:40 +0800 Subject: [PATCH] fix(send-like): update serialization to resolve user UID and adjust payload structure --- .../oidb-services/interaction/send-like.ts | 35 +++++++++++++---- .../interaction/send-like.test.ts | 39 +++++++++++++------ packages/proto-defs/src/oidb-actions/base.ts | 13 ++++++- 3 files changed, 65 insertions(+), 22 deletions(-) diff --git a/packages/bridge/src/oidb-services/interaction/send-like.ts b/packages/bridge/src/oidb-services/interaction/send-like.ts index 9666ea36..278daa0c 100644 --- a/packages/bridge/src/oidb-services/interaction/send-like.ts +++ b/packages/bridge/src/oidb-services/interaction/send-like.ts @@ -1,12 +1,26 @@ -// 0x7E5_104 — send "thumbs up" (赞) to another user (friend list 点赞). +// 0x7E5_104 — send "thumbs up" (赞) to another user (profile-card 点赞). // -// `count` is the number of likes in this single call (QQ allows -// 1–20 batched). Server caps daily quotas separately. +// Wire shape lives at fields 11/12/13 with a uid (NOT uin) target and a +// fixed `sourceId = 71` marker for the profile-card entry point. The +// server rejects uin-form payloads with "被点赞 QQ 号非法", so we resolve +// uin → uid through the identity service before encoding. +// +// `count` is the number of likes in this single call (QQ allows 1–20 +// batched). Server caps daily quotas separately. +// +// Upstream parity: +// - Lagrange.Core `OidbSvcTrpcTcp0x7E5_104` (fields 11/12/13): +// dev/Lagrange.Core/.../Service/Oidb/Request/OidbSvcTrpcTcp0x7E5_104.cs:14-18 +// - Lagrange.Core `FriendLikeService` (always emits `Field2 = 71`): +// dev/Lagrange.Core/.../Service/Action/FriendLikeService.cs:18-23 +// - NapCat `UserApi.like` (`setBuddyProfileLike` with sourceId 71): +// dev/NapCatQQ/packages/napcat-core/apis/user.ts:63-70 import { protobuf_decode, protobuf_encode } from '@snowluma/proton'; import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb'; import type { OidbLike } from '@snowluma/proto-defs/oidb-actions/base'; import { invokeOidb, type OidbSender } from '../../oidb-service'; +import type { BridgeContext } from '../../bridge-context'; export namespace SendLike { export const command = 0x7E5; @@ -17,12 +31,17 @@ export namespace SendLike { count: number; } - export type Deps = OidbSender; + export type Deps = OidbSender & Pick; - export const serialize = (_ctx: Deps, p: Params): OidbLike => ({ - targetUin: p.userId, - count: p.count, - }); + export const serialize = async (ctx: Deps, p: Params): Promise => { + const targetUid = await ctx.resolveUserUid(p.userId); + if (!targetUid) throw new Error(`failed to resolve uid for ${p.userId}`); + return { + targetUid, + sourceId: 71, + count: p.count, + }; + }; export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {}; diff --git a/packages/bridge/tests/oidb-services/interaction/send-like.test.ts b/packages/bridge/tests/oidb-services/interaction/send-like.test.ts index 9c0113ce..6388d7cf 100644 --- a/packages/bridge/tests/oidb-services/interaction/send-like.test.ts +++ b/packages/bridge/tests/oidb-services/interaction/send-like.test.ts @@ -6,9 +6,12 @@ import type { SendPacketResult } from '@snowluma/common/packet-sender'; import { SendLike } from '../../../src/oidb-services/interaction/send-like'; -function makeSender() { +function makeDeps(uid = 'target-uid-xyz') { const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) }; - return { sendRawPacket: vi.fn(async () => r) }; + return { + sendRawPacket: vi.fn(async () => r), + resolveUserUid: vi.fn(async () => uid), + }; } describe('SendLike namespace', () => { @@ -18,26 +21,38 @@ describe('SendLike namespace', () => { }); describe('serialize', () => { - it('passes userId / count through verbatim', () => { - expect(SendLike.serialize({} as any, { userId: 10001, count: 3 })).toEqual({ targetUin: 10001, count: 3 }); + it('resolves uid via ctx and emits {targetUid, sourceId=71, count}', async () => { + const deps = makeDeps('UID-AAA'); + const body = await SendLike.serialize(deps, { userId: 10001, count: 3 }); + expect(deps.resolveUserUid).toHaveBeenCalledWith(10001); + expect(body).toEqual({ targetUid: 'UID-AAA', sourceId: 71, count: 3 }); + }); + + it('throws when ctx returns an empty uid', async () => { + const deps = makeDeps(''); + await expect(SendLike.serialize(deps, { userId: 10001, count: 1 })) + .rejects.toThrow(/failed to resolve uid/); }); }); describe('invoke (e2e)', () => { it('routes to OidbSvcTrpcTcp.0x7e5_104', async () => { - const sender = makeSender(); - await SendLike.invoke(sender, { userId: 10001, count: 3 }); - expect(sender.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0x7e5_104'); + const deps = makeDeps(); + await SendLike.invoke(deps, { userId: 10001, count: 3 }); + expect(deps.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0x7e5_104'); }); - it('encodes targetUin + count into envelope body', async () => { - const sender = makeSender(); - await SendLike.invoke(sender, { userId: 10001, count: 3 }); - const [, bytes] = sender.sendRawPacket.mock.calls[0]!; + it('encodes targetUid (field 11) + sourceId=71 (field 12) + count (field 13)', async () => { + const deps = makeDeps('UID-BBB'); + await SendLike.invoke(deps, { userId: 10001, count: 5 }); + const [, bytes] = deps.sendRawPacket.mock.calls[0]!; const env = protobuf_decode>(bytes); expect(env.command).toBe(0x7E5); expect(env.subCommand).toBe(104); - expect(env.body).toMatchObject({ targetUin: 10001, count: 3 }); + expect(env.body).toMatchObject({ targetUid: 'UID-BBB', sourceId: 71, count: 5 }); + // Defensive: the obsolete uin-form field must not appear (server + // rejects uin-form payloads with "被点赞 QQ 号非法"). + expect((env.body as any).targetUin).toBeUndefined(); }); }); }); diff --git a/packages/proto-defs/src/oidb-actions/base.ts b/packages/proto-defs/src/oidb-actions/base.ts index 4a14a6ab..560c3070 100644 --- a/packages/proto-defs/src/oidb-actions/base.ts +++ b/packages/proto-defs/src/oidb-actions/base.ts @@ -114,9 +114,18 @@ export interface OidbSpecialTitle { groupUin?: pb<1, uint_32>; body?: pb<2, OidbSpecialTitleBody>; } +// 0x7E5_104 (FriendLike) request body. Field numbers 11/12/13 (NOT +// 1/2/3) — the server reads `targetUid` from tag 11 and rejects with +// "被点赞 QQ 号非法" if it lands on the wrong tag. `sourceId = 71` is +// the fixed marker for the "profile card" 点赞 entry point. +// Mirrors Lagrange.Core's `OidbSvcTrpcTcp0x7E5_104`: +// dev/Lagrange.Core/.../Service/Oidb/Request/OidbSvcTrpcTcp0x7E5_104.cs:14-18 +// and NapCat's UserApi.like (`setBuddyProfileLike` → sourceId 71): +// dev/NapCatQQ/packages/napcat-core/apis/user.ts:63-70 export interface OidbLike { - targetUin?: pb<1, uint_32>; - count?: pb<2, uint_32>; + targetUid?: pb<11, string>; + sourceId?: pb<12, uint_32>; + count?: pb<13, uint_32>; } export interface OidbGroupRequestList { count?: pb<1, uint_32>;