jsdw_ios/QuickLocation/API/UserAPI.swift

79 lines
1.9 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.

//
// UserAPI.swift
// QuickLocation
//
// Created by 八条 on 2026/5/28.
//
import Moya
import SwiftyUserDefaults
internal import Alamofire
/// 用户相关API
enum UserAPI {
/// 登录
/// - Parameters:
/// - type: weixin、phone、apple、onekey、device、alipay
/// - bind:1绑定 2解绑 为空是登录
case login(type: String,
bind: String,
data: [String: Any])
/// 用户信息
case userInfo
/// 用户IM Token
case imToken
/// 退出登录
case logout
}
extension UserAPI: MultiTargetProtocol {
var path: String {
switch self {
case .login:
return "api/user/login"
case .userInfo:
return "api/user"
case .imToken:
return "mapi/openim/user/token/get"
case .logout:
return "api/user/logout"
}
}
var method: Moya.Method {
switch self {
case .userInfo:
return .get
default:
return .post
}
}
var task: Moya.Task {
switch self {
case let .login(type, bind, data):
var params = Parameters()
params["type"] = type
params["bind"] = bind
params["data"] = data
return .requestParameters(parameters: params, encoding: JSONEncoding())
case .userInfo:
return .requestParameters(parameters: Parameters(), encoding: URLEncoding())
case .imToken:
var params = Parameters()
params["platform_id"] = 1
params["force"] = true
return .requestParameters(parameters: params, encoding: JSONEncoding())
case .logout:
return .requestParameters(parameters: Parameters(), encoding: JSONEncoding())
}
}
}