refactor: 优化平台适配器命名规范和登录逻辑
- 将平台标识符从简写改为语义化名称(tt->bytedance, weapp->wechat) - 登录接口动态获取平台类型,提升代码可维护性 - 优化代码格式,统一条件判断样式
This commit is contained in:
parent
f7073fb4f7
commit
be71df2ecd
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue