800 字
4 分钟
综设需求——建立用户“指纹”库?
用户指纹库是什么?
我们在金融学互联网+综合设计课程中,需要在安卓app中收集、在后端建立一个用户指纹库。用户指纹库是通过收集用户设备和行为特征,形成能够唯一或准唯一标识用户的特征集合。它不收集个人隐私信息,而是通过技术特征组合来识别设备。
主要特征维度:
设备特征:
- 屏幕分辨率、像素密度
- 设备型号、操作系统版本
- 浏览器/WebView版本信息
- 字体列表
- 硬件配置(CPU核心数、内存大小)
- 时区、语言设置
行为特征:
- 应用使用时间段
- 常用功能模块
- 操作习惯(点击频率、滑动速度)
- 网络环境变化模式
在UniApp中的实现方案(拟)
基础设备信息收集:
// 获取系统信息uni.getSystemInfo({ success: (res) => { const deviceFingerprint = { platform: res.platform, model: res.model, system: res.system, version: res.version, screenWidth: res.screenWidth, screenHeight: res.screenHeight, pixelRatio: res.pixelRatio, language: res.language, brand: res.brand }; this.saveFingerprint(deviceFingerprint); }});
// 获取更多设备特征async function getAdvancedFingerprint() { const fingerprint = {};
// 网络信息 const network = await uni.getNetworkType(); fingerprint.networkType = network.networkType;
// 电池信息 const battery = await uni.getBatteryInfo(); fingerprint.batteryLevel = battery.level;
// 存储信息 const storage = await uni.getStorageInfo(); fingerprint.storageSize = storage.currentSize;
return fingerprint;}行为特征收集:
// 用户行为追踪class UserBehaviorTracker { constructor() { this.behaviorData = { loginTimes: [], featureUsage: {}, operationHabits: {} }; }
// 记录功能使用 trackFeatureUsage(featureName) { const now = new Date(); if (!this.behaviorData.featureUsage[featureName]) { this.behaviorData.featureUsage[featureName] = []; } this.behaviorData.featureUsage[featureName].push(now); }
// 记录操作习惯 trackOperation(operationType, duration) { this.behaviorData.operationHabits[operationType] = this.behaviorData.operationHabits[operationType] || []; this.behaviorData.operationHabits[operationType].push(duration); }}注意事项?
合规性要求:
// 必须添加用户授权async function requestFingerprintPermission() { try { // 显示隐私政策说明 const result = await uni.showModal({ title: '数据收集说明', content: '为提供更好的服务,我们将收集设备特征信息用于安全风控,这些信息不会识别个人身份。', confirmText: '同意', cancelText: '拒绝' });
if (result.confirm) { // 用户同意后开始收集 this.startFingerprintCollection(); // 保存用户授权记录 uni.setStorageSync('fingerprint_agreed', true); } } catch (error) { console.error('获取授权失败:', error); }}数据安全:
// 数据加密传输function encryptFingerprintData(data) { // 使用加密算法处理敏感数据 const encrypted = { timestamp: Date.now(), data: JSON.stringify(data), signature: this.generateSignature(data) }; return encrypted;}
// 安全存储function saveFingerprintLocally(data) { uni.setStorage({ key: 'device_fingerprint', data: this.encryptFingerprintData(data), success: () => { console.log('指纹数据保存成功'); } });}技术实现要点
跨平台兼容性:
// 平台差异处理function getPlatformSpecificInfo() { // #ifdef APP-PLUS return this.getAppDeviceInfo(); // #endif
// #ifdef H5 return this.getH5DeviceInfo(); // #endif
// #ifdef MP-WEIXIN return this.getMiniProgramInfo(); // #endif}数据上传策略:
// 分批上传,减少网络压力class FingerprintUploader { constructor() { this.batchSize = 10; this.uploadQueue = []; }
addToUpload(data) { this.uploadQueue.push(data); if (this.uploadQueue.length >= this.batchSize) { this.uploadBatch(); } }
async uploadBatch() { const batch = this.uploadQueue.splice(0, this.batchSize); try { await uni.request({ url: 'https://your-api.com/fingerprint', method: 'POST', data: { fingerprints: batch, deviceId: this.getDeviceId() } }); } catch (error) { // 上传失败,重新加入队列 this.uploadQueue.unshift(...batch); } }}搭建须知
- 明确告知:在应用启动时明确告知用户数据收集目的
- 可选退出:提供用户拒绝参与的选择
- 数据最小化:只收集必要的特征数据
- 定期清理:设置数据过期时间,定期清理历史数据
- 安全传输:使用HTTPS加密传输所有数据
综设需求——建立用户“指纹”库?
https://blog.tonks.top/posts/fingerprint/ 部分信息可能已经过时