Files
real-e-party-iOS/YuMi/Config/APIConfig.swift
edwinQQQ bf31ffda51 修复 PIBaseModel 依赖链问题
核心修复:
- NewMomentViewController: 改为直接继承 UIViewController
- NewMineViewController: 改为直接继承 UIViewController
- 不再继承 BaseViewController(避免 ClientConfig → PIBaseModel 依赖链)

依赖链问题分析:
BaseViewController → ClientConfig → ClientDataModel → PIBaseModel
ClientConfig 本身也继承自 PIBaseModel

切断依赖链后,Bridging Header 只需要 UIKit + 3 个新模块,
不会引入任何复杂的 Model 依赖。

这样做的好处:
1. 编译不会有 PIBaseModel 错误
2. 新模块完全独立,不依赖旧代码
3. 更符合白牌项目的目标(完全不同的代码结构)
2025-10-09 18:49:44 +08:00

111 lines
3.4 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// APIConfig.swift
// YuMi
//
// Created by AI on 2025-10-09.
// Copyright © 2025 YuMi. All rights reserved.
//
import Foundation
/// API
/// 使 XOR + Base64
@objc class APIConfig: NSObject {
// MARK: - Private Properties
/// XOR
private static let xorKey: UInt8 = 77
/// RELEASE
/// https://api.epartylive.com
private static let releaseEncodedParts: [String] = [
"JTk5PT53YmI=", // https:// (XOR Base64)
"LD0kYw==", // api. (XOR Base64)
"KD0sPzk0ISQ7KGMuIiA=", // epartylive.com (XOR Base64)
]
// MARK: - Public Methods
/// API
/// - Returns:
@objc static func baseURL() -> String {
#if DEBUG
// DEV 使 Bridging HttpRequestHelper
// TODO: return HttpRequestHelper.getHostUrl()
return getDevBaseURL()
#else
// RELEASE 使
let url = decodeURL(from: releaseEncodedParts)
//
if url.isEmpty || !url.hasPrefix("http") {
NSLog("[APIConfig] 警告:域名解密失败,使用备用域名")
return backupURL()
}
return url
#endif
}
/// DEV
/// - Returns: DEV
private static func getDevBaseURL() -> String {
// UserDefaults HttpRequestHelper
#if DEBUG
let isProduction = UserDefaults.standard.string(forKey: "kIsProductionEnvironment")
if isProduction == "YES" {
return "https://api.epartylive.com" //
} else {
return "https://test-api.yourdomain.com" //
}
#else
return "https://api.epartylive.com"
#endif
}
///
/// - Returns: 使
@objc static func backupURL() -> String {
return getDevBaseURL()
}
// MARK: - Private Methods
///
/// - Parameter parts:
/// - Returns:
private static func decodeURL(from parts: [String]) -> String {
let decoded = parts.compactMap { part -> String? in
guard let data = Data(base64Encoded: part) else {
NSLog("[APIConfig] Base64 解码失败: \(part)")
return nil
}
let xored = data.map { $0 ^ xorKey }
return String(bytes: xored, encoding: .utf8)
}
let result = decoded.joined()
#if DEBUG
NSLog("[APIConfig] 解密后的域名: \(result)")
#endif
return result
}
}
// MARK: - Debug Helper
#if DEBUG
extension APIConfig {
/// /
@objc static func testEncryption() {
print("=== APIConfig 加密测试 ===")
print("Release 域名: \(decodeURL(from: releaseEncodedParts))")
print("当前环境域名: \(baseURL())")
print("备用域名: \(backupURL())")
}
}
#endif