feat(qzone): like_qzone / unlike_qzone — like/unlike a 说说 via web API
setQzoneLike POSTs a form body to w.qzone.qq.com's internal_dolike_app (like) or internal_unlike_app (unlike), proxied through h5.qzone, keyed by the feed's mood unikey/curkey (http://user.qzone.qq.com/<uin>/mood/<tid>) and fid=tid, as the bot (opUin). target_uin selects whose 说说 (defaults to the bot's own); scope is 说说 (mood, appid 311). Throws on non-zero code/subcode. Rejects empty tid pre-flight. WRITE — rate-limit (风控). - core: QzoneApi.like(tid, targetUin?, like); onebot: like_qzone + unlike_qzone actions; regen catalog. - tests: dolike vs unlike CGI selection, unikey/curkey/fid/opuin form lock, empty-tid preflight, code+subcode throws, and bridge owner- defaulting (self vs friend) + like-flag threading.
This commit is contained in:
6 files changed
+287
-2
No files matched your search
@@ -461,3 +461,73 @@ export async function deleteQzoneMsg(
|
||||
throw new Error(`qzone delete failed: subcode=${data.subcode} ${data.message ?? ''}`.trim());
|
||||
}
|
||||
}
|
||||
|
||||
// ─────────────── 点赞/取消赞 (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.
|
||||
|
||||
interface RawLikeResponse {
|
||||
code?: number;
|
||||
subcode?: number;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
export async function setQzoneLike(
|
||||
cookieObject: Record<string, string>,
|
||||
opUin: string,
|
||||
targetUin: string,
|
||||
tid: string,
|
||||
like: boolean,
|
||||
): Promise<void> {
|
||||
if (!cookieObject || typeof cookieObject !== 'object') {
|
||||
throw new Error('cookieObject is required');
|
||||
}
|
||||
if (!tid) {
|
||||
throw new Error('tid is required');
|
||||
}
|
||||
|
||||
const bkn = getBknFromCookie(cookieObject);
|
||||
const cgi = like ? 'internal_dolike_app' : 'internal_unlike_app';
|
||||
const url = `https://h5.qzone.qq.com/proxy/domain/w.qzone.qq.com/cgi-bin/likes/${cgi}?g_tk=${bkn}`;
|
||||
// unikey/curkey address the 说说 (mood) feed; fid is the tid.
|
||||
const unikey = `http://user.qzone.qq.com/${targetUin}/mood/${tid}`;
|
||||
const body = new URLSearchParams({
|
||||
qzreferrer: `https://user.qzone.qq.com/${opUin}`,
|
||||
opuin: opUin,
|
||||
unikey,
|
||||
curkey: unikey,
|
||||
appid: '311',
|
||||
typeid: '0',
|
||||
fid: tid,
|
||||
from: '1',
|
||||
active: '0',
|
||||
fupdate: '1',
|
||||
format: 'json',
|
||||
}).toString();
|
||||
|
||||
const text = await RequestUtil.HttpGetText(url, 'POST', body, {
|
||||
Cookie: cookieToString(cookieObject),
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
});
|
||||
const data = parseQzoneJson<RawLikeResponse>(text);
|
||||
|
||||
const verb = like ? 'like' : 'unlike';
|
||||
if (typeof data.code === 'number' && data.code !== 0) {
|
||||
log.warn('setQzoneLike(%s): non-zero code (tid=%s) code=%d msg=%s', verb, tid, data.code, data.message);
|
||||
throw new Error(`qzone ${verb} failed: code=${data.code} ${data.message ?? ''}`.trim());
|
||||
}
|
||||
if (typeof data.subcode === 'number' && data.subcode !== 0) {
|
||||
log.warn('setQzoneLike(%s): non-zero subcode (tid=%s) subcode=%d msg=%s', verb, tid, data.subcode, data.message);
|
||||
throw new Error(`qzone ${verb} failed: subcode=${data.subcode} ${data.message ?? ''}`.trim());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user