This commit is contained in:
2025-05-01 03:59:37 +08:00
parent 26ca4c21c8
commit e58adbc46b
45 changed files with 7460 additions and 87 deletions

66
packages/xhs/src/index.ts Normal file
View File

@@ -0,0 +1,66 @@
import { XhsClient as XhsClientBase } from '@kevisual/xhs-core';
export const getSign = async (uri: string, data: any, a1: string, web_session?: string) => {
const signs = await fetch('http://light.xiongxiao.me:5006/sign', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
uri,
data,
a1,
web_session: web_session,
}),
}).then((res) => res.json());
return signs;
};
type XhsOptions = {
cookie?: string;
};
export class XhsClient extends XhsClientBase {
constructor(opts: XhsOptions) {
super(opts as any);
}
/**
* 获取未读消息
* @returns
*/
async getUnread(): Promise<UnreadCount> {
const url = '/api/sns/web/unread_count';
const response = await this.get(url);
return response;
}
async sign(uri: string, data: any, config: any) {
let header = config?.header || {};
const cookieDist = this.getCookieMap();
const web_session = cookieDist['web_session'];
const a1 = cookieDist['a1'];
const res = await getSign(uri, data, a1, web_session);
header['x-s'] = res['x-s'];
header['x-t'] = res['x-t'];
config.header = header;
return config;
}
async getNoteById(noteId: string, xsecToken?: string) {
const data = {
source_note_id: noteId,
image_scenes: ['CRD_WM_WEBP'],
};
const uri = '/api/sns/web/v1/feed';
try {
const response = await this.post(uri, data, { sign: this.sign.bind(this) });
return response['items'][0]['node_card'];
} catch (error) {
console.log(error);
}
}
}
type UnreadCount = {
unread_count: number;
likes: number;
connections: number;
mentions: number;
};

View File

@@ -0,0 +1,4 @@
import { XhsClient } from '../index.ts';
export const cookie = "a1=19686f83a65uiloc0y7wv79une457hsjh5lt00dpe40000147626;abRequestId=0a794332-4561-5f49-93f7-780b8b028e1f;access-token-creator.xiaohongshu.com=customer.creator.AT-68c517498636784561614544frjvxzj7yu8iewie;agora_session=6a0031373435393132333637323735343733393437313634000000000000;customerClientId=536706778174172;galaxy_creator_session_id=OhpHDDSoADhNEhnH5LLnQpletFLApu1fd91f;galaxy.creator.beaker.session.id=1745912429847011598150;gid=yjKqYfK0qDyYyj2DDSqd4ujxyW9kvxIuT62ddkMWhElyuxq8yDd6hl888q2WYy88j8i80yYD;loadts=1746020512562;sec_poison_id=441c932e-a6ac-4d8d-97ae-beb14adb1929;unread={%22ub%22:%2267eaf1fe000000001202c3ea%22%2C%22ue%22:%226803aa37000000001c0319d8%22%2C%22uc%22:35};web_session=040069b2e9c511ca302086ca253a4bde8b1cd1;webBuild=4.62.3;webId=97e5f097499594cad49aa0bd1a8ed83f;websectiga=3633fe24d49c7dd0eb923edc8205740f10fdb18b25d424d2a2322c6196d2a4ad;x-user-id-creator.xiaohongshu.com=639d86590000000026006076;xsecappid=xhs-pc-web;acw_tc=0a00df6217460205042195762e721fba339a0dbe8e4738b961a5ff15e74619;"
export const client = new XhsClient({ cookie } as any);

View File

@@ -0,0 +1,15 @@
import { client } from '../common.ts';
// client.getNoteComments()
// client.getNoteById('67dcc34e000000000602a8eb', 'ABuYS8Xb1o08DlRmMLIabdqnW0OKnLR9nMpDGq5bVRdvk').then((res) => {
// console.log(res);
// });
// client.getNoteByIdFromHtml('67dcc34e000000000602a8eb', 'ABuYS8Xb1o08DlRmMLIabdqnW0OKnLR9nMpDGq5bVRdvk').then((res) => {
// console.log(res);
// });
const id = '6810d722000000002100f139';
const x = 'LBEqTFigLzp41AdwQ-E3hbQScnvrx2flLgHElHpQ8zHWc=';
client.getNoteByIdFromHtml(id, x).then((res) => {
console.log(res);
});

View File

@@ -0,0 +1,5 @@
import { client } from '../common.ts';
client.getSelfInfoV2().then((res) => {
console.log(res);
});

View File

@@ -0,0 +1,5 @@
import { client } from '../common.ts';
client.getUnread().then((res) => {
console.log(res);
});