From be71df2ecd47f1259d43fba22f66b3af0c814c0e Mon Sep 17 00:00:00 2001 From: imeepos Date: Tue, 9 Sep 2025 10:20:35 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E9=80=82=E9=85=8D=E5=99=A8=E5=91=BD=E5=90=8D=E8=A7=84?= =?UTF-8?q?=E8=8C=83=E5=92=8C=E7=99=BB=E5=BD=95=E9=80=BB=E8=BE=91=20-=20?= =?UTF-8?q?=E5=B0=86=E5=B9=B3=E5=8F=B0=E6=A0=87=E8=AF=86=E7=AC=A6=E4=BB=8E?= =?UTF-8?q?=E7=AE=80=E5=86=99=E6=94=B9=E4=B8=BA=E8=AF=AD=E4=B9=89=E5=8C=96?= =?UTF-8?q?=E5=90=8D=E7=A7=B0(tt->bytedance,=20weapp->wechat)=20-=20?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=8E=A5=E5=8F=A3=E5=8A=A8=E6=80=81=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=B9=B3=E5=8F=B0=E7=B1=BB=E5=9E=8B=EF=BC=8C=E6=8F=90?= =?UTF-8?q?=E5=8D=87=E4=BB=A3=E7=A0=81=E5=8F=AF=E7=BB=B4=E6=8A=A4=E6=80=A7?= =?UTF-8?q?=20-=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=EF=BC=8C=E7=BB=9F=E4=B8=80=E6=9D=A1=E4=BB=B6=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/platforms/factory.ts | 18 +++++++++--------- src/sdk/sdk-server.ts | 8 +++++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/platforms/factory.ts b/src/platforms/factory.ts index ca776f4..13c58c0 100644 --- a/src/platforms/factory.ts +++ b/src/platforms/factory.ts @@ -15,7 +15,7 @@ declare const qq: any; * 支持的平台类型 * 目前支持:字节跳动小程序(tt) */ -export type Platform = 'tt' | 'weapp' | 'alipay' | 'swan' | 'qq'; +export type Platform = 'bytedance' | 'wechat' | 'alipay' | 'swan' | 'qq'; /** * 平台适配器工厂类 @@ -40,11 +40,11 @@ export class PlatformFactory { */ createRewardedVideoAd(): RewardedVideoAd { switch (this.platform) { - case 'tt': + case 'bytedance': return new RewardedVideoAdTT({ adUnitId: 'gncb4kr2b6kwp0uacr' }); - case 'weapp': + case 'wechat': return new RewardedVideoAdWeApp({ adUnitId: 'adunit-xxxxxxxxxxxxxxxx' // 微信广告单元ID,需要开发者配置 }); @@ -62,9 +62,9 @@ export class PlatformFactory { createMedia(): Media { switch (this.platform) { - case 'tt': + case 'bytedance': return new MediaTT(); - case 'weapp': + case 'wechat': return new MediaWeApp(); case 'alipay': throw new Error(`支付宝小程序平台暂未实现`); @@ -80,9 +80,9 @@ export class PlatformFactory { createUserInfo(): UserInfo { switch (this.platform) { - case 'tt': + case 'bytedance': return new UserInfoTT(); - case 'weapp': + case 'wechat': return new UserInfoWeApp(); case 'alipay': throw new Error(`支付宝小程序平台暂未实现`); @@ -119,10 +119,10 @@ export class PlatformFactory { */ static detectPlatform(): Platform { if (typeof tt !== 'undefined') { - return 'tt'; + return 'bytedance'; } if (typeof wx !== 'undefined') { - return 'weapp'; + return 'wechat'; } if (typeof my !== 'undefined') { return 'alipay'; diff --git a/src/sdk/sdk-server.ts b/src/sdk/sdk-server.ts index 2e418d5..7486899 100644 --- a/src/sdk/sdk-server.ts +++ b/src/sdk/sdk-server.ts @@ -1,6 +1,7 @@ import Taro from "@tarojs/taro" import { IToken, IUser } from "./types"; +import { createPlatformFactory } from "../platforms"; const TOKEN_STORAGE_KEY = 'access_token'; const TOKEN_UID_KEY = 'user_uid'; @@ -193,10 +194,10 @@ export class SdkServer { imageUrl: params.imageUrl, }); const data = response.data; - if(typeof data === 'string'){ + if (typeof data === 'string') { return data; } - return data.executionId + return data.executionId } catch (error) { throw error; } @@ -209,8 +210,9 @@ export class SdkServer { */ async login(params: any): Promise<{ tokens: IToken, user: IUser }> { try { + const platform = createPlatformFactory() const response = await this.request<{ tokens: IToken, user: IUser }>(`/api/v1/users/login`, 'POST', { - platform: `bytedance`, + platform: platform.getPlatform(), code: params.code, encryptedData: params.encryptedData, iv: params.iv,