小程序接口域名通过环境版本判断自动切换

This commit is contained in:
Dev
2026-09-21 15:26:44 +08:00
parent 5f4c8147ca
commit 8591e5e99f
2 changed files with 23 additions and 3 deletions
+22 -2
View File
@@ -1,9 +1,29 @@
const ApiRoot = 'http://softmt.cn';
// const ApiRoot = 'https://soft.szcti.com';
// 接口环境:按小程序运行版本自动切换,无需注释切换域名
// develop: 开发者工具运行/真机预览调试 | trial: 上传后的体验版 | release: 审核发布的正式版
const API_ROOTS = {
develop: 'http://codebg.cn', // 本地开发(phpStudy,hosts 需将 codebg.cn 指向 127.0.0.1)
trial: 'https://codebg.cn', // 体验版(线上,需 https + 备案域名)
release: 'https://codebg.cn', // 正式版(线上,需 https + 备案域名)
};
// 当前运行环境,供调试确认(可在 app.js onLaunch 中打印)
let envVersion = 'release';
function getApiRoot() {
try {
envVersion = wx.getAccountInfoSync().miniProgram.envVersion || 'release';
} catch (e) {
// 基础库过低等异常情况,按正式版处理
}
return API_ROOTS[envVersion] || API_ROOTS.release;
}
const ApiRoot = getApiRoot();
const ApiRootUrl = ApiRoot + '/api/'
module.exports = {
ApiRoot: ApiRoot,
envVersion: envVersion,
// 登录
AuthLoginByWeixin: ApiRootUrl + 'auth/wxLogin', //微信登录
// 需求
+1 -1
View File
@@ -52,7 +52,7 @@
},
"compileType": "miniprogram",
"libVersion": "3.8.7",
"appid": "wxa3d241d5017bd962",
"appid": "wx51cf161b113d9c07",
"projectname": "tdesign-miniprogram-starter-retail",
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},