95 行
2.3 KiB
Markdown
95 行
2.3 KiB
Markdown
# Xuqm License SDK
|
|
|
|
Android SDK for device license registration and verification.
|
|
|
|
## Features
|
|
|
|
- **Stable Device ID**: Uses `ANDROID_ID` (stable per app signing key + device + user), with UUID fallback
|
|
- **Token Caching**: Caches valid status for configurable window (default 10 min) to reduce network calls
|
|
- **Auto Recovery**: Automatically re-registers when token is invalid or revoked
|
|
- **Offline Support**: Returns cached OK status when network is unavailable
|
|
- **Encrypted License File**: Reads `assets/xuqm/license.xuqm`; the file does not expose appKey or server URL as readable text
|
|
- **AppKey Change Detection**: Automatically clears old data when decrypted appKey changes
|
|
|
|
## Integration
|
|
|
|
```kotlin
|
|
dependencies {
|
|
implementation("com.xuqm:sdk-license:0.1.0-SNAPSHOT")
|
|
}
|
|
```
|
|
|
|
## Usage
|
|
|
|
### License File
|
|
|
|
Download the encrypted License file from the tenant platform and place it at:
|
|
|
|
```text
|
|
app/src/main/assets/xuqm/license.xuqm
|
|
```
|
|
|
|
The SDK also accepts a tenant-platform downloaded file such as
|
|
`app/src/main/assets/xuqm/MyApp.xuqmlicense`.
|
|
|
|
No explicit initialization code is required.
|
|
|
|
### Check License
|
|
|
|
```kotlin
|
|
LicenseSDK.checkLicense { isValid ->
|
|
if (isValid) {
|
|
// allow app usage
|
|
} else {
|
|
// block app usage or show warning
|
|
}
|
|
}
|
|
```
|
|
|
|
Optional user metadata can be uploaded during the same check. All fields are optional.
|
|
|
|
```kotlin
|
|
LicenseSDK.checkLicense(
|
|
userInfo = LicenseUserInfo(
|
|
userId = "u_10001",
|
|
name = "张三",
|
|
email = "zhangsan@example.com",
|
|
phone = "13800000000",
|
|
),
|
|
) { isValid ->
|
|
// allow or block app usage
|
|
}
|
|
```
|
|
|
|
### Get Status (no network)
|
|
|
|
```kotlin
|
|
val status = LicenseSDK.getStatus() // OK, DENIED, or UNKNOWN
|
|
```
|
|
|
|
### Re-register (force)
|
|
|
|
```kotlin
|
|
lifecycleScope.launch {
|
|
val result = LicenseSDK.reRegister()
|
|
}
|
|
```
|
|
|
|
### Get Device ID
|
|
|
|
```kotlin
|
|
val deviceId = LicenseSDK.getDeviceId()
|
|
```
|
|
|
|
## Configuration
|
|
|
|
| Parameter | Default | Description |
|
|
|-----------|---------|-------------|
|
|
| `appKey` | from encrypted file | Company appKey from tenant platform |
|
|
| `deviceName` | `${MANUFACTURER} ${MODEL}` | Device display name |
|
|
| `baseUrl` | `https://auth.dev.xuqinmin.com/` | License server base URL |
|
|
|
|
## Data Storage
|
|
|
|
All data (device ID, token, status) is stored in `EncryptedSharedPreferences` with AES-256 encryption.
|