'use strict'; const configCenter = require('uni-config-center') const OauthConfig = { 'mp-weixin': ['mp-weixin', 'oauth', 'weixin'], 'h5-weixin': ['web', 'oauth', 'h5-weixin'] } class ConfigBase { constructor() { this._ready = false this._uniId = null const uniIdConfig = configCenter({ pluginId: 'uni-id' }) this._uniId = uniIdConfig.config() this._ready = true } getAppConfig(appid) { if (Array.isArray(this._uniId)) { return this._uniId.find((item) => { return (item.dcloudAppid === appid) }) } return this._uniId } get ready() { return this._ready } } class AppConfig extends ConfigBase { constructor() { super() } get(appid, platform) { if (!this.isSupport(platform)) { return null } let appConfig = this.getAppConfig(appid) if (!appConfig) { return null } return this.getOauthConfig(appConfig, platform) } isSupport(platformName) { return (AppConfig.Support_Platforms.indexOf(platformName) >= 0) } getOauthConfig(appConfig, platformName) { let tree = OauthConfig[platformName] let node = appConfig for (let i = 0; i < tree.length; i++) { let nodeName = tree[i] if (node[nodeName]) { node = node[nodeName] } else { node = null break } } if (node && node.appid && node.appsecret) { return { appid: node.appid, secret: node.appsecret } } return null } } AppConfig.Support_Platforms = ['mp-weixin', 'h5-weixin'] module.exports = { AppConfig };