添加网络层并接入 v9 登录流程及单元测试

This commit is contained in:
2026-07-06 15:33:34 +08:00
parent 31ffec0f2b
commit d424928243
21 changed files with 2387 additions and 18 deletions
+47
View File
@@ -0,0 +1,47 @@
//
// AuthAPI.swift
// suixinkan
//
import Foundation
@MainActor
/// 登录认证 API,封装 config、v9 登录和账号选择相关接口。
final class AuthAPI {
private let client: APIClient
/// 初始化登录 API,并注入共享网络客户端。
init(client: APIClient) {
self.client = client
}
/// 获取 App 配置,控制注册/验证码登录入口显隐。
func getAppConfig() async throws -> AppConfigResponse {
try await client.send(
APIRequest(method: .get, path: "/api/app/config")
)
}
/// 使用手机号和密码发起 v9 登录,返回临时 token 及可选账号列表。
func login(username: String, password: String) async throws -> V9AuthResponse {
try await client.send(
APIRequest(
method: .post,
path: "/api/app/v9/login",
body: LoginRequest(username: username, password: password)
)
)
}
/// 选择具体景区或门店账号,换取正式登录 token。
func setUser(_ request: SetUserRequest, tokenOverride: String? = nil) async throws -> V9AuthResponse {
try await client.send(
APIRequest(
method: .post,
path: "/api/app/v9/set-user",
body: request
),
tokenOverride: tokenOverride
)
}
}