Appearance
iOS对接
准备工作
下载示例工程、下载 SDK
修改密钥配置
AppDelegate.swift 文件修改
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// 配置密钥参数
let apiDomain = "https://api.kauth.cn" //接入点
let programId = "1959821336266936321" //程序 Id -> 登录后台 ->程序管理-> 程序 Id
let programSecret = "F77VzI7UWAElpWrz" //程序密钥 -> 登录后台 -> 程序管理 -> 程序密钥
let merchantPublicKey = "....+fmxrEri1qYicq8PO7mDIrwPR2I0USoKKOFMwIDAQAB" //商户密钥-> 系统设置 -> 密钥配置 -> RSA 公钥 -> PKCS#8格式
KauthCore.shared.configure(apiDomain: apiDomain, programId: programId, programSecret: programSecret, merchantPublicKey: merchantPublicKey)
window = UIWindow(frame: UIScreen.main.bounds)
let loginVC = LoginViewController()
let navController = UINavigationController(rootViewController: loginVC)
window?.rootViewController = navController
window?.makeKeyAndVisible()
return true
}```swift心跳保活
所有登录成功后 的页面 继承BaseViewController,BaseViewController 会自动开启心跳
其他接口
NetworkManager.swift 可以对照着在线 api 文档查看:https://kauth.cn/merchant/developer/apiDebug
目前时间有限,只测试完了:卡密登录、卡密解绑、卡密充值 、心跳、用户信息
其他的接口 还没来得及测完,ios 用户不急的话 可以再等等
swift
struct APIEndpoint {
let path: String
let method: HTTPMethod
let body: Encodable?
init(path: String, method: HTTPMethod = .post, body: Encodable? = nil) {
self.path = path
self.method = method
self.body = body
}
// MARK: - Factory Methods (用户认证模块)
static func getCaptcha(captchaKey: String?) -> APIEndpoint {
let body = CaptchaRequest(captchaKey: captchaKey)
return APIEndpoint(path: "/api/consumer/user/captcha", body: body)
}
/// 用户密码登录 (与Android KauthApiService.pwdLogin一致)
static func pwdLogin(loginName: String, password: String, captchaCode: String? = nil, captchaUuid: String? = nil, deviceId: String) -> APIEndpoint {
let body = PwdLoginRequest(loginName: loginName, password: password, captchaCode: captchaCode, captchaUuid: captchaUuid, deviceId: deviceId)
return APIEndpoint(path: "/api/consumer/user/pwdlogin", body: body)
}
/// 卡密登录 (与Android KauthApiService.kaLogin一致)
static func kaLogin(kaPwd: String, captchaCode: String? = nil, captchaUuid: String? = nil, deviceId: String, platformType: String = "iOS") -> APIEndpoint {
let body = KaLoginRequest(kaPwd: kaPwd, captchaCode: captchaCode, captchaUuid: captchaUuid, deviceId: deviceId, platformType: platformType)
return APIEndpoint(path: "/api/consumer/user/kaLogin", body: body)
}
static func loginOut() -> APIEndpoint {
return APIEndpoint(path: "/api/consumer/user/loginOut")
}
static func trialLogin(captchaKey: String? = nil, captchaCode: String? = nil) -> APIEndpoint {
let body = TrialLoginReq(captchaKey: captchaKey, captchaCode: captchaCode)
return APIEndpoint(path: "/api/consumer/user/trialLogin", body: body)
}
/// 用户注册 (与Android KauthApiService.register一致)
static func register(loginName: String, password: String, kaPassword: String, captchaCode: String? = nil, captchaUuid: String? = nil, nickName: String? = nil, deviceId: String) -> APIEndpoint {
let body = RegisterRequest(loginName: loginName, password: password, kaPassword: kaPassword, captchaCode: captchaCode, captchaUuid: captchaUuid, nickName: nickName, deviceId: deviceId)
return APIEndpoint(path: "/api/consumer/user/register", body: body)
}
/// 账号充值 (与Android KauthApiService.recharge一致)
static func recharge(loginName: String, kaPassword: String, deviceId: String, captchaCode: String? = nil, captchaUuid: String? = nil) -> APIEndpoint {
let body = RechargeRequest(loginName: loginName, kaPassword: kaPassword, deviceId: deviceId, captchaCode: captchaCode, captchaUuid: captchaUuid)
return APIEndpoint(path: "/api/consumer/user/recharge", body: body)
}
/// 以卡充卡 (与Android KauthApiService.rechargeKa一致)
static func rechargeKa(cardPwd: String, rechargeCardPwd: String) -> APIEndpoint {
let body = KaRechargeKaReq(cardPwd: cardPwd, rechargeCardPwd: rechargeCardPwd)
return APIEndpoint(path: "/api/consumer/user/rechargeKa", body: body)
}
static func changePassword(username: String, newPassword: String, captchaKey: String? = nil, captchaCode: String? = nil) -> APIEndpoint {
let body = ResetPwdRequest(username: username, newPassword: newPassword, captchaKey: captchaKey, captchaCode: captchaCode)
return APIEndpoint(path: "/api/consumer/user/changePassword", body: body)
}
static func unbindDevice(deviceId: String? = nil) -> APIEndpoint {
let body = UnbindDeviceRequest(deviceId: deviceId)
return APIEndpoint(path: "/api/consumer/user/unbindDevice", body: body)
}
/// 未登录状态下,卡密解绑设备 (与Android KauthApiService.unbindDeviceKaPwd一致)
static func unbindDeviceKaPwd(kaPwd: String, deviceId: String) -> APIEndpoint {
let body = UnbindDeviceKaPwdRequest(kaPwd: kaPwd, deviceId: deviceId)
return APIEndpoint(path: "/api/consumer/user/unbindDeviceKaPwd", body: body)
}
static func userInfo() -> APIEndpoint {
return APIEndpoint(path: "/api/consumer/user/userInfo")
}
static func pong() -> APIEndpoint {
return APIEndpoint(path: "/api/consumer/user/pong")
}
// MARK: - Factory Methods (配置管理模块)
static func updateUserConfig(configData: String) -> APIEndpoint {
let body = UpdateCustomConfigReq(configData: configData)
return APIEndpoint(path: "/api/consumer/custom/config/updateUserConfig", body: body)
}
static func getUserConfig() -> APIEndpoint {
return APIEndpoint(path: "/api/consumer/custom/config/getUserConfig")
}
static func updateKaConfig(configData: String) -> APIEndpoint {
let body = UpdateCustomConfigReq(configData: configData)
return APIEndpoint(path: "/api/consumer/custom/config/updateKaConfig", body: body)
}
static func getKaConfig() -> APIEndpoint {
return APIEndpoint(path: "/api/consumer/custom/config/getKaConfig")
}
// MARK: - Factory Methods (程序管理模块)
static func getProgramDetail() -> APIEndpoint {
return APIEndpoint(path: "/api/consumer/program/detail")
}
static func getServerTime() -> APIEndpoint {
return APIEndpoint(path: "/api/consumer/program/serverTime")
}
// MARK: - Factory Methods (脚本错误模块)
static func reportScriptError(errorType: String, errorMsg: String, stackTrace: String? = nil, scriptName: String? = nil, scriptVersion: String? = nil) -> APIEndpoint {
let body = ConsumerProgramScriptErrorReportReq(errorType: errorType, errorMsg: errorMsg, stackTrace: stackTrace, scriptName: scriptName, scriptVersion: scriptVersion)
return APIEndpoint(path: "/api/consumer/scriptError/report", body: body)
}
// MARK: - Factory Methods (设备管理模块)
static func cardUnBindDevice() -> APIEndpoint {
return APIEndpoint(path: "/api/consumer/device/cardUnBindDevice")
}
// MARK: - Factory Methods (远程控制模块)
static func getRemoteVar(varKey: String, defaultValue: String? = nil) -> APIEndpoint {
let body = GetRemoteVarReq(varKey: varKey, defaultValue: defaultValue)
return APIEndpoint(path: "/api/remote/getRemoteVar", body: body)
}
static func getRemoteData(varKey: String, defaultValue: String? = nil) -> APIEndpoint {
let body = GetRemoteVarReq(varKey: varKey, defaultValue: defaultValue)
return APIEndpoint(path: "/api/remote/getRemoteData", body: body)
}
static func addRemoteData(varKey: String, data: String, expireTime: Int64? = nil) -> APIEndpoint {
let body = RemoteDataAddReq(varKey: varKey, data: data, expireTime: expireTime)
return APIEndpoint(path: "/api/remote/addRemoteData", body: body)
}
static func updateRemoteData(id: Int64, data: String? = nil, expireTime: Int64? = nil) -> APIEndpoint {
let body = RemoteDataUpdateReq(id: id, data: data, expireTime: expireTime)
return APIEndpoint(path: "/api/remote/updateRemoteData", body: body)
}
static func deleteRemoteData(id: Int64) -> APIEndpoint {
let body = RemoteDataDeleteReq(id: id)
return APIEndpoint(path: "/api/remote/deleteRemoteData", body: body)
}
static func callFunction(functionName: String, params: String? = nil) -> APIEndpoint {
let body = CallFunctionReq(functionName: functionName, params: params)
return APIEndpoint(path: "/api/remote/callFunction", body: body)
}
static func getNewestScript(version: String? = nil) -> APIEndpoint {
let body = GetNewestScriptReq(version: version)
return APIEndpoint(path: "/api/remote/getNewestScript", body: body)
}
static func scriptDownloadV2(version: String? = nil, scriptMd5: String? = nil) -> APIEndpoint {
let body = ScriptDownloadReq(version: version, scriptMd5: scriptMd5)
return APIEndpoint(path: "/api/remote/scriptDownloadV2", body: body)
}
}