fix(mining-app): QR码解析加固 + debugPrint排查

- 清除不可见字符(BOM/零宽空格)
- 三级宽松解析:正则→Uri.parse→兜底phone=提取
- 添加 [QR_SCAN] 调试日志定位实际扫码值

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-31 05:54:34 -08:00
parent 8c31dee000
commit 03cc5bc324
2 changed files with 28 additions and 22 deletions

View File

@ -570,6 +570,7 @@ class _SendSharesPageState extends ConsumerState<SendSharesPage> {
if (result == null) return;
//
debugPrint('[QR_SCAN] scanner returned: "$result"');
final phone = parseTransferQrCode(result);
if (phone != null) {
setState(() {

View File

@ -250,37 +250,42 @@ class _QrScannerSheetState extends State<QrScannerSheet> {
/// null
String? parseTransferQrCode(String qrCode) {
try {
final trimmed = qrCode.trim();
// BOM
final trimmed = qrCode.trim().replaceAll(RegExp(r'[\u200B-\u200D\uFEFF\u00A0]'), '');
// 使 /
// durian://transfer/?phone=xxx durian://transfer?phone=xxx
final regex = RegExp(r'^durian://transfer/?[?]phone=(\d{11})$');
debugPrint('[QR_SCAN] raw length=${qrCode.length}, trimmed length=${trimmed.length}');
debugPrint('[QR_SCAN] raw codeUnits=${qrCode.codeUnits}');
debugPrint('[QR_SCAN] trimmed="$trimmed"');
// 1 - durian://transfer phone=11
final regex = RegExp(r'durian://transfer[/?].*?phone=(\d{11})');
final match = regex.firstMatch(trimmed);
if (match != null) {
debugPrint('[QR_SCAN] regex matched, phone=${match.group(1)}');
return match.group(1);
}
// 使 Uri.parse
final uri = Uri.parse(trimmed);
// scheme
if (uri.scheme != 'durian') return null;
// host ( authority )
if (uri.host != 'transfer') return null;
// phone
final phone = uri.queryParameters['phone'];
if (phone == null || phone.isEmpty) return null;
//
if (phone.length != 11 || !RegExp(r'^\d{11}$').hasMatch(phone)) {
return null;
// 2Uri.parse
final uri = Uri.tryParse(trimmed);
if (uri != null && uri.scheme == 'durian') {
final phone = uri.queryParameters['phone'];
if (phone != null && RegExp(r'^\d{11}$').hasMatch(phone)) {
debugPrint('[QR_SCAN] Uri.parse matched, phone=$phone');
return phone;
}
}
return phone;
// 3 - phone=11
final fallback = RegExp(r'phone=(\d{11})').firstMatch(trimmed);
if (fallback != null) {
debugPrint('[QR_SCAN] fallback matched, phone=${fallback.group(1)}');
return fallback.group(1);
}
debugPrint('[QR_SCAN] all parsing failed for: "$trimmed"');
return null;
} catch (e) {
debugPrint('[QR_SCAN] exception: $e');
return null;
}
}