uniApp 开发小程序,并且是第三方开发,根据需求需要从ext.json中写入商户id,从而发布不同商户的版本。

首先将ext.json文件放置到和根目录( 同main.js位置)

{
	"extEnable": true,
	"extAppid": "填入你的extAppId",
	"directCommit": false,
	"ext": {
		"shopId": "自定义内容",
        "name":"自定义内容2",
	}
}


同时你的微信开发者工具,appId需要修改为已被第三方授权的id

 我这边暂时没授权,但是不影响我们拿到ext.json文件的数据内容。

使用uni封装好的同步获取ext.json的api再次封装便于使用和获取指定字段.

utils > 


//同步取出ext.json对象
export function getExtStoreId(type){
	try{
		const extConfig = uni.getExtConfigSync ? uni.getExtConfigSync() : {shopId:'默认的门店id'}
		console.log(extConfig,'extJson对象');
		return extConfig[type];
	}catch(err){
		console.log(err,'getExtStoreId__error')
	}
}

调用并获取

外部使用

storeId = tool.getExtStoreId('shopId');

 

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐