feat(qzone): send_qzone_msg — publish a text 说说 via web API
First Qzone WRITE path. publishQzoneMsg POSTs a form-urlencoded body to taotao.qzone.qq.com's emotion_cgi_publish_v6 (proxied through h5.qzone), g_tk in the query, on the bot's own space. Returns the server-assigned tid (the handle for later delete/comment/like) + post time. - Throws on transport failure, non-zero Qzone code (content rejected / rate-limited), or a success body with no tid — never reports a publish as succeeded without the feed id. Rejects empty content pre-flight. - 带图 (image) publishing is a later slice (needs the upload CGI first). - Action carries a风控/限流 caveat: publishing is an active action and high frequency is rate-limited by Qzone, same as sending messages. - core: QzoneApi.publish; onebot: send_qzone_msg action; regen catalog. - tests: form-body/url/headers lock, empty-content preflight, non-zero code throw, missing-tid throw, and bridge self-space threading.
This commit is contained in:
6 files changed
+204
-2
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, vi, afterEach } from 'vitest';
|
||||
import { getQzoneFeeds, getQzoneMsgList, mapFeeds, mapMsgList, parseQzoneJson } from '@snowluma/protocol/web/qzone';
|
||||
import { getQzoneFeeds, getQzoneMsgList, mapFeeds, mapMsgList, parseQzoneJson, publishQzoneMsg } from '@snowluma/protocol/web/qzone';
|
||||
import { RequestUtil } from '@snowluma/protocol/web/request-util';
|
||||
|
||||
// The 说说 list comes from taotao.qzone.qq.com's emotion_cgi_msglist_v6 CGI,
|
||||
@@ -189,3 +189,46 @@ describe('qzone / getQzoneFeeds (HTTP layer)', () => {
|
||||
await expect(getQzoneFeeds(cookies, '10000')).rejects.toThrow('无法获取空间好友动态');
|
||||
});
|
||||
});
|
||||
|
||||
describe('qzone / publishQzoneMsg (HTTP layer)', () => {
|
||||
afterEach(() => vi.restoreAllMocks());
|
||||
|
||||
it('POSTs a form-urlencoded body to the proxied publish CGI and returns tid/time', async () => {
|
||||
const spy = vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":0,"tid":"NEWTID","now":1700000000}');
|
||||
|
||||
const out = await publishQzoneMsg(cookies, '10000', 'hello 世界');
|
||||
|
||||
expect(out).toEqual({ tid: 'NEWTID', time: 1700000000 });
|
||||
|
||||
const [url, method, body, headers] = spy.mock.calls[0]!;
|
||||
expect(method).toBe('POST');
|
||||
expect(url).toBe(
|
||||
`https://h5.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_publish_v6?g_tk=${expectedGtk}`,
|
||||
);
|
||||
const h = headers as Record<string, string>;
|
||||
expect(h['Content-Type']).toBe('application/x-www-form-urlencoded');
|
||||
expect(h.Cookie).toContain('p_skey=PSK');
|
||||
// form body carries the content (urlencoded) and the host uin
|
||||
const form = new URLSearchParams(body as string);
|
||||
expect(form.get('con')).toBe('hello 世界');
|
||||
expect(form.get('hostuin')).toBe('10000');
|
||||
expect(form.get('format')).toBe('json');
|
||||
expect(form.get('qzreferrer')).toBe('https://user.qzone.qq.com/10000');
|
||||
});
|
||||
|
||||
it('rejects empty content before any request', async () => {
|
||||
const spy = vi.spyOn(RequestUtil, 'HttpGetText');
|
||||
await expect(publishQzoneMsg(cookies, '10000', '')).rejects.toThrow('content is required');
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('throws on a non-zero qzone code (rejected/rate-limited)', async () => {
|
||||
vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":-10000,"message":"too frequent"}');
|
||||
await expect(publishQzoneMsg(cookies, '10000', 'hi')).rejects.toThrow('code=-10000');
|
||||
});
|
||||
|
||||
it('throws when the success body carries no tid', async () => {
|
||||
vi.spyOn(RequestUtil, 'HttpGetText').mockResolvedValue('{"code":0,"now":1700000000}');
|
||||
await expect(publishQzoneMsg(cookies, '10000', 'hi')).rejects.toThrow('缺少 tid');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user