Skip to content

Let's use AI to Earn!

feat: 小红书登录改为从小红书登录,而不是创作者中心,因为小红书登录了之后创作者中心可以凭借小红书的cookie直接登录,而小红书不能凭借创作者中心的cookie登录。

gaoSird4c79ba7bcbe
diff --git a/electron/main/plat/platforms/douyin/index.ts b/electron/main/plat/platforms/douyin/index.ts
index 540c6791..2d79973b 100644
--- a/electron/main/plat/platforms/douyin/index.ts
+++ b/electron/main/plat/platforms/douyin/index.ts
@@ -63,7 +63,7 @@ export class Douyin extends PlatformBase {
loginTime: new Date(),
type: this.type,
uid: userInfo.authorId,
- account: userInfo.authorId,
+ account: userInfo.uid,
avatar: userInfo.avatar,
nickname: userInfo.nickname,
token: data.localStorage,
diff --git a/electron/plat/douyin/index.ts b/electron/plat/douyin/index.ts
index 85dcc7f2..3d5541e1 100644
--- a/electron/plat/douyin/index.ts
+++ b/electron/plat/douyin/index.ts
@@ -344,6 +344,7 @@ export class DouyinService {
if (res.status_code === 0) {
resolve({
+ uid: res.user.sec_uid,
authorId:
res.user.unique_id !== '' ? res.user.unique_id : res.user.uid,
nickname: res.user.nickname ?? '',
diff --git a/electron/plat/xiaohongshu/index.ts b/electron/plat/xiaohongshu/index.ts
index d70f94cc..c0e33f5a 100644
--- a/electron/plat/xiaohongshu/index.ts
+++ b/electron/plat/xiaohongshu/index.ts
@@ -15,7 +15,7 @@ export class XiaohongshuService {
private defaultUserAgent =
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36';
private loginUrl = 'https://creator.xiaohongshu.com/';
- // private loginUrl = 'https://www.xiaohongshu.com/';
+ private loginUrlHome = 'https://www.xiaohongshu.com/';
private getUserInfoUrl =
'https://creator.xiaohongshu.com/api/galaxy/user/info';
private getDashboardUrl =
@@ -28,9 +28,9 @@ export class XiaohongshuService {
'https://edith.xiaohongshu.com/web_api/sns/v2/note';
private fileBlockSize = 5242880;
private cookieCheckField = 'access-token';
- // private cookieCheckField = 'web_session';
private cookieIntervalList: { [key: string]: NodeJS.Timer } = {};
private prev_web_session = '';
+ private win?: BrowserWindow;
/**
* 授权|预览
@@ -115,8 +115,9 @@ export class XiaohongshuService {
}
// 加载登录页
- await win.loadURL(this.loginUrl);
+ await win.loadURL(this.loginUrlHome);
+ this.win = win;
return {
winContentsId: win.id,
partition,
@@ -131,33 +132,51 @@ export class XiaohongshuService {
partition: string,
): Promise<Electron.Cookie[]> {
return new Promise((resolve, reject) => {
+ console.log('----------------------');
+ this.win!.webContents.openDevTools();
// Monitor cookie status with interval
this.cookieIntervalList[winContentsId] = setInterval(async () => {
try {
- const cookies = await session.fromPartition(partition).cookies.get({
- url: this.loginUrl,
- });
- // const web_session = cookies.find((v) => v.name === 'web_session');
- // if (!this.prev_web_session) {
- // this.prev_web_session = web_session?.value || '';
- // }
- /**
- * 因为小红书的cookie字段始终存在
- * 所以判断cookie是否进行更改
- */
- // if (this.prev_web_session === (web_session?.value || '')) return;
-
- const alreadyLogin = cookies.some((cookie) => {
- return cookie.name.includes(this.cookieCheckField);
- });
- if (alreadyLogin) {
- // Clear interval
- if (this.cookieIntervalList[winContentsId]) {
- clearInterval(this.cookieIntervalList[winContentsId] as any);
- delete this.cookieIntervalList[winContentsId];
+ console.log(
+ this.win!.webContents.getURL().includes(this.loginUrlHome),
+ );
+ console.log(this.win!.webContents.getURL().includes(this.loginUrl));
+ if (this.win!.webContents.getURL().includes(this.loginUrlHome)) {
+ const cookies2 = await session
+ .fromPartition(partition)
+ .cookies.get({
+ url: this.loginUrlHome,
+ });
+ const web_session = cookies2.find((v) => v.name === 'web_session');
+ if (!this.prev_web_session) {
+ this.prev_web_session = web_session?.value || '';
}
+ if (this.prev_web_session === (web_session?.value || '')) return;
+ await this.win!.loadURL(this.loginUrl + 'login?source=official');
+ } else if (this.win!.webContents.getURL().includes(this.loginUrl)) {
+ const cookies1 = await session
+ .fromPartition(partition)
+ .cookies.get({
+ url: this.loginUrl,
+ });
+ const cookies2 = await session
+ .fromPartition(partition)
+ .cookies.get({
+ url: this.loginUrlHome,
+ });
+ const cookies = cookies1.concat(cookies2);
+ const alreadyLogin = cookies1.some((cookie) => {
+ return cookie.name.includes(this.cookieCheckField);
+ });
+ if (alreadyLogin) {
+ // Clear interval
+ if (this.cookieIntervalList[winContentsId]) {
+ clearInterval(this.cookieIntervalList[winContentsId] as any);
+ delete this.cookieIntervalList[winContentsId];
+ }
- resolve(cookies);
+ resolve(cookies);
+ }
}
} catch (error) {
// Clear interval on error
diff --git a/src/components/WebView/index.tsx b/src/components/WebView/index.tsx
index 708e5cc6..d481da86 100644
--- a/src/components/WebView/index.tsx
+++ b/src/components/WebView/index.tsx
@@ -10,19 +10,23 @@ import { generateUUID } from '../../utils';
import styles from './webView.module.scss';
import { Spin } from 'antd';
import { ICookieParams } from '../../../electron/main/account/BrowserWindow/browserWindow';
+import { AccountInfo } from '../../views/account/comment';
+import { AccountType } from '../../../commont/AccountEnum';
export interface IWebViewRef {}
export interface IWebViewProps {
url: string;
cookieParams?: ICookieParams;
- jsCode?: string;
+ // 是否开启沙盒化模式
+ partition?: boolean;
+ account?: AccountInfo;
}
const WebView = memo(
forwardRef(
(
- { url, cookieParams, jsCode }: IWebViewProps,
+ { url, cookieParams, partition, account }: IWebViewProps,
ref: ForwardedRef<IWebViewRef>,
) => {
const webviewRef = useRef<HTMLWebViewElement>(null);
@@ -34,8 +38,18 @@ const WebView = memo(
useEffect(() => {
setLoading(true);
+
webviewRef.current?.addEventListener('dom-ready', async () => {
- if (jsCode) {
+ // 每个平台localStorage添加
+ if (account) {
+ let jsCode;
+ if (account?.type === AccountType.Douyin) {
+ jsCode = `
+ localStorage.setItem('douyin_web_hide_guide', '1');
+ localStorage.setItem('user_info', '{"uid":"${account.account}","nickname":"${account.nickname}","avatarUrl":"${account.avatar}"}');
+ localStorage.setItem('useShortcut2', '{"Wed Mar 12 2025":false}');
+ `;
+ }
// @ts-ignore
webviewRef.current!.executeJavaScript(jsCode);
}
@@ -70,9 +84,9 @@ const WebView = memo(
<webview
ref={webviewRef}
webpreferences="sandbox"
- src={!jsCode ? (loading ? 'about:blank' : url) : url}
+ src={loading ? 'about:blank' : url}
style={{ width: '100%', height: '100%' }}
- partition={partitionId.current}
+ partition={partition ? partitionId.current : undefined}
useragent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0"
></webview>
</Spin>
diff --git a/src/views/publish/children/pubRecord/page.tsx b/src/views/publish/children/pubRecord/page.tsx
index 14737c85..718c382d 100644
--- a/src/views/publish/children/pubRecord/page.tsx
+++ b/src/views/publish/children/pubRecord/page.tsx
@@ -160,7 +160,6 @@ export default function Page() {
{examineVideo.account && open ? (
<WebView
url={examineVideo.url}
- jsCode={examineVideo.jsCode}
cookieParams={{
cookies: JSON.parse(examineVideo.account.loginCookie),
}}
@@ -242,18 +241,16 @@ export default function Page() {
type="link"
onClick={() => {
if (!v.dataId) return;
+ console.log(v);
setExamineVideo((prevState) => {
const newState = { ...prevState };
newState.open = true;
newState.account = account;
+
if (account?.type === AccountType.Douyin) {
newState.url = `https://www.douyin.com/user/self?from_tab_name=main&modal_id=${v.dataId}&showTab=post`;
- newState.jsCode = `
- localStorage.setItem('douyin_web_hide_guide', '1');
- localStorage.setItem('user_info', '1');
- localStorage.setItem('user_info_passport', '1');
- localStorage.setItem('useShortcut2', '{"Wed Mar 12 2025":false}');
- `;
+ } else {
+ newState.url = `https://www.xiaohongshu.com/explore/67d18664000000000903814a?xsec_token=YBMab332BXv8-5Do5w8-AfCUsQpEry-xdpKLyG1y_g67k%3D&xsec_source=pc_creatormng`;
}
return newState;
});