feat: 更新Podfile和Podfile.lock,移除Alamofire依赖并添加API认证机制文档

- 注释掉Podfile中的Alamofire依赖,更新Podfile.lock以反映更改。
- 在yana/APIs/API-README.md中新增自动认证Header机制的详细文档,描述其工作原理、实现细节及最佳实践。
- 在yana/yanaApp.swift中将print语句替换为debugInfo以增强调试信息的输出。
- 在API相关文件中实现用户认证状态检查和相关header的自动添加逻辑,提升API请求的安全性和用户体验。
- 更新多个文件中的日志输出,确保在DEBUG模式下提供详细的调试信息。
This commit is contained in:
edwinQQQ
2025-07-11 16:53:46 +08:00
parent 750eecf6ff
commit f9f3dec53f
30 changed files with 537 additions and 219 deletions

View File

@@ -5,8 +5,8 @@ struct DESEncryptOCTest {
/// OC DES
static func testOCDESEncryption() {
print("🧪 开始测试 OC 版本的 DES 加密...")
print(String(repeating: "=", count: 50))
debugInfo("🧪 开始测试 OC 版本的 DES 加密...")
debugInfo(String(repeating: "=", count: 50))
let key = "1ea53d260ecf11e7b56e00163e046a26"
let testCases = [
@@ -19,25 +19,25 @@ struct DESEncryptOCTest {
for testCase in testCases {
if let encrypted = DESEncrypt.encryptUseDES(testCase, key: key) {
print("✅ 加密成功:")
print(" 原文: \"\(testCase)\"")
print(" 密文: \(encrypted)")
debugInfo("✅ 加密成功:")
debugInfo(" 原文: \"\(testCase)\"")
debugInfo(" 密文: \(encrypted)")
//
if let decrypted = DESEncrypt.decryptUseDES(encrypted, key: key) {
let isMatch = decrypted == testCase
print(" 解密: \"\(decrypted)\" \(isMatch ? "" : "")")
debugInfo(" 解密: \"\(decrypted)\" \(isMatch ? "" : "")")
} else {
print(" 解密: 失败 ❌")
debugError(" 解密: 失败 ❌")
}
} else {
print("❌ 加密失败: \"\(testCase)\"")
debugError("❌ 加密失败: \"\(testCase)\"")
}
print()
debugInfo("")
}
print(String(repeating: "=", count: 50))
print("🏁 OC版本DES加密测试完成")
debugInfo(String(repeating: "=", count: 50))
debugInfo("🏁 OC版本DES加密测试完成")
}
}

View File

@@ -54,23 +54,23 @@ final class DataMigrationManager {
///
/// - Returns:
func performMigration() -> MigrationResult {
print("🔄 开始检查数据迁移...")
debugInfo("🔄 开始检查数据迁移...")
//
if isMigrationCompleted() {
print("✅ 数据已经迁移过,跳过迁移")
debugInfo("✅ 数据已经迁移过,跳过迁移")
return .alreadyMigrated
}
//
let legacyData = collectLegacyData()
if legacyData.isEmpty {
print(" 没有发现需要迁移的数据")
debugInfo(" 没有发现需要迁移的数据")
markMigrationCompleted()
return .noDataToMigrate
}
print("📦 发现需要迁移的数据: \(legacyData.keys.joined(separator: ", "))")
debugInfo("📦 发现需要迁移的数据: \(legacyData.keys.joined(separator: ", "))")
do {
//
@@ -85,11 +85,11 @@ final class DataMigrationManager {
//
markMigrationCompleted()
print("✅ 数据迁移完成")
debugInfo("✅ 数据迁移完成")
return .completed
} catch {
print("❌ 数据迁移失败: \(error)")
debugError("❌ 数据迁移失败: \(error)")
return .failed(error)
}
}
@@ -157,9 +157,9 @@ final class DataMigrationManager {
do {
let accountModel = try JSONDecoder().decode(AccountModel.self, from: accountModelData)
try keychain.store(accountModel, forKey: "account_model")
print("✅ AccountModel 迁移成功")
debugInfo("✅ AccountModel 迁移成功")
} catch {
print("❌ AccountModel 迁移失败: \(error)")
debugError("❌ AccountModel 迁移失败: \(error)")
// AccountModel
try migrateAccountModelFromIndependentFields(legacyData)
}
@@ -173,9 +173,9 @@ final class DataMigrationManager {
do {
let userInfo = try JSONDecoder().decode(UserInfo.self, from: userInfoData)
try keychain.store(userInfo, forKey: "user_info")
print("✅ UserInfo 迁移成功")
debugInfo("✅ UserInfo 迁移成功")
} catch {
print("❌ UserInfo 迁移失败: \(error)")
debugError("❌ UserInfo 迁移失败: \(error)")
throw error
}
}
@@ -183,7 +183,7 @@ final class DataMigrationManager {
//
if let appLanguage = legacyData[LegacyStorageKeys.appLanguage] as? String {
try keychain.storeString(appLanguage, forKey: "AppLanguage")
print("✅ 语言设置迁移成功")
debugInfo("✅ 语言设置迁移成功")
}
}
@@ -191,7 +191,7 @@ final class DataMigrationManager {
private func migrateAccountModelFromIndependentFields(_ legacyData: [String: Any]) throws {
guard let userId = legacyData[LegacyStorageKeys.userId] as? String,
let accessToken = legacyData[LegacyStorageKeys.accessToken] as? String else {
print(" 没有足够的独立字段来重建 AccountModel")
debugInfo(" 没有足够的独立字段来重建 AccountModel")
return
}
@@ -208,7 +208,7 @@ final class DataMigrationManager {
)
try KeychainManager.shared.store(accountModel, forKey: "account_model")
print("✅ 从独立字段重建 AccountModel 成功")
debugInfo("✅ 从独立字段重建 AccountModel 成功")
}
///
@@ -240,7 +240,7 @@ final class DataMigrationManager {
}
}
print("✅ 迁移数据验证成功")
debugInfo("✅ 迁移数据验证成功")
}
///
@@ -249,11 +249,11 @@ final class DataMigrationManager {
for key in keys {
userDefaults.removeObject(forKey: key)
print("🗑️ 清理旧数据: \(key)")
debugInfo("🗑️ 清理旧数据: \(key)")
}
userDefaults.synchronize()
print("✅ 旧数据清理完成")
debugInfo("✅ 旧数据清理完成")
}
}
@@ -287,13 +287,13 @@ extension DataMigrationManager {
switch migrationResult {
case .completed:
print("🎉 应用启动时数据迁移完成")
debugInfo("🎉 应用启动时数据迁移完成")
case .alreadyMigrated:
break //
case .noDataToMigrate:
break //
case .failed(let error):
print("⚠️ 应用启动时数据迁移失败: \(error)")
debugError("⚠️ 应用启动时数据迁移失败: \(error)")
//
}
}
@@ -307,9 +307,9 @@ extension DataMigrationManager {
///
func debugPrintLegacyData() {
let legacyData = collectLegacyData()
print("🔍 旧版本数据:")
debugInfo("🔍 旧版本数据:")
for (key, value) in legacyData {
print(" - \(key): \(type(of: value))")
debugInfo(" - \(key): \(type(of: value))")
}
}
@@ -322,7 +322,7 @@ extension DataMigrationManager {
userDefaults.set("zh-Hans", forKey: LegacyStorageKeys.appLanguage)
userDefaults.synchronize()
print("🧪 已创建测试用的旧版本数据")
debugInfo("🧪 已创建测试用的旧版本数据")
}
///
@@ -331,7 +331,7 @@ extension DataMigrationManager {
do {
try KeychainManager.shared.clearAll()
} catch {
print("❌ 清除 Keychain 数据失败: \(error)")
debugError("❌ 清除 Keychain 数据失败: \(error)")
}
// UserDefaults
@@ -350,7 +350,7 @@ extension DataMigrationManager {
}
userDefaults.synchronize()
print("🧪 已清除所有迁移相关数据")
debugInfo("🧪 已清除所有迁移相关数据")
}
}
#endif

View File

@@ -108,7 +108,7 @@ final class KeychainManager {
throw KeychainError.keychainOperationFailed(status)
}
print("🔐 Keychain 存储成功: \(key)")
debugInfo("🔐 Keychain 存储成功: \(key)")
}
/// Keychain Codable
@@ -137,7 +137,7 @@ final class KeychainManager {
// 4.
do {
let object = try JSONDecoder().decode(type, from: data)
print("🔐 Keychain 读取成功: \(key)")
debugInfo("🔐 Keychain 读取成功: \(key)")
return object
} catch {
throw KeychainError.decodingFailed(error)
@@ -176,7 +176,7 @@ final class KeychainManager {
switch status {
case errSecSuccess:
print("🔐 Keychain 更新成功: \(key)")
debugInfo("🔐 Keychain 更新成功: \(key)")
case errSecItemNotFound:
//
@@ -196,7 +196,7 @@ final class KeychainManager {
switch status {
case errSecSuccess:
print("🔐 Keychain 删除成功: \(key)")
debugInfo("🔐 Keychain 删除成功: \(key)")
case errSecItemNotFound:
//
@@ -231,7 +231,7 @@ final class KeychainManager {
switch status {
case errSecSuccess, errSecItemNotFound:
print("🔐 Keychain 清除完成")
debugInfo("🔐 Keychain 清除完成")
default:
throw KeychainError.keychainOperationFailed(status)
@@ -353,9 +353,9 @@ extension KeychainManager {
///
func debugPrintAllKeys() {
let keys = debugListAllKeys()
print("🔐 Keychain 中存储的键:")
debugInfo("🔐 Keychain 中存储的键:")
for key in keys {
print(" - \(key)")
debugInfo(" - \(key)")
}
}
}