|
|
@ -15,6 +15,7 @@ struct StsConfig { |
|
|
var deviceSecret: String |
|
|
var deviceSecret: String |
|
|
let agentId: String |
|
|
let agentId: String |
|
|
var cmei: String = "" |
|
|
var cmei: String = "" |
|
|
|
|
|
var mac: String = "" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// MARK: - StsAgent |
|
|
// MARK: - StsAgent |
|
|
@ -87,9 +88,9 @@ class StsAgent: NSObject { |
|
|
super.init() |
|
|
super.init() |
|
|
let sessionConfig = URLSessionConfiguration.default |
|
|
let sessionConfig = URLSessionConfiguration.default |
|
|
urlSession = URLSession(configuration: sessionConfig, delegate: nil, delegateQueue: OperationQueue()) |
|
|
urlSession = URLSession(configuration: sessionConfig, delegate: nil, delegateQueue: OperationQueue()) |
|
|
os_log("StsAgent 初始化: productId=%{public}@ deviceNo=%{public}@ deviceId=%{public}@ cmei=%{public}@ hasSecret=%{public}@", |
|
|
os_log("StsAgent 初始化: productId=%{public}@ deviceNo=%{public}@ deviceId=%{public}@ cmei=%{public}@ mac=%{public}@ hasSecret=%{public}@", |
|
|
log: logger, type: .info, |
|
|
log: logger, type: .info, |
|
|
config.productId, config.deviceNo, config.deviceId, config.cmei, |
|
|
config.productId, config.deviceNo, config.deviceId, config.cmei, config.mac, |
|
|
config.deviceSecret.isEmpty ? "false" : "true") |
|
|
config.deviceSecret.isEmpty ? "false" : "true") |
|
|
// 与 Android 行为对齐:凭证已有时立即尝试上报一次心跳(受 1 小时冷却保护) |
|
|
// 与 Android 行为对齐:凭证已有时立即尝试上报一次心跳(受 1 小时冷却保护) |
|
|
if !config.deviceSecret.isEmpty && !config.deviceId.isEmpty { |
|
|
if !config.deviceSecret.isEmpty && !config.deviceId.isEmpty { |
|
|
@ -105,6 +106,13 @@ class StsAgent: NSObject { |
|
|
os_log("updateCmei: cmei 已更新为 %{public}@", log: logger, type: .info, cmei) |
|
|
os_log("updateCmei: cmei 已更新为 %{public}@", log: logger, type: .info, cmei) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// 动态更新 MAC(首次初始化时可能尚未获取到) |
|
|
|
|
|
func updateMac(_ mac: String) { |
|
|
|
|
|
guard !mac.isEmpty, mac != config.mac else { return } |
|
|
|
|
|
config.mac = mac |
|
|
|
|
|
os_log("updateMac: mac 已更新为 %{public}@", log: logger, type: .info, mac) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// MARK: - 公共接口 |
|
|
// MARK: - 公共接口 |
|
|
|
|
|
|
|
|
func startCall() { |
|
|
func startCall() { |
|
|
@ -233,8 +241,8 @@ class StsAgent: NSObject { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
defaults.set(now, forKey: HEARTBEAT_PREFS_KEY) |
|
|
defaults.set(now, forKey: HEARTBEAT_PREFS_KEY) |
|
|
os_log("reportHeartbeat: 开始上报 deviceId=%{public}@ deviceNo=%{public}@ cmei=%{public}@", |
|
|
os_log("reportHeartbeat: 开始上报 deviceId=%{public}@ deviceNo=%{public}@ cmei=%{public}@ mac=%{public}@", |
|
|
log: logger, type: .info, config.deviceId, config.deviceNo, config.cmei) |
|
|
log: logger, type: .info, config.deviceId, config.deviceNo, config.cmei, config.mac) |
|
|
|
|
|
|
|
|
let urlStr = "https://ivs.chinamobiledevice.com:11443/v2/customer/device/report" |
|
|
let urlStr = "https://ivs.chinamobiledevice.com:11443/v2/customer/device/report" |
|
|
guard let url = URL(string: urlStr) else { return } |
|
|
guard let url = URL(string: urlStr) else { return } |
|
|
@ -243,17 +251,16 @@ class StsAgent: NSObject { |
|
|
req.setValue("application/json", forHTTPHeaderField: "Content-Type") |
|
|
req.setValue("application/json", forHTTPHeaderField: "Content-Type") |
|
|
req.timeoutInterval = 10 |
|
|
req.timeoutInterval = 10 |
|
|
|
|
|
|
|
|
let systemVersion = UIDevice.current.systemVersion |
|
|
|
|
|
let params: [String: Any] = [ |
|
|
let params: [String: Any] = [ |
|
|
"innerIp": ["127.0.0.1"], |
|
|
"innerIp": ["127.0.0.1"], |
|
|
"netSpeed": "0Mbps", |
|
|
"netSpeed": "0Mbps", |
|
|
"netType": "WiFi", |
|
|
"netType": "WiFi", |
|
|
"platform": "iOS\(systemVersion)", |
|
|
"platform": "", |
|
|
"sdkVersion": "ai_http_1.0", |
|
|
"sdkVersion": "ai_http_1.0", |
|
|
"firmwareVersion": "1.0.0", |
|
|
"firmwareVersion": "1.0.0", |
|
|
"imei": "", |
|
|
"imei": "", |
|
|
"cmei": config.cmei, |
|
|
"cmei": config.cmei, |
|
|
"mac": "", |
|
|
"mac": config.mac, |
|
|
] |
|
|
] |
|
|
let bodyDict: [String: Any] = [ |
|
|
let bodyDict: [String: Any] = [ |
|
|
"deviceId": config.deviceId, |
|
|
"deviceId": config.deviceId, |
|
|
|