Skip to content

Let's use AI to Earn!

feat: 主进程位置添加数据完成

gaoSir10749f99bf80
diff --git a/electron/main/plat/PlatformBase.ts b/electron/main/plat/PlatformBase.ts
index b53a3b6d..28cf1f64 100644
--- a/electron/main/plat/PlatformBase.ts
+++ b/electron/main/plat/PlatformBase.ts
@@ -9,8 +9,10 @@ import {
AccountInfoTypeRV,
DashboardData,
IAccountInfoParams,
+ IGetLocationDataParams,
IGetTopicsParams,
IGetTopicsResponse,
+ ILocationDataItem,
IVideoPublishParams,
StatisticsData,
VideoCallbackType,
@@ -82,4 +84,10 @@ export abstract class PlatformBase {
// 获取这个平台的话题
abstract getTopics(params: IGetTopicsParams): Promise<IGetTopicsResponse>;
+
+ // 获取位置数据
+ abstract getLocationData(params: IGetLocationDataParams): Promise<{
+ status: number;
+ data: ILocationDataItem[];
+ }>;
}
diff --git a/electron/main/plat/index.ts b/electron/main/plat/index.ts
index 3a99ae1d..3e5fdf5d 100644
--- a/electron/main/plat/index.ts
+++ b/electron/main/plat/index.ts
@@ -11,7 +11,7 @@ import kwai from './platforms/Kwai';
import xhs from './platforms/xhs';
import douyin from './platforms/douyin';
import wxSph from './platforms/wxSph';
-import { IAccountInfoParams } from './plat.type';
+import { IAccountInfoParams, IGetLocationDataParams } from './plat.type';
import { PublishVideoResult } from './module';
import { VideoModel } from '../../db/models/video';
import { PubItemVideo } from './pub/PubItemVideo';
@@ -82,7 +82,7 @@ class PlatController {
}
/**
- * 获取某个平台的话题
+ * 获取某个平台的话题数据
* @param account
* @param keyword
*/
@@ -122,6 +122,15 @@ class PlatController {
const platform = this.platforms.get(account.type)!;
return await platform.getDashboard(account, time || []);
}
+
+ // 获取位置数据
+ public async getLocationData(params: IGetLocationDataParams) {
+ const platform = this.platforms.get(params.account!.type)!;
+ return await platform.getLocationData({
+ ...params,
+ cookie: JSON.parse(params.account!.loginCookie),
+ });
+ }
}
const platController = new PlatController();
diff --git a/electron/main/plat/plat.type.ts b/electron/main/plat/plat.type.ts
index b0887f80..f5a150d9 100644
--- a/electron/main/plat/plat.type.ts
+++ b/electron/main/plat/plat.type.ts
@@ -93,3 +93,24 @@ export interface IGetTopicsParams {
keyword: string;
account: AccountModel;
}
+
+// 话题参数
+export interface IGetLocationDataParams {
+ keywords: string;
+ latitude: number;
+ longitude: number;
+ cookie?: Electron.Cookie[];
+ account?: AccountModel;
+}
+
+// 地点数据
+export interface ILocationDataItem {
+ // 地点名称
+ name: string;
+ // 简单地址简介
+ simpleAddress: string;
+ // 地址ID
+ id: string;
+ // 距离
+ distance: string;
+}
diff --git a/electron/main/plat/platforms/Kwai/index.ts b/electron/main/plat/platforms/Kwai/index.ts
index edf744ef..fa41fe8c 100644
--- a/electron/main/plat/platforms/Kwai/index.ts
+++ b/electron/main/plat/platforms/Kwai/index.ts
@@ -9,6 +9,7 @@ import { PlatformBase } from '../../PlatformBase';
import {
AccountInfoTypeRV,
IAccountInfoParams,
+ IGetLocationDataParams,
IGetTopicsParams,
IGetTopicsResponse,
IVideoPublishParams,
@@ -128,6 +129,13 @@ export class Kwai extends PlatformBase {
}),
};
}
+
+ async getLocationData(params: IGetLocationDataParams) {
+ return {
+ status: 400,
+ data: [],
+ };
+ }
}
const kwai = new Kwai();
diff --git a/electron/main/plat/platforms/douyin/index.ts b/electron/main/plat/platforms/douyin/index.ts
index fbe36e81..2cde9588 100644
--- a/electron/main/plat/platforms/douyin/index.ts
+++ b/electron/main/plat/platforms/douyin/index.ts
@@ -11,6 +11,7 @@ import {
CookiesType,
DashboardData,
IAccountInfoParams,
+ IGetLocationDataParams,
IGetTopicsParams,
IGetTopicsResponse,
IVideoPublishParams,
@@ -186,6 +187,27 @@ export class Douyin extends PlatformBase {
}),
};
}
+
+ // 获取热点数据
+ async getHotData(query: string) {
+ const hotDataRes = await douyinService.getHotspotData({ query });
+ return hotDataRes.data;
+ }
+
+ async getLocationData(params: IGetLocationDataParams) {
+ const locationRes = await douyinService.getLocation(params);
+ return {
+ status: locationRes.status,
+ data: locationRes.data.poi_list.map((v) => {
+ return {
+ name: v.poi_name,
+ simpleAddress: v.simple_address_str,
+ id: v.poi_id,
+ distance: v.distance,
+ };
+ }),
+ };
+ }
}
const douyin = new Douyin();
diff --git a/electron/main/plat/platforms/wxSph/index.ts b/electron/main/plat/platforms/wxSph/index.ts
index 5c25802f..cb9e58ee 100644
--- a/electron/main/plat/platforms/wxSph/index.ts
+++ b/electron/main/plat/platforms/wxSph/index.ts
@@ -11,6 +11,7 @@ import {
CookiesType,
DashboardData,
IAccountInfoParams,
+ IGetLocationDataParams,
IGetTopicsParams,
IGetTopicsResponse,
IVideoPublishParams,
@@ -159,6 +160,33 @@ export class WxSph extends PlatformBase {
status: 400,
});
}
+
+ async getLocationData(params: IGetLocationDataParams) {
+ const locationRes = await shipinhaoService.getLocation({
+ ...params,
+ keyword: params.keywords,
+ });
+ return {
+ status: locationRes.status,
+ data: locationRes.data.data.list.map((v) => {
+ return {
+ name: v.name,
+ simpleAddress: v.fullAddress,
+ id: v.poiCheckSum,
+ distance: '',
+ };
+ }),
+ };
+ }
+
+ // 获取商品号的活动列表
+ async getActivityList(params: { cookie: Electron.Cookie[]; query: string }) {
+ const activityRes = await shipinhaoService.getActivityList(params);
+ return {
+ status: activityRes.status,
+ data: activityRes.data,
+ };
+ }
}
const wxSph = new WxSph();
diff --git a/electron/main/plat/platforms/xhs/index.ts b/electron/main/plat/platforms/xhs/index.ts
index d5ced0cc..facbc29c 100644
--- a/electron/main/plat/platforms/xhs/index.ts
+++ b/electron/main/plat/platforms/xhs/index.ts
@@ -11,6 +11,7 @@ import {
CookiesType,
DashboardData,
IAccountInfoParams,
+ IGetLocationDataParams,
IGetTopicsParams,
IGetTopicsResponse,
IVideoPublishParams,
@@ -196,6 +197,25 @@ export class Xhs extends PlatformBase {
}),
};
}
+
+ async getLocationData(params: IGetLocationDataParams) {
+ const locationRes = await xiaohongshuService.getLocations({
+ ...params,
+ keyword: params.keywords,
+ cookies: params.cookie,
+ });
+ return {
+ status: locationRes.status,
+ data: locationRes.data.data.poi_list.map((v) => {
+ return {
+ name: v.name,
+ simpleAddress: v.full_address,
+ id: v.poi_id,
+ distance: '',
+ };
+ }),
+ };
+ }
}
const xhs = new Xhs();
diff --git a/electron/main/publish/controller.ts b/electron/main/publish/controller.ts
index 90dc06d0..0dc9bf05 100644
--- a/electron/main/publish/controller.ts
+++ b/electron/main/publish/controller.ts
@@ -16,6 +16,7 @@ import { VideoPubService } from './video/service';
import { VideoModel } from '../../db/models/video';
import platController from '../plat';
import { AccountModel } from '../../db/models/account';
+import type { IGetLocationDataParams } from '../plat/plat.type';
@Controller()
export class PublishController {
@@ -145,4 +146,13 @@ export class PublishController {
) {
return await platController.getTopic(account, keyword);
}
+
+ // 获取位置数据
+ @Icp('ICP_PUBLISH_GET_LOCATION')
+ async getLocationData(
+ event: Electron.IpcMainInvokeEvent,
+ params: IGetLocationDataParams,
+ ) {
+ return await platController.getLocationData(params);
+ }
}
diff --git a/electron/plat/douyin/index.ts b/electron/plat/douyin/index.ts
index 61c54720..c0b54a57 100644
--- a/electron/plat/douyin/index.ts
+++ b/electron/plat/douyin/index.ts
@@ -6,7 +6,7 @@ import * as crypto from 'crypto';
import { v4 as uuidv4 } from 'uuid';
// @ts-ignore
import crc32 from 'crc32';
-import { CookieToString, getFileContent } from '../utils';
+import { getFileContent } from '../utils';
import {
DouyinLocationDataResponse,
DouyinTopicsSugResponse,
@@ -2001,9 +2001,8 @@ export class DouyinService {
// 获取位置数据
async getLocation(params: {
keywords: string;
- latitude: string;
- longitude: string;
- cookie: Electron.Cookie[];
+ latitude: number;
+ longitude: number;
}) {
return await requestNet<DouyinLocationDataResponse>({
url: `${this.loginUrl}aweme/v1/life/video_api/search/poi/?${jsonToQueryString(
@@ -2014,23 +2013,17 @@ export class DouyinService {
},
)}`,
method: 'GET',
- headers: {
- cookie: CookieToString(params.cookie),
- },
});
}
// 获取热点数据
- async getHotspotData(params: { query: string; cookie: Electron.Cookie[]; }) {
+ async getHotspotData(params: { query: string }) {
return await requestNet<DouyinLocationDataResponse>({
url: `${this.loginUrl}aweme/v1/hotspot/search/?${jsonToQueryString({
...params,
count: 50,
})}`,
method: 'GET',
- headers: {
- cookie: CookieToString(params.cookie),
- },
});
}
}
diff --git a/electron/plat/shipinhao/index.ts b/electron/plat/shipinhao/index.ts
index c1ae4cf7..242dc130 100644
--- a/electron/plat/shipinhao/index.ts
+++ b/electron/plat/shipinhao/index.ts
@@ -4,7 +4,7 @@ import path from 'path';
import { FileUtils } from '../../util/file';
import { CookieToString, getFileContent } from '../utils';
import requestNet from '../requestNet';
-import { DouyinTopicsSugResponse } from '../douyin/douyin.type';
+import { WeChatLocationData } from './wxShp.type';
interface UserInfo {
authorId: string;
@@ -1313,7 +1313,7 @@ export class ShipinhaoService {
latitude: number;
cookie: Electron.Cookie[];
}) {
- return await requestNet<DouyinTopicsSugResponse>({
+ return await requestNet<WeChatLocationData>({
url: `https://channels.weixin.qq.com/cgi-bin/mmfinderassistant-bin/helper/helper_search_location`,
method: 'POST',
body: params,
@@ -1322,6 +1322,18 @@ export class ShipinhaoService {
},
});
}
+
+ // 获取商品号的活动
+ async getActivityList(params: { cookie: Electron.Cookie[]; query: string }) {
+ return await requestNet<WeChatLocationData>({
+ url: `https://channels.weixin.qq.com/cgi-bin/mmfinderassistant-bin/post/post_search_event`,
+ method: 'POST',
+ body: params,
+ headers: {
+ cookie: CookieToString(params.cookie),
+ },
+ });
+ }
}
// 导出服务实例
diff --git a/electron/plat/xiaohongshu/index.ts b/electron/plat/xiaohongshu/index.ts
index 8033525a..5bc5f3e1 100644
--- a/electron/plat/xiaohongshu/index.ts
+++ b/electron/plat/xiaohongshu/index.ts
@@ -1287,8 +1287,8 @@ export class XiaohongshuService {
keyword: string;
page?: number;
size?: number;
- source: string;
- type: number;
+ source?: string;
+ type?: number;
cookies: Electron.Cookie[];
}) {
return await requestNet<IXHSLocationResponse>({
@@ -1300,6 +1300,8 @@ export class XiaohongshuService {
...params,
page: 1,
size: 50,
+ source: 'WEB',
+ type: 3,
},
});
}