2026-04-21 22:07:29 +08:00
|
|
|
package com.xuqm.sdk.push
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import com.xuqm.sdk.XuqmSDK
|
2026-04-27 19:30:06 +08:00
|
|
|
import com.xuqm.sdk.core.ServiceEndpointRegistry
|
2026-04-21 22:07:29 +08:00
|
|
|
import com.xuqm.sdk.network.ApiClient
|
|
|
|
|
import com.xuqm.sdk.push.api.PushApi
|
|
|
|
|
import com.xuqm.sdk.utils.DeviceUtils
|
|
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
|
|
|
|
|
object PushSDK {
|
|
|
|
|
|
2026-04-27 19:30:06 +08:00
|
|
|
private val api: PushApi get() = ApiClient.create(PushApi::class.java, ServiceEndpointRegistry.pushBaseUrl)
|
2026-04-21 22:07:29 +08:00
|
|
|
private val scope = CoroutineScope(Dispatchers.IO)
|
|
|
|
|
|
2026-04-27 17:18:55 +08:00
|
|
|
fun registerDevice(context: Context, userId: String) {
|
2026-04-21 22:07:29 +08:00
|
|
|
XuqmSDK.requireInit()
|
|
|
|
|
val vendor = DeviceUtils.getVendor()
|
2026-04-27 17:18:55 +08:00
|
|
|
val deviceId = DeviceUtils.getDeviceId(context)
|
2026-04-21 22:07:29 +08:00
|
|
|
scope.launch {
|
|
|
|
|
runCatching {
|
2026-04-27 17:18:55 +08:00
|
|
|
api.registerDevice(
|
2026-04-27 19:00:54 +08:00
|
|
|
appId = XuqmSDK.appId,
|
|
|
|
|
userId = userId,
|
|
|
|
|
vendor = vendor,
|
|
|
|
|
token = deviceId,
|
2026-04-27 17:18:55 +08:00
|
|
|
)
|
2026-04-21 22:07:29 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-27 17:18:55 +08:00
|
|
|
fun unregisterDevice(userId: String) {
|
2026-04-21 22:07:29 +08:00
|
|
|
XuqmSDK.requireInit()
|
|
|
|
|
scope.launch {
|
2026-04-27 17:18:55 +08:00
|
|
|
runCatching { api.unregisterDevice(XuqmSDK.appId, userId) }
|
2026-04-21 22:07:29 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|