微信小程序根据运行环境切换域名

微信小程序根据运行环境切换域名

DansRoh Lv4

微信小程序

微信小程序中根据项目环境,切换域名实现

通过wx.getAccountInfoSync()获取envVersion来判断使用哪个域名

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
let baseUrl:string = '';
let tkbackUrl: string = '';
const { miniProgram: { envVersion } } = wx.getAccountInfoSync();
console.log('envVersion', envVersion)
switch (envVersion) {
case "develop": // 开发版
baseUrl = "https://cs-web.spritarmath.com";
// baseUrl = "http://192.168.20.140:8001";
tkbackUrl = "https://cs-tkback.spritarmath.com";
break;
case "trial": // 体验版
baseUrl = "https://web.spritarmath.com";
tkbackUrl = "https://tkback.spritarmath.com";
break;
default: // 正式版
baseUrl = "https://web.spritarmath.com";
tkbackUrl = "https://tkback.spritarmath.com";
break;
}
export default {
baseUrl,
tkbackUrl,
ossUrl: 'https://cqtech.oss-cn-chengdu.aliyuncs.com/',
serverImg: 'https://filetech.spritarmath.com/weChat/miniProd/', // 服务器图片地址的前缀
homeIndex: '/pages/index/index', // 首页地址
}
  • 标题: 微信小程序根据运行环境切换域名
  • 作者: DansRoh
  • 创建于 : 2023-12-25 00:00:00
  • 更新于 : 2024-06-24 17:16:56
  • 链接: https://blog.shinri.me/2023/12/25/10_微信小程序切换域名/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论
此页目录
微信小程序根据运行环境切换域名