Skip to content

Commit

Permalink
feat: 修改小红书的加密方式的计算
Browse files Browse the repository at this point in the history
  • Loading branch information
duan602728596 committed Jan 22, 2024
1 parent 79ae160 commit 202f20c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
13 changes: 10 additions & 3 deletions packages/main/src/ipcHandle/xiaohongshuHandle.mts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ function ipcXiaohongshuHandle(): void {
const url: string = request.url;

if (url.includes('fe-static.xhscdn.com') && url.includes('vendor-dynamic')) {
const response: Protocol.Network.GetResponseBodyForInterceptionResponse = await client!.Network.getResponseBodyForInterception({ interceptionId });
const response: Protocol.Network.GetResponseBodyForInterceptionResponse
= await client!.Network.getResponseBodyForInterception({ interceptionId });
const scriptText: string = atob(response.body);
const newScriptText: string = scriptText.replace(
/function xsCommon/i, 'window._xsCommon=xsCommon;function xsCommon');
Expand Down Expand Up @@ -159,12 +160,18 @@ function ipcXiaohongshuHandle(): void {
// 获取header的加密
ipcMain.handle(
XiaohongshuHandleChannel.XiaohongshuChromeRemoteSign,
async function(event: IpcMainInvokeEvent, url: string, data: string | undefined): Promise<string | undefined> {
async function(event: IpcMainInvokeEvent, url: string, data: string | undefined, platform: string): Promise<string | undefined> {
await clientSwitch(client, 'www.xiaohongshu.com');

if (client) {
const signResult: Protocol.Runtime.EvaluateResponse = await client.Runtime.evaluate({
expression: `JSON.stringify(window._webmsxyw("${ url }", ${ data ?? 'undefined' }));`
expression: `var headers = window._webmsxyw('${ url }', ${ data ?? 'undefined' });
var args = {
headers,
url: '//edith.xiaohongshu.com${ url }'
};
var xsCommonHeader = window._xsCommon(${ JSON.stringify({ platform }) }, args);
JSON.stringify(args.headers);`
});

return signResult.result.value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class XiaohongshuExpand {
}

static async chromeDevtoolsSign(reqPath: string, data: string | undefined): Promise<SignResult> {
const result: string = await ipcRenderer.invoke(XiaohongshuHandleChannel.XiaohongshuChromeRemoteSign, reqPath, data);
const platform: string = /Mac/i.test(window.navigator.platform) ? 'Mac OS' : (
/Win/i.test(window.navigator.platform) ? 'Windows' : 'Linux');
const result: string = await ipcRenderer.invoke(XiaohongshuHandleChannel.XiaohongshuChromeRemoteSign, reqPath, data, platform);

return JSON.parse(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
type JsonCache,
type MergeData
} from './messageTypes';
import { _xiaohongshuLogProtocol } from '../../../../../utils/logProtocol/logActions';
import type { _UserPostedObject } from '../../../../../../../main/src/logProtocol/logTemplate/xiaohongshu.mjs';

/* 小红书 */
let userId: string;
Expand Down Expand Up @@ -80,6 +82,10 @@ function requestHtml(): Promise<UserPostedResponse | undefined> {
function handleSignMessage(event: MessageEvent<MessageObject>): void {
if (isRequestHtmlMessage(event.data) && id === event.data.id) {
removeEventListener('message', handleSignMessage);
_xiaohongshuLogProtocol.post<_UserPostedObject>('userPosted', {
userId,
response: JSON.stringify(event.data.result, null, 2)
});
resolve(event.data.result);
}
}
Expand Down Expand Up @@ -199,7 +205,7 @@ async function getMergeData(data: Array<PostedNoteItem>): Promise<GetMergeDataRe
/* 小红书轮询 */
async function xiaohongshuListener(): Promise<void> {
try {
const userPostedRes: UserPostedResponse | undefined = await requestHtml();
const userPostedRes: UserPostedResponse = await requestUserPosted(userId, cookieString, signProtocol, port);

if (userPostedRes && userPostedRes.success) {
_isSendDebugMessage && (_debugTimes = 0);
Expand Down Expand Up @@ -269,7 +275,7 @@ EndTime: ${ _endTime }`,
/* 初始化小红书 */
async function xiaohongshuInit(): Promise<void> {
try {
const userPostedRes: UserPostedResponse | undefined = await requestHtml();
const userPostedRes: UserPostedResponse = await requestUserPosted(userId, cookieString, signProtocol, port);

if (userPostedRes && userPostedRes.success) {
const data: Array<PostedNoteItem> = userPostedRes.data.notes ?? [];
Expand Down
5 changes: 3 additions & 2 deletions packages/qqtools/src/services/xiaohongshu/interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface NoteFeedResponse {
}

export interface SignResult {
'X-s': string;
'X-t': string;
'X-S': string;
'X-T': string;
'X-S-Common': string;
}

0 comments on commit 202f20c

Please sign in to comment.