fix: 修改客服,增加sdk使用;增加邀请链接短链,升级flutter到3.35.0,Dart 3.9.0

This commit is contained in:
2026-01-24 23:14:18 -08:00
parent 57a47874be
commit e59cbf8b60
20 changed files with 457 additions and 187 deletions
@@ -1,29 +1,42 @@
import 'package:flutter_keychain/flutter_keychain.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
class IAPPendingOrderService {
static const _keyOrderNo = 'hi_iap_pending_order_no';
static const _keyJwsData = 'hi_iap_pending_jws_data'; // 新增 Key
// 创建统一存储实例
static final _storage = FlutterSecureStorage(
aOptions: const AndroidOptions(
encryptedSharedPreferences: true, // Android 加密存储
),
iOptions: const IOSOptions(
accessibility: KeychainAccessibility.first_unlock, // iOS Keychain
),
);
/// 存储待处理订单号
static Future<void> setPendingOrderNo(String orderNo) async {
await FlutterKeychain.put(key: _keyOrderNo, value: orderNo);
await _storage.write(key: _keyOrderNo, value: orderNo);
}
/// 获取待处理订单号
static Future<String?> getPendingOrderNo() async {
return await FlutterKeychain.get(key: _keyOrderNo);
return await _storage.read(key: _keyOrderNo);
}
/// 存储 JWS 凭证数据
static Future<void> setPendingJwsData(String jwsData) async {
await FlutterKeychain.put(key: _keyJwsData, value: jwsData);
await _storage.write(key: _keyJwsData, value: jwsData);
}
/// 获取存储的 JWS 凭证数据
static Future<String?> getPendingJwsData() async {
return await FlutterKeychain.get(key: _keyJwsData);
return await _storage.read(key: _keyJwsData);
}
/// 清除待处理订单和 JWS 数据
static Future<void> clearPendingOrderNo() async {
await FlutterKeychain.remove(key: _keyOrderNo);
await FlutterKeychain.remove(key: _keyJwsData);
await _storage.delete(key: _keyOrderNo);
await _storage.delete(key: _keyJwsData);
}
}
+17 -22
View File
@@ -2,7 +2,7 @@ import 'dart:io';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_udid/flutter_udid.dart';
import 'package:flutter_keychain/flutter_keychain.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import '../utils/kr_secure_storage.dart';
import '../utils/kr_log_util.dart';
import 'package:crypto/crypto.dart';
@@ -140,54 +140,49 @@ class KRDeviceInfoService {
/// iOS设备ID - 优先使用Keychain存储的UUID(卸载重装后不变)
/// iOS的identifierForVendor在所有同供应商应用卸载后会重置
/// 使用flutter_keychain存储到iOS Keychain,保证即使卸载重装,设备ID也不会变化
/// 使用flutter_secure_storage存储到iOS Keychain,保证即使卸载重装,设备ID也不会变化
Future<String> _getIOSDeviceId() async {
try {
const keychainKey = 'kr_ios_device_persistent_id';
// 1. 优先从iOS Keychain读取已存储的设备ID(卸载后依然存在)
String? storedId = await FlutterKeychain.get(key: keychainKey);
final storage = FlutterSecureStorage();
// 1. 优先从 Keychain 读取已存储的设备ID
String? storedId = await storage.read(key: keychainKey);
if (storedId != null && storedId.isNotEmpty) {
if (kDebugMode) {
print('📱 iOS: 从Keychain读取已存储的设备ID');
print('📱 iOS: 从 Keychain 读取已存储的设备ID');
}
KRLogUtil.kr_i('📱 iOS: 使用Keychain中的持久化设备ID', tag: 'KRDeviceInfoService');
KRLogUtil.kr_i('📱 iOS: 使用 Keychain 中的持久化设备ID', tag: 'KRDeviceInfoService');
return storedId;
}
// 2. 如果Keychain中没有,生成新的设备ID
// 2. 如果 Keychain 中没有,生成新的设备ID
final iosInfo = await _deviceInfo.iosInfo;
// 使用硬件级别的信息生成唯一标识(作为备用方案)
String udid = await FlutterUdid.consistentUdid;
// 构建多因子字符串(不使用会变化的identifierForVendor作为主要因子)
final factors = [
udid,
iosInfo.utsname.machine, // 硬件机器类型(如"iPhone14,3"
iosInfo.model, // 型号
iosInfo.systemName, // 系统名
// 移除: iosInfo.identifierForVendor - 因为它会在卸载后变化
// 移除: iosInfo.name - 用户可以修改设备名
// 移除: iosInfo.systemVersion - 系统升级会变化
iosInfo.utsname.machine,
iosInfo.model,
iosInfo.systemName,
];
final combined = factors
.where((f) => f.isNotEmpty)
.join('|');
final combined = factors.where((f) => f.isNotEmpty).join('|');
final bytes = utf8.encode(combined);
final hash = sha256.convert(bytes);
final newDeviceId = hash.toString();
// 3. 保存到iOS Keychain(即使应用卸载也会保留)
await FlutterKeychain.put(key: keychainKey, value: newDeviceId);
// 3. 保存到 Keychain
await storage.write(key: keychainKey, value: newDeviceId);
if (kDebugMode) {
print('📱 iOS: 生成新设备ID并保存到Keychain - 因子数: ${factors.where((f) => f.isNotEmpty).length}');
print('📱 iOS: 生成新设备ID并保存到 Keychain');
}
KRLogUtil.kr_i('📱 iOS: 生成并持久化新设备ID到Keychain', tag: 'KRDeviceInfoService');
KRLogUtil.kr_i('📱 iOS: 新设备ID已保存到 Keychain', tag: 'KRDeviceInfoService');
return newDeviceId;
} catch (e) {