ios_receiptHelper.dart
858 Bytes
import 'dart:convert';
import 'package:flutter/services.dart';
class ReceiptHelper {
static const _channel = MethodChannel('cn.banxe.appframe/receipt');
/// 获取 Base64 编码的收据数据,直接可用于 /verifyReceipt
static Future<String> getBase64Receipt() async {
try {
final String? base64 = await _channel.invokeMethod('getReceipt');
if (base64 == null || base64.isEmpty) {
throw Exception('收据为空,请先刷新收据');
}
return base64;
} on MissingPluginException {
throw Exception('原生插件未注册,请检查 iOS 代码');
}
}
/// 强制刷新收据(沙盒环境常需要)
static Future<void> refreshReceipt() async {
try {
await _channel.invokeMethod('refreshReceipt');
} catch (e) {
throw Exception('刷新收据失败: $e');
}
}
}