CNLiveEnvironment.swift 5.24 KB
//
//  CNLiveEnvironment.swift
//  metaCode
//
//  Created by daojian on 2023/6/15.
//

import Foundation

///当前应用的APPID
let APPId: String  = CNLiveEnvironmentManager.shared.appId
///当前应用的APPKey
let APPKey: String = CNLiveEnvironmentManager.shared.appKey
///网家家应用的APPID
let APPId_wjj: String  = CNLiveEnvironmentManager.shared.appId_wjj
///网家家应用的APPKey
let APPKey_wjj: String = CNLiveEnvironmentManager.shared.appKey_wjj
///当前应用的登录请求域名
let APPLoginHost: String! = CNLiveEnvironmentManager.shared.loginHost
///当前应用的Secret
let APPSecret: String = CNLiveEnvironmentManager.shared.appSecret
///当前应用的部分请求接口
let APPBaseMCUrl: String = CNLiveEnvironmentManager.shared.base_mc_url
/// 网家家内接口
let APPBaseWjjUrl: String = CNLiveEnvironmentManager.shared.base_wjj_url
/// 网家家内电商接口
let APPBaseWjjShopUrl: String = CNLiveEnvironmentManager.shared.base_mjj_shop_url

///当前APP的环境
let APPCurrentEnvironment: CNLiveEnvironment = CNLiveEnvironmentManager.shared.currentEnvironment

///是否是开发环境
let IsDevEnvironment: Bool = (CNLiveEnvironmentManager.shared.currentEnvironment == .development)
///是否是testFlight 环境
let IsTestFlightEnvironment: Bool = (CNLiveEnvironmentManager.shared.currentEnvironment == .testFlight)
///是否是线上环境
let IsProductionEnvironment: Bool = (CNLiveEnvironmentManager.shared.currentEnvironment == .production)

///APP 环境类型
enum CNLiveEnvironment {
    ///开发环境
    case development
    ///testFlight 环境
    case testFlight
    ///线上环境
    case production
    
}

class CNLiveEnvironmentManager: NSObject{
    
    //单例类
    static let shared = CNLiveEnvironmentManager()
    
    var appId: String
    var appKey: String
    var appId_wjj: String
    var appKey_wjj: String
    var appSecret: String
    ///登录接口域名
    var loginHost: String
    /// 码云项目的主域名
    var base_mc_url: String
    /// 网家家域名请求
    var base_wjj_url: String
    /// 获取IM token 请求域名
    var img_token_url: String
    /// 网家家电商域名请求
    var base_mjj_shop_url: String
    /// 元码webViewUA设置
    var base_web_UA: String = "yuanma"
    
    ///当前环境
    var currentEnvironment: CNLiveEnvironment
    
    //重新init方法为私有,不让外部调用
    private override init() {
        self.appId = ""
        self.appKey = ""
        self.appId_wjj = ""
        self.appKey_wjj = ""
        self.loginHost = ""
        self.appSecret = ""
        self.base_mc_url = ""
        self.img_token_url = ""
        self.base_wjj_url = ""
        self.base_mjj_shop_url = ""
        self.currentEnvironment = .development
    }
    //重新copy 和 mutableCopy 方法
    override func copy() -> Any {
        return self
    }
    
    override func mutableCopy() -> Any {
        return self
    }
    
    //配置环境
    func setupEnvironment(environment: CNLiveEnvironment){
        
        self.currentEnvironment = environment
        
        switch environment {
        case .development:
            self.developmentEnvironment()
        case .testFlight:
            self.testFlightEnvironment()
        case .production:
            self.productionEnvironment()
        }
    }
    
    //开发环境配置
    func developmentEnvironment(){
        self.appId = "802_li40qhp922"
        self.appKey = "ae3a7ad3e4b9beb7cfe2078db648ebb89aa249ca2e82ac"
        self.appId_wjj = "769_jetj7bq525"
        self.appKey_wjj = "0d57b045ec0c3988a682d94c644e66b9b8e0d2b8ef937d"
        self.appSecret = "3cc9f12db322a3d3656012ef929604cf6d6847471535f9"
        self.loginHost = "https://api.cnlive.com"
        self.img_token_url = "https://api.cnlive.com/open/api2"
        self.base_mc_url = "https://metacode.cnlive.com/api"
        self.base_wjj_url = "https://apiwjj.cnlive.com"
        self.base_mjj_shop_url = "https://manageshop.cnlive.com"
    }
    //testFlight 环境配置
    func testFlightEnvironment(){
        self.appId = "802_li40qhp922"
        self.appKey = "ae3a7ad3e4b9beb7cfe2078db648ebb89aa249ca2e82ac"
        self.appId_wjj = "769_jetj7bq525"
        self.appKey_wjj = "0d57b045ec0c3988a682d94c644e66b9b8e0d2b8ef937d"
        self.appSecret = "3cc9f12db322a3d3656012ef929604cf6d6847471535f9"
        self.loginHost = "https://api.cnlive.com"
        self.img_token_url = "https://api.cnlive.com/open/api2"
        self.base_mc_url = "https://metacode.cnlive.com/api"
        self.base_wjj_url = "https://apiwjj.cnlive.com"
        self.base_mjj_shop_url = "https://manageshop.cnlive.com"
    }
    //production 生产环境配置
    func productionEnvironment(){
        self.appId = "769_li40lrkt53"
        self.appKey = "064f392f84dfe7bbe9f1eabeda53ea02044213019b0406"
        self.appId_wjj = "769_jetj7bq525"
        self.appKey_wjj = "0d57b045ec0c3988a682d94c644e66b9b8e0d2b8ef937d"
        self.appSecret = "68b5cc42fbdb466d56c2e22b00b1494feec8149f9dd32e"
        self.loginHost = "https://api.cnlive.com"
        self.img_token_url = "https://api.cnlive.com/open/api2"
        self.base_mc_url = "https://metacode.cnlive.com/api"
        self.base_wjj_url = "https://apiwjj.cnlive.com"
        self.base_mjj_shop_url = "https://manageshop.cnlive.com"
    }
    
}