sdk final

This commit is contained in:
robin
2026-03-05 16:53:59 +08:00
parent a10f3f3740
commit 491ade1bc3
44 changed files with 1595 additions and 960 deletions

View File

@@ -7,27 +7,30 @@ import 'package:flutter/services.dart';
class TrustAPPHttpdns {
static const MethodChannel _channel = MethodChannel('TrustAPP_httpdns');
/// New API only:
/// appId + primary/backup service host + optional sign secret.
/// Initialize the SDK.
/// [apiUrl] is the unified endpoint URL, e.g. "https://httpdns.example.com:8445".
/// [appId] and [secretKey] are required for authentication.
static Future<bool> init({
required String appId,
required String primaryServiceHost,
String? backupServiceHost,
int servicePort = 443,
String? apiUrl,
@Deprecated('Use apiUrl instead') String? primaryServiceHost,
@Deprecated('Use apiUrl instead') String? backupServiceHost,
@Deprecated('Use apiUrl instead') int servicePort = 443,
String? secretKey,
}) async {
final String normalizedAppId = appId.trim();
final String normalizedPrimary = primaryServiceHost.trim();
if (normalizedAppId.isEmpty || normalizedPrimary.isEmpty) {
if (normalizedAppId.isEmpty) {
return false;
}
final Map<String, dynamic> args = <String, dynamic>{
'appId': normalizedAppId,
'primaryServiceHost': normalizedPrimary,
if (apiUrl != null && apiUrl.trim().isNotEmpty) 'apiUrl': apiUrl.trim(),
if (primaryServiceHost != null && primaryServiceHost.trim().isNotEmpty)
'primaryServiceHost': primaryServiceHost.trim(),
if (backupServiceHost != null && backupServiceHost.trim().isNotEmpty)
'backupServiceHost': backupServiceHost.trim(),
if (servicePort > 0) 'servicePort': servicePort,
'servicePort': servicePort,
if (secretKey != null && secretKey.isNotEmpty) 'secretKey': secretKey,
};