fix(send-like): update serialization to resolve user UID and adjust payload structure

This commit is contained in:
DrSmoothl committed 2026-05-23 22:50:40 +08:00
1 parent d8c72c2ebc
commit 98296fcec5
3 files changed
+65 -22

No files matched your search

@@ -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<BridgeContext, 'resolveUserUid'>;
export const serialize = (_ctx: Deps, p: Params): OidbLike => ({
targetUin: p.userId,
count: p.count,
});
export const serialize = async (ctx: Deps, p: Params): Promise<OidbLike> => {
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 => {};
@@ -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<OidbBase<OidbLike>>(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();
});
});
});
+11 -2
View File
@@ -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>;