fix(qzone): thread abstime into like, flag unlike endpoint as unverified

Adversarial review (NEEDS-FIXES) of the like/unlike slice:
- Missing abstime: every real dolike impl (QLiker.py, CSDN) sends the
  target feed's post time. Threaded abstime through setQzoneLike →
  QzoneApi.like → like_qzone/unlike_qzone actions (optional, default 0;
  pass the feed's real time for reliability). Test asserts it.
- internal_unlike_app is the conventional paired CGI but NO public bot
  impl exercises unlike, so it's best-guess. Labeled UNVERIFIED/pending a
  live capture in the helper comment, the unlike action summary, and the
  unlike test — instead of pinning it as confirmed truth (avoiding the
  re-codify-a-wrong-constant trap the last 3 slices hit).
- Documented the success-signal (code/subcode) as extrapolated from
  sibling CGIs (dolike may use a succ/fail token instead).

The confirmed mechanics (dolike CGI, opuin=liker, unikey/curkey mood
shape, appid=311, fid=tid) are noted as such.
This commit is contained in:
DrSmoothl committed 2026-06-20 02:02:25 +08:00
1 parent d497f1e6c7
commit 870504ae3a
6 files changed
+87 -24

No files matched your search

+2 -2
View File
@@ -54,10 +54,10 @@ export class QzoneApi {
* 给一条说说点赞/取消赞。`targetUin` 省略时点赞机器人自己空间的说说; * 给一条说说点赞/取消赞。`targetUin` 省略时点赞机器人自己空间的说说;
* 点赞好友说说时传好友 uin(tid 来自 get_qzone_feeds / get_qzone_msg_list)。 * 点赞好友说说时传好友 uin(tid 来自 get_qzone_feeds / get_qzone_msg_list)。
*/ */
async like(tid: string, targetUin: number | undefined, like: boolean): Promise<void> { async like(tid: string, targetUin: number | undefined, like: boolean, abstime = 0): Promise<void> {
const selfUin = this.ctx.identity.uin; const selfUin = this.ctx.identity.uin;
const owner = targetUin && targetUin > 0 ? targetUin.toString() : selfUin; const owner = targetUin && targetUin > 0 ? targetUin.toString() : selfUin;
const cookieObject = await this.ctx.apis.web.getCookies('qzone.qq.com'); const cookieObject = await this.ctx.apis.web.getCookies('qzone.qq.com');
await setQzoneLike(cookieObject, selfUin, owner, tid, like); await setQzoneLike(cookieObject, selfUin, owner, tid, like, abstime);
} }
} }
+6 -5
View File
@@ -72,16 +72,17 @@ describe('apis/qzone', () => {
const getCookies = vi.fn(async () => ({ p_skey: 'PSK' })); const getCookies = vi.fn(async () => ({ p_skey: 'PSK' }));
const bridge = mockBridge({ apis: { ...mockApiHub(), web: { getCookies } } as never }); const bridge = mockBridge({ apis: { ...mockApiHub(), web: { getCookies } } as never });
const likeSpy = vi.spyOn(qzoneWeb, 'setQzoneLike').mockResolvedValue(); const likeSpy = vi.spyOn(qzoneWeb, 'setQzoneLike').mockResolvedValue();
await new QzoneApi(bridge as never).like('TIDX', undefined, true); await new QzoneApi(bridge as never).like('TIDX', undefined, true, 1700000000);
// opUin = self ('10001'), owner defaults to self when target_uin absent // opUin = self ('10001'), owner defaults to self when target_uin absent; abstime threaded
expect(likeSpy).toHaveBeenCalledWith({ p_skey: 'PSK' }, '10001', '10001', 'TIDX', true); expect(likeSpy).toHaveBeenCalledWith({ p_skey: 'PSK' }, '10001', '10001', 'TIDX', true, 1700000000);
}); });
it('like targets a friend\'s space (owner = target_uin) and threads the unlike flag', async () => { it('like targets a friend\'s space (owner = target_uin) and threads the unlike flag + abstime default', async () => {
const getCookies = vi.fn(async () => ({ p_skey: 'PSK' })); const getCookies = vi.fn(async () => ({ p_skey: 'PSK' }));
const bridge = mockBridge({ apis: { ...mockApiHub(), web: { getCookies } } as never }); const bridge = mockBridge({ apis: { ...mockApiHub(), web: { getCookies } } as never });
const likeSpy = vi.spyOn(qzoneWeb, 'setQzoneLike').mockResolvedValue(); const likeSpy = vi.spyOn(qzoneWeb, 'setQzoneLike').mockResolvedValue();
await new QzoneApi(bridge as never).like('TIDX', 20002, false); await new QzoneApi(bridge as never).like('TIDX', 20002, false);
expect(likeSpy).toHaveBeenCalledWith({ p_skey: 'PSK' }, '10001', '20002', 'TIDX', false); // abstime defaults to 0 when omitted
expect(likeSpy).toHaveBeenCalledWith({ p_skey: 'PSK' }, '10001', '20002', 'TIDX', false, 0);
}); });
}); });
+35 -1
View File
@@ -3405,6 +3405,17 @@ export const ACTIONS: CatalogAction[] = [
"minimum": 1 "minimum": 1
}, },
"desc": "说说所属 QQ 号,省略则为机器人自己" "desc": "说说所属 QQ 号,省略则为机器人自己"
},
{
"name": "abstime",
"type": "int",
"required": false,
"schema": {
"type": "integer",
"minimum": 0
},
"desc": "说说发表时间(unix 秒),传真实值更可靠",
"default": 0
} }
], ],
"invariants": [], "invariants": [],
@@ -3420,6 +3431,12 @@ export const ACTIONS: CatalogAction[] = [
"type": "integer", "type": "integer",
"minimum": 1, "minimum": 1,
"description": "说说所属 QQ 号,省略则为机器人自己" "description": "说说所属 QQ 号,省略则为机器人自己"
},
"abstime": {
"type": "integer",
"minimum": 0,
"description": "说说发表时间(unix 秒),传真实值更可靠",
"default": 0
} }
}, },
"required": [ "required": [
@@ -6421,7 +6438,7 @@ export const ACTIONS: CatalogAction[] = [
{ {
"name": "unlike_qzone", "name": "unlike_qzone",
"aliases": [], "aliases": [],
"summary": "取消对一条说说的点赞(QQ 空间)", "summary": "取消对一条说说的点赞(QQ 空间;取消赞端点待真机核实)",
"readOnly": false, "readOnly": false,
"params": [ "params": [
{ {
@@ -6443,6 +6460,17 @@ export const ACTIONS: CatalogAction[] = [
"minimum": 1 "minimum": 1
}, },
"desc": "说说所属 QQ 号,省略则为机器人自己" "desc": "说说所属 QQ 号,省略则为机器人自己"
},
{
"name": "abstime",
"type": "int",
"required": false,
"schema": {
"type": "integer",
"minimum": 0
},
"desc": "说说发表时间(unix 秒),传真实值更可靠",
"default": 0
} }
], ],
"invariants": [], "invariants": [],
@@ -6458,6 +6486,12 @@ export const ACTIONS: CatalogAction[] = [
"type": "integer", "type": "integer",
"minimum": 1, "minimum": 1,
"description": "说说所属 QQ 号,省略则为机器人自己" "description": "说说所属 QQ 号,省略则为机器人自己"
},
"abstime": {
"type": "integer",
"minimum": 0,
"description": "说说发表时间(unix 秒),传真实值更可靠",
"default": 0
} }
}, },
"required": [ "required": [
+8 -4
View File
@@ -87,17 +87,19 @@ export const actions = [
}), }),
// like_qzone — 给一条说说点赞。target_uin 省略=机器人自己空间;点赞好友说说传其 uin。 // like_qzone — 给一条说说点赞。target_uin 省略=机器人自己空间;点赞好友说说传其 uin。
// 写操作;高频点赞会被 Qzone 风控,调用方需限流。 // abstime=该说说的发表时间(unix 秒,来自 get_qzone_feeds/get_qzone_msg_list),
// 传真实值更可靠;不传按 0。写操作;高频点赞会被 Qzone 风控,调用方需限流。
defineAction({ defineAction({
name: 'like_qzone', name: 'like_qzone',
summary: '给一条说说点赞(QQ 空间)', summary: '给一条说说点赞(QQ 空间)',
params: { params: {
tid: f.string({ allowEmpty: false }).describe('说说 tid'), tid: f.string({ allowEmpty: false }).describe('说说 tid'),
target_uin: f.uint().describe('说说所属 QQ 号,省略则为机器人自己').optional(), target_uin: f.uint().describe('说说所属 QQ 号,省略则为机器人自己').optional(),
abstime: f.int({ min: 0 }).describe('说说发表时间(unix 秒),传真实值更可靠').default(0),
}, },
run: async (p, ctx) => { run: async (p, ctx) => {
try { try {
await ctx.bridge.apis.qzone.like(p.tid, p.target_uin, true); await ctx.bridge.apis.qzone.like(p.tid, p.target_uin, true, p.abstime);
return okResponse(null); return okResponse(null);
} catch (error) { } catch (error) {
const message = error instanceof Error ? error.message : 'failed to like qzone msg'; const message = error instanceof Error ? error.message : 'failed to like qzone msg';
@@ -107,16 +109,18 @@ export const actions = [
}), }),
// unlike_qzone — 取消对一条说说的点赞。参数同 like_qzone。写操作。 // unlike_qzone — 取消对一条说说的点赞。参数同 like_qzone。写操作。
// 注意:取消赞端点(internal_unlike_app)暂未经真机核实,待抓包确认。
defineAction({ defineAction({
name: 'unlike_qzone', name: 'unlike_qzone',
summary: '取消对一条说说的点赞(QQ 空间)', summary: '取消对一条说说的点赞(QQ 空间;取消赞端点待真机核实)',
params: { params: {
tid: f.string({ allowEmpty: false }).describe('说说 tid'), tid: f.string({ allowEmpty: false }).describe('说说 tid'),
target_uin: f.uint().describe('说说所属 QQ 号,省略则为机器人自己').optional(), target_uin: f.uint().describe('说说所属 QQ 号,省略则为机器人自己').optional(),
abstime: f.int({ min: 0 }).describe('说说发表时间(unix 秒),传真实值更可靠').default(0),
}, },
run: async (p, ctx) => { run: async (p, ctx) => {
try { try {
await ctx.bridge.apis.qzone.like(p.tid, p.target_uin, false); await ctx.bridge.apis.qzone.like(p.tid, p.target_uin, false, p.abstime);
return okResponse(null); return okResponse(null);
} catch (error) { } catch (error) {
const message = error instanceof Error ? error.message : 'failed to unlike qzone msg'; const message = error instanceof Error ? error.message : 'failed to unlike qzone msg';
+23 -9
View File
@@ -463,12 +463,22 @@ export async function deleteQzoneMsg(
} }
// ─────────────── 点赞/取消赞 (like/unlike) — internal_dolike_app ─────────────── // ─────────────── 点赞/取消赞 (like/unlike) — internal_dolike_app ───────────────
// Likes or unlikes a 说说 (mood, appid 311) on `targetUin`'s space. like → // Likes or unlikes a 说说 (mood, appid 311) on `targetUin`'s space, keyed by
// internal_dolike_app, unlike → internal_unlike_app, same form body keyed by // the feed's unikey/curkey (`http://user.qzone.qq.com/<uin>/mood/<tid>`,
// the feed's unikey/curkey (`http://user.qzone.qq.com/<uin>/mood/<tid>`) and // identical, http not https) and `fid` (= tid). The like CGI
// `fid` (= tid). WRITE OP — rate-limit (likes are an active action,风控'd // (internal_dolike_app), opuin=liker, unikey/curkey shape, and appid=311 are
// like sending messages). Scope is 说说 only; other feed types use a // CONFIRMED against community impls (QLiker.py, CSDN 点赞协议). Two things are
// different unikey shape and are out of scope for this slice. // NOT live-verified and follow this file's "extrapolated, pending a live
// capture" posture:
// • the UNLIKE endpoint `internal_unlike_app` — it's the conventional
// paired CGI but no public bot impl exercises unlike, so it's best-guess.
// • the success SIGNAL — we throw on a non-zero code/subcode (extrapolated
// from sibling CGIs); the dolike response may instead carry a succ/fail
// token, so a clean parse is treated as success.
// `abstime` (the target feed's post time) is threaded through because every
// real dolike impl sends it; 0 is a tolerated fallback when unknown.
// WRITE OP — rate-limit (likes are an active action,风控'd like messages).
// Scope is 说说 only; other feed types use a different unikey shape.
interface RawLikeResponse { interface RawLikeResponse {
code?: number; code?: number;
@@ -478,9 +488,11 @@ interface RawLikeResponse {
/** /**
* Like or unlike a 说说 by `tid` on `targetUin`'s space, as the bot * Like or unlike a 说说 by `tid` on `targetUin`'s space, as the bot
* (`opUin`). Resolves on success; THROWS on a transport failure or a * (`opUin`). `abstime` is the target feed's post time (unix seconds) — pass
* non-zero Qzone `code`/`subcode` (e.g. an unknown tid, no permission, or * the real value (from get_qzone_feeds/msglist) for reliability; 0 is a
* an auth failure). `like=false` hits the unlike CGI. * tolerated fallback. Resolves on success; THROWS on a transport failure or
* a non-zero Qzone `code`/`subcode`. `like=false` hits the (unverified)
* unlike CGI.
*/ */
export async function setQzoneLike( export async function setQzoneLike(
cookieObject: Record<string, string>, cookieObject: Record<string, string>,
@@ -488,6 +500,7 @@ export async function setQzoneLike(
targetUin: string, targetUin: string,
tid: string, tid: string,
like: boolean, like: boolean,
abstime = 0,
): Promise<void> { ): Promise<void> {
if (!cookieObject || typeof cookieObject !== 'object') { if (!cookieObject || typeof cookieObject !== 'object') {
throw new Error('cookieObject is required'); throw new Error('cookieObject is required');
@@ -508,6 +521,7 @@ export async function setQzoneLike(
curkey: unikey, curkey: unikey,
appid: '311', appid: '311',
typeid: '0', typeid: '0',
abstime: String(abstime),
fid: tid, fid: tid,
from: '1', from: '1',
active: '0', active: '0',
+13 -3
View File
@@ -296,13 +296,14 @@ describe('qzone / deleteQzoneMsg (HTTP layer)', () => {
describe('qzone / setQzoneLike (HTTP layer)', () => { describe('qzone / setQzoneLike (HTTP layer)', () => {
afterEach(() => vi.restoreAllMocks()); afterEach(() => vi.restoreAllMocks());
it('POSTs to internal_dolike_app with the mood unikey/curkey/fid when liking', async () => { it('POSTs to internal_dolike_app with the mood unikey/curkey/fid/abstime when liking', async () => {
const spy = vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":0,"subcode":0}'); const spy = vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":0,"subcode":0}');
await expect(setQzoneLike(cookies, '10000', '20002', 'TIDX', true)).resolves.toBeUndefined(); await expect(setQzoneLike(cookies, '10000', '20002', 'TIDX', true, 1700000000)).resolves.toBeUndefined();
const [url, method, body, headers] = spy.mock.calls[0]!; const [url, method, body, headers] = spy.mock.calls[0]!;
expect(method).toBe('POST'); expect(method).toBe('POST');
// like CGI + unikey/curkey shape + opuin + appid CONFIRMED (QLiker.py, CSDN)
expect(url).toBe( expect(url).toBe(
`https://h5.qzone.qq.com/proxy/domain/w.qzone.qq.com/cgi-bin/likes/internal_dolike_app?g_tk=${expectedGtk}`, `https://h5.qzone.qq.com/proxy/domain/w.qzone.qq.com/cgi-bin/likes/internal_dolike_app?g_tk=${expectedGtk}`,
); );
@@ -316,9 +317,18 @@ describe('qzone / setQzoneLike (HTTP layer)', () => {
expect(form.get('fid')).toBe('TIDX'); expect(form.get('fid')).toBe('TIDX');
expect(form.get('opuin')).toBe('10000'); expect(form.get('opuin')).toBe('10000');
expect(form.get('appid')).toBe('311'); expect(form.get('appid')).toBe('311');
// abstime threaded through (every real dolike impl sends it)
expect(form.get('abstime')).toBe('1700000000');
}); });
it('hits internal_unlike_app when unliking', async () => { it('defaults abstime to 0 when not supplied', async () => {
const spy = vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":0}');
await setQzoneLike(cookies, '10000', '20002', 'TIDX', true);
const form = new URLSearchParams(spy.mock.calls[0]![2] as string);
expect(form.get('abstime')).toBe('0');
});
it('hits internal_unlike_app when unliking (NB: unlike endpoint UNVERIFIED, pending a live capture)', async () => {
const spy = vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":0}'); const spy = vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":0}');
await setQzoneLike(cookies, '10000', '10000', 'TIDX', false); await setQzoneLike(cookies, '10000', '10000', 'TIDX', false);
const [url] = spy.mock.calls[0]!; const [url] = spy.mock.calls[0]!;