小程序接口域名通过环境版本判断自动切换
This commit is contained in:
@@ -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/'
|
const ApiRootUrl = ApiRoot + '/api/'
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
ApiRoot: ApiRoot,
|
ApiRoot: ApiRoot,
|
||||||
|
envVersion: envVersion,
|
||||||
// 登录
|
// 登录
|
||||||
AuthLoginByWeixin: ApiRootUrl + 'auth/wxLogin', //微信登录
|
AuthLoginByWeixin: ApiRootUrl + 'auth/wxLogin', //微信登录
|
||||||
// 需求
|
// 需求
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
},
|
},
|
||||||
"compileType": "miniprogram",
|
"compileType": "miniprogram",
|
||||||
"libVersion": "3.8.7",
|
"libVersion": "3.8.7",
|
||||||
"appid": "wxa3d241d5017bd962",
|
"appid": "wx51cf161b113d9c07",
|
||||||
"projectname": "tdesign-miniprogram-starter-retail",
|
"projectname": "tdesign-miniprogram-starter-retail",
|
||||||
"simulatorType": "wechat",
|
"simulatorType": "wechat",
|
||||||
"simulatorPluginLibVersion": {},
|
"simulatorPluginLibVersion": {},
|
||||||
|
|||||||
Reference in New Issue
Block a user