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:
6 files changed
+87
-24
No files matched your search
@@ -54,10 +54,10 @@ export class QzoneApi {
|
||||
* 给一条说说点赞/取消赞。`targetUin` 省略时点赞机器人自己空间的说说;
|
||||
* 点赞好友说说时传好友 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 owner = targetUin && targetUin > 0 ? targetUin.toString() : selfUin;
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -72,16 +72,17 @@ describe('apis/qzone', () => {
|
||||
const getCookies = vi.fn(async () => ({ p_skey: 'PSK' }));
|
||||
const bridge = mockBridge({ apis: { ...mockApiHub(), web: { getCookies } } as never });
|
||||
const likeSpy = vi.spyOn(qzoneWeb, 'setQzoneLike').mockResolvedValue();
|
||||
await new QzoneApi(bridge as never).like('TIDX', undefined, true);
|
||||
// opUin = self ('10001'), owner defaults to self when target_uin absent
|
||||
expect(likeSpy).toHaveBeenCalledWith({ p_skey: 'PSK' }, '10001', '10001', 'TIDX', true);
|
||||
await new QzoneApi(bridge as never).like('TIDX', undefined, true, 1700000000);
|
||||
// opUin = self ('10001'), owner defaults to self when target_uin absent; abstime threaded
|
||||
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 bridge = mockBridge({ apis: { ...mockApiHub(), web: { getCookies } } as never });
|
||||
const likeSpy = vi.spyOn(qzoneWeb, 'setQzoneLike').mockResolvedValue();
|
||||
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);
|
||||
});
|
||||
});
|
||||
@@ -3405,6 +3405,17 @@ export const ACTIONS: CatalogAction[] = [
|
||||
"minimum": 1
|
||||
},
|
||||
"desc": "说说所属 QQ 号,省略则为机器人自己"
|
||||
},
|
||||
{
|
||||
"name": "abstime",
|
||||
"type": "int",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"desc": "说说发表时间(unix 秒),传真实值更可靠",
|
||||
"default": 0
|
||||
}
|
||||
],
|
||||
"invariants": [],
|
||||
@@ -3420,6 +3431,12 @@ export const ACTIONS: CatalogAction[] = [
|
||||
"type": "integer",
|
||||
"minimum": 1,
|
||||
"description": "说说所属 QQ 号,省略则为机器人自己"
|
||||
},
|
||||
"abstime": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"description": "说说发表时间(unix 秒),传真实值更可靠",
|
||||
"default": 0
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -6421,7 +6438,7 @@ export const ACTIONS: CatalogAction[] = [
|
||||
{
|
||||
"name": "unlike_qzone",
|
||||
"aliases": [],
|
||||
"summary": "取消对一条说说的点赞(QQ 空间)",
|
||||
"summary": "取消对一条说说的点赞(QQ 空间;取消赞端点待真机核实)",
|
||||
"readOnly": false,
|
||||
"params": [
|
||||
{
|
||||
@@ -6443,6 +6460,17 @@ export const ACTIONS: CatalogAction[] = [
|
||||
"minimum": 1
|
||||
},
|
||||
"desc": "说说所属 QQ 号,省略则为机器人自己"
|
||||
},
|
||||
{
|
||||
"name": "abstime",
|
||||
"type": "int",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"desc": "说说发表时间(unix 秒),传真实值更可靠",
|
||||
"default": 0
|
||||
}
|
||||
],
|
||||
"invariants": [],
|
||||
@@ -6458,6 +6486,12 @@ export const ACTIONS: CatalogAction[] = [
|
||||
"type": "integer",
|
||||
"minimum": 1,
|
||||
"description": "说说所属 QQ 号,省略则为机器人自己"
|
||||
},
|
||||
"abstime": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"description": "说说发表时间(unix 秒),传真实值更可靠",
|
||||
"default": 0
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -87,17 +87,19 @@ export const actions = [
|
||||
}),
|
||||
|
||||
// like_qzone — 给一条说说点赞。target_uin 省略=机器人自己空间;点赞好友说说传其 uin。
|
||||
// 写操作;高频点赞会被 Qzone 风控,调用方需限流。
|
||||
// abstime=该说说的发表时间(unix 秒,来自 get_qzone_feeds/get_qzone_msg_list),
|
||||
// 传真实值更可靠;不传按 0。写操作;高频点赞会被 Qzone 风控,调用方需限流。
|
||||
defineAction({
|
||||
name: 'like_qzone',
|
||||
summary: '给一条说说点赞(QQ 空间)',
|
||||
params: {
|
||||
tid: f.string({ allowEmpty: false }).describe('说说 tid'),
|
||||
target_uin: f.uint().describe('说说所属 QQ 号,省略则为机器人自己').optional(),
|
||||
abstime: f.int({ min: 0 }).describe('说说发表时间(unix 秒),传真实值更可靠').default(0),
|
||||
},
|
||||
run: async (p, ctx) => {
|
||||
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);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'failed to like qzone msg';
|
||||
@@ -107,16 +109,18 @@ export const actions = [
|
||||
}),
|
||||
|
||||
// unlike_qzone — 取消对一条说说的点赞。参数同 like_qzone。写操作。
|
||||
// 注意:取消赞端点(internal_unlike_app)暂未经真机核实,待抓包确认。
|
||||
defineAction({
|
||||
name: 'unlike_qzone',
|
||||
summary: '取消对一条说说的点赞(QQ 空间)',
|
||||
summary: '取消对一条说说的点赞(QQ 空间;取消赞端点待真机核实)',
|
||||
params: {
|
||||
tid: f.string({ allowEmpty: false }).describe('说说 tid'),
|
||||
target_uin: f.uint().describe('说说所属 QQ 号,省略则为机器人自己').optional(),
|
||||
abstime: f.int({ min: 0 }).describe('说说发表时间(unix 秒),传真实值更可靠').default(0),
|
||||
},
|
||||
run: async (p, ctx) => {
|
||||
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);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'failed to unlike qzone msg';
|
||||
|
||||
@@ -463,12 +463,22 @@ export async function deleteQzoneMsg(
|
||||
}
|
||||
|
||||
// ─────────────── 点赞/取消赞 (like/unlike) — internal_dolike_app ───────────────
|
||||
// Likes or unlikes a 说说 (mood, appid 311) on `targetUin`'s space. like →
|
||||
// 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>`) and
|
||||
// `fid` (= tid). WRITE OP — rate-limit (likes are an active action,风控'd
|
||||
// like sending messages). Scope is 说说 only; other feed types use a
|
||||
// different unikey shape and are out of scope for this slice.
|
||||
// Likes or unlikes a 说说 (mood, appid 311) on `targetUin`'s space, keyed by
|
||||
// the feed's unikey/curkey (`http://user.qzone.qq.com/<uin>/mood/<tid>`,
|
||||
// identical, http not https) and `fid` (= tid). The like CGI
|
||||
// (internal_dolike_app), opuin=liker, unikey/curkey shape, and appid=311 are
|
||||
// CONFIRMED against community impls (QLiker.py, CSDN 点赞协议). Two things are
|
||||
// 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 {
|
||||
code?: number;
|
||||
@@ -478,9 +488,11 @@ interface RawLikeResponse {
|
||||
|
||||
/**
|
||||
* Like or unlike a 说说 by `tid` on `targetUin`'s space, as the bot
|
||||
* (`opUin`). Resolves on success; THROWS on a transport failure or a
|
||||
* non-zero Qzone `code`/`subcode` (e.g. an unknown tid, no permission, or
|
||||
* an auth failure). `like=false` hits the unlike CGI.
|
||||
* (`opUin`). `abstime` is the target feed's post time (unix seconds) — pass
|
||||
* the real value (from get_qzone_feeds/msglist) for reliability; 0 is a
|
||||
* 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(
|
||||
cookieObject: Record<string, string>,
|
||||
@@ -488,6 +500,7 @@ export async function setQzoneLike(
|
||||
targetUin: string,
|
||||
tid: string,
|
||||
like: boolean,
|
||||
abstime = 0,
|
||||
): Promise<void> {
|
||||
if (!cookieObject || typeof cookieObject !== 'object') {
|
||||
throw new Error('cookieObject is required');
|
||||
@@ -508,6 +521,7 @@ export async function setQzoneLike(
|
||||
curkey: unikey,
|
||||
appid: '311',
|
||||
typeid: '0',
|
||||
abstime: String(abstime),
|
||||
fid: tid,
|
||||
from: '1',
|
||||
active: '0',
|
||||
|
||||
@@ -296,13 +296,14 @@ describe('qzone / deleteQzoneMsg (HTTP layer)', () => {
|
||||
describe('qzone / setQzoneLike (HTTP layer)', () => {
|
||||
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}');
|
||||
|
||||
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]!;
|
||||
expect(method).toBe('POST');
|
||||
// like CGI + unikey/curkey shape + opuin + appid CONFIRMED (QLiker.py, CSDN)
|
||||
expect(url).toBe(
|
||||
`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('opuin')).toBe('10000');
|
||||
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}');
|
||||
await setQzoneLike(cookies, '10000', '10000', 'TIDX', false);
|
||||
const [url] = spy.mock.calls[0]!;
|
||||
|
||||
Reference in new issue
Block a user