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,