diff --git a/miniprogram/lefu/config.ts b/miniprogram/lefu/config.ts index e860741..2a2ebaa 100644 --- a/miniprogram/lefu/config.ts +++ b/miniprogram/lefu/config.ts @@ -1,11 +1,25 @@ import type { LeFuConfig } from './types' +import { ENV, type EnvType } from '../utils/env/index' + +/** 各环境配网网关地址:develop / trial 走测试网关,release 走正式网关 */ +const DOMAINS: Record = { + develop: { + domain1: 'http://10.10.10.10:8889', + domain2: 'http://10.10.10.10:8889/weight', + }, + trial: { + domain1: 'http://10.10.10.10:8889', + domain2: 'http://10.10.10.10:8889/weight', + }, + release: { + domain1: 'http://device.shuziweidao.com:80/gateway', + domain2: 'http://device.shuziweidao.com:80/weight', + }, +} /** 乐福 SDK 配置 */ export const LEFU_CONFIG: LeFuConfig = { key: 'lefudc91611833e18d94', secret: 'eQ50JYimMp0X7uhNLj6D3lTEk4TUUvEG7dvaqKM9t1U=', - // domain1: 'http://10.10.10.10:8889', - // domain2: 'http://10.10.10.10:8889/weight', - domain1: 'http://device.shuziweidao.com:80/gateway', - domain2: 'http://device.shuziweidao.com:80/weight', + ...DOMAINS[ENV], } diff --git a/miniprogram/utils/env/index.ts b/miniprogram/utils/env/index.ts new file mode 100644 index 0000000..00be152 --- /dev/null +++ b/miniprogram/utils/env/index.ts @@ -0,0 +1,12 @@ +import type { EnvType } from './types' + +export type { EnvType } + +/** 获取当前运行环境,基础库不支持 getAccountInfoSync 时回退 develop */ +export const ENV: EnvType = (() => { + try { + return wx.getAccountInfoSync().miniProgram.envVersion as EnvType + } catch { + return 'develop' + } +})() diff --git a/miniprogram/utils/env/types.ts b/miniprogram/utils/env/types.ts new file mode 100644 index 0000000..34790c3 --- /dev/null +++ b/miniprogram/utils/env/types.ts @@ -0,0 +1,2 @@ +/** 小程序运行环境:develop 开发版 / trial 体验版 / release 正式版 */ +export type EnvType = 'develop' | 'trial' | 'release' diff --git a/miniprogram/utils/request/config.ts b/miniprogram/utils/request/config.ts index c0f65f1..e87cd60 100644 --- a/miniprogram/utils/request/config.ts +++ b/miniprogram/utils/request/config.ts @@ -1,8 +1,12 @@ -// TODO: 替换为实际接口地址 -const IS_DEV = true +import { ENV, type EnvType } from '../env/index' -export const BASE_URL = IS_DEV - ? 'http://10.10.10.10:8889/' - : '' +/** 各环境接口网关地址:develop / trial 走测试网关,release 走正式网关 */ +const BASE_URLS: Record = { + develop: 'http://10.10.10.10:8889/', + trial: 'http://10.10.10.10:8889/', + release: 'https://device.shuziweidao.com/gateway/', +} + +export const BASE_URL = BASE_URLS[ENV] export const TIMEOUT = 30000