Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
公众号授权账户
daoyian3a3fea75bcd0
diff --git a/src/api/platAuth.ts b/src/api/platAuth.tsindex 434f162c..57aa4c96 100644--- a/src/api/platAuth.ts+++ b/src/api/platAuth.ts@@ -105,4 +105,21 @@ export const checkTiktokAuthApi = ( taskId:any ) => {url: `/plat/tiktok/auth/info/${taskId}`,method: 'GET',});-};\ No newline at end of file+};+++// 微信授权+export const getWxGzhAuthUrlApi = (mail: string) => {+ return request({+ url: '/plat/wxGzh/auth/url/pc',+ method: 'GET',+ params: { type: 'pc' },+ });+};++export const checkWxGzAuthApi = ( taskId:any ) => {+ return request({+ url: `/plat/wxGzh/auth/info/${taskId}`,+ method: 'GET',+ });+};diff --git a/src/app/[lng]/accounts/components/AddAccountModal/index.tsx b/src/app/[lng]/accounts/components/AddAccountModal/index.tsxindex a27686f2..b4c37d96 100644--- a/src/app/[lng]/accounts/components/AddAccountModal/index.tsx+++ b/src/app/[lng]/accounts/components/AddAccountModal/index.tsx@@ -9,6 +9,7 @@ import { youtubeSkip } from "../../plat/YoutubeLogin";import { twitterSkip } from "../../plat/TwtterLogin";import { tiktokSkip } from "../../plat/TiktokLogin";import { facebookSkip } from "../../plat/FacebookLogin";+import { wxGzhSkip } from "../../plat/WxGzh";export interface IAddAccountModalRef {}@@ -71,6 +72,9 @@ const AddAccountModal = memo(case PlatType.Facebook:await facebookSkip(key);break;+ case PlatType.WxGzh:+ await wxGzhSkip(key);+ break;}}}>diff --git a/src/app/[lng]/accounts/plat/WxGzh.ts b/src/app/[lng]/accounts/plat/WxGzh.tsnew file mode 100644index 00000000..7454077d--- /dev/null+++ b/src/app/[lng]/accounts/plat/WxGzh.ts@@ -0,0 +1,67 @@+import qs from "qs";+import { PlatType } from "@/app/config/platConfig";+import { checkWxGzAuthApi, getWxGzhAuthUrlApi } from "@/api/platAuth";+import { useAccountStore } from "@/store/account";++++/**+ * 微信被点击+ * @param platType+ */+export async function wxGzhSkip(platType: PlatType) {+ if (platType !== PlatType.WxGzh) return;++ const res: any = await getWxGzhAuthUrlApi('pc');+ if (res?.code !== 0) return;+ const url = res.data.url;+ window.open(`${url}`);++ const wxGzhLoginRes = await wxGzhLogin(res.data.taskId);++}++export function wxGzhLogin(taskId:any): Promise<any> {+ return new Promise(async (resolve, reject) => {+ try {+ // 开始轮询检查授权状态+ const checkAuthStatus = async () => {+ try {+ const authRess:any = await checkWxGzAuthApi(taskId);+ let authRes = authRess;+ console.log('authRes', authRes)+ if (authRes?.code === 0 && authRes?.data.status == 1) {+ // message.success('授权成功');+ // useAccountStore+ const accountStore = useAccountStore.getState();+ await accountStore.getAccountList();+ resolve(authRes);+ return true;+ }+ // return false;+ } catch (error) {+ console.error('检查授权状态失败:', error);+ return false;+ }+ };++ // 设置轮询间隔+ const interval = setInterval(async () => {+ const isSuccess = await checkAuthStatus();+ if (isSuccess) {+ clearInterval(interval);+ }+ }, 2000);++ // 5分钟后自动停止轮询+ setTimeout(() => {+ clearInterval(interval);+ // message.error('授权超时,请重试');+ reject(new Error('授权超时'));+ }, 5 * 60 * 1000);++ } catch (e) {+ reject(e);+ }+ });+}diff --git a/src/app/config/platConfig.ts b/src/app/config/platConfig.tsindex 966a2b27..eb6bf1a8 100644--- a/src/app/config/platConfig.ts+++ b/src/app/config/platConfig.ts@@ -6,6 +6,7 @@ import douyinSvg from "@/assets/svgs/plat/douyin.svg";import tiktokSvg from "@/assets/svgs/plat/tiktok.svg";import twitterSvg from "@/assets/svgs/plat/twtter.svg";import facebookSvg from "@/assets/svgs/plat/facebook.svg";+import wxGzhSvg from "@/assets/svgs/plat/wx-sph.svg";// 平台类型export enum PlatType {@@ -109,7 +110,7 @@ export const AccountPlatInfoMap = new Map<PlatType, IAccountPlatInfo>([titleMax: 16,topicMax: 10,},- themeColor: "red",+ themeColor: "blue",},],[@@ -123,7 +124,7 @@ export const AccountPlatInfoMap = new Map<PlatType, IAccountPlatInfo>([titleMax: 16,topicMax: 10,},- themeColor: "red",+ themeColor: "blue",},],[@@ -137,7 +138,7 @@ export const AccountPlatInfoMap = new Map<PlatType, IAccountPlatInfo>([titleMax: 16,topicMax: 10,},- themeColor: "red",+ themeColor: "black",},],[@@ -151,7 +152,21 @@ export const AccountPlatInfoMap = new Map<PlatType, IAccountPlatInfo>([titleMax: 16,topicMax: 10,},- themeColor: "red",+ themeColor: "blue",+ },+ ],+ [+ PlatType.WxGzh,+ {+ name: "微信公众号",+ icon: wxGzhSvg.src,+ url: "https://mp.weixin.qq.com/",+ pubTypes: new Set([PubType.VIDEO]),+ commonPubParamsConfig: {+ titleMax: 16,+ topicMax: 10,+ },+ themeColor: "green",},],]);