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

@@ -22,6 +22,7 @@ class TrustAPPHttpDnsPlugin : FlutterPlugin, MethodCallHandler {
private var appId: String? = null
private var secretKey: String? = null
private var apiUrl: String? = null
private var primaryServiceHost: String? = null
private var backupServiceHost: String? = null
private var servicePort: Int? = null
@@ -63,9 +64,11 @@ class TrustAPPHttpDnsPlugin : FlutterPlugin, MethodCallHandler {
return
}
val apiUrlArg = (args["apiUrl"] as? String)?.trim()
val primaryHostArg = (args["primaryServiceHost"] as? String)?.trim()
if (primaryHostArg.isNullOrBlank()) {
Log.i("TrustAPPHttpDns", "initialize missing primaryServiceHost")
if (apiUrlArg.isNullOrBlank() && primaryHostArg.isNullOrBlank()) {
Log.i("TrustAPPHttpDns", "initialize missing both apiUrl and primaryServiceHost")
result.success(false)
return
}
@@ -81,13 +84,14 @@ class TrustAPPHttpDnsPlugin : FlutterPlugin, MethodCallHandler {
appId = parsedAppId
secretKey = secret
apiUrl = apiUrlArg
primaryServiceHost = primaryHostArg
backupServiceHost = backup?.trim()?.takeIf { it.isNotEmpty() }
servicePort = if (port != null && port > 0) port else null
Log.i(
"TrustAPPHttpDns",
"initialize appId=$appId, primaryServiceHost=$primaryServiceHost, backupServiceHost=$backupServiceHost, servicePort=$servicePort"
"initialize appId=$appId, apiUrl=$apiUrl, primaryServiceHost=$primaryServiceHost, backupServiceHost=$backupServiceHost, servicePort=$servicePort"
)
result.success(true)
}
@@ -190,25 +194,39 @@ class TrustAPPHttpDnsPlugin : FlutterPlugin, MethodCallHandler {
}
try {
builder.javaClass.getMethod("setPrimaryServiceHost", String::class.java)
.invoke(builder, primaryServiceHost)
hostConfigApplied = true
} catch (t: Throwable) {
Log.w("TrustAPPHttpDns", "setPrimaryServiceHost failed: ${t.message}")
}
try {
backupServiceHost?.let {
builder.javaClass.getMethod("setBackupServiceHost", String::class.java)
.invoke(builder, it)
if (!apiUrl.isNullOrBlank()) {
try {
builder.javaClass.getMethod("setServiceUrl", String::class.java)
.invoke(builder, apiUrl)
hostConfigApplied = true
} catch (t: Throwable) {
Log.w("TrustAPPHttpDns", "setServiceUrl failed: ${t.message}")
}
} else {
try {
builder.javaClass.getMethod("setPrimaryServiceHost", String::class.java)
.invoke(builder, primaryServiceHost)
hostConfigApplied = true
} catch (t: Throwable) {
Log.w("TrustAPPHttpDns", "setPrimaryServiceHost failed: ${t.message}")
}
try {
backupServiceHost?.let {
builder.javaClass.getMethod("setBackupServiceHost", String::class.java)
.invoke(builder, it)
}
} catch (_: Throwable) {
}
try {
servicePort?.let {
builder.javaClass.getMethod("setServicePort", Int::class.javaPrimitiveType)
.invoke(builder, it)
}
} catch (_: Throwable) {
}
}
} catch (_: Throwable) {
}
try {
servicePort?.let {
builder.javaClass.getMethod("setServicePort", Int::class.javaPrimitiveType)
.invoke(builder, it)
}
} catch (_: Throwable) {
} catch (e: Exception) {
Log.w("TrustAPPHttpDns", "Host configuration failed: ${e.message}")
}
try {

View File

@@ -0,0 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"new_httpdns","path":"/Users/robin/product/waf-platform/HttpDNSSDK/sdk/flutter/new_httpdns/","native_build":true,"dependencies":[],"dev_dependency":false}],"android":[{"name":"new_httpdns","path":"/Users/robin/product/waf-platform/HttpDNSSDK/sdk/flutter/new_httpdns/","native_build":true,"dependencies":[],"dev_dependency":false}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"new_httpdns","dependencies":[]}],"date_created":"2026-03-05 15:58:08.461101","version":"3.41.4","swift_package_manager_enabled":{"ios":false,"macos":false}}

View File

@@ -20,7 +20,5 @@
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>12.0</string>
</dict>
</plist>

View File

@@ -0,0 +1,18 @@
#
# This podspec is NOT to be published. It is only used as a local source!
# This is a generated file; do not edit or check into version control.
#
Pod::Spec.new do |s|
s.name = 'Flutter'
s.version = '1.0.0'
s.summary = 'A UI toolkit for beautiful and fast apps.'
s.homepage = 'https://flutter.dev'
s.license = { :type => 'BSD' }
s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' }
s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s }
s.ios.deployment_target = '13.0'
# Framework linking is handled by Flutter tooling, not CocoaPods.
# Add a placeholder to satisfy `s.dependency 'Flutter'` plugin podspecs.
s.vendored_frameworks = 'path/to/nothing'
end

View File

@@ -0,0 +1,15 @@
// This is a generated file; do not edit or check into version control.
FLUTTER_ROOT=/usr/local/share/flutter
FLUTTER_APPLICATION_PATH=/Users/robin/product/waf-platform/HttpDNSSDK/sdk/flutter/new_httpdns/example
COCOAPODS_PARALLEL_CODE_SIGN=true
FLUTTER_TARGET=/Users/robin/product/waf-platform/HttpDNSSDK/sdk/flutter/new_httpdns/example/lib/main.dart
FLUTTER_BUILD_DIR=build
FLUTTER_BUILD_NAME=1.0.0
FLUTTER_BUILD_NUMBER=1
EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386
EXCLUDED_ARCHS[sdk=iphoneos*]=armv7
DART_DEFINES=RkxVVFRFUl9WRVJTSU9OPTMuNDEuNA==,RkxVVFRFUl9DSEFOTkVMPXN0YWJsZQ==,RkxVVFRFUl9HSVRfVVJMPWh0dHBzOi8vZ2l0aHViLmNvbS9mbHV0dGVyL2ZsdXR0ZXIuZ2l0,RkxVVFRFUl9GUkFNRVdPUktfUkVWSVNJT049ZmYzN2JlZjYwMw==,RkxVVFRFUl9FTkdJTkVfUkVWSVNJT049ZTRiOGRjYTNmMQ==,RkxVVFRFUl9EQVJUX1ZFUlNJT049My4xMS4x
DART_OBFUSCATION=false
TRACK_WIDGET_CREATION=true
TREE_SHAKE_ICONS=false
PACKAGE_CONFIG=/Users/robin/product/waf-platform/HttpDNSSDK/sdk/flutter/new_httpdns/example/.dart_tool/package_config.json

View File

@@ -0,0 +1,32 @@
#
# Generated file, do not edit.
#
import lldb
def handle_new_rx_page(frame: lldb.SBFrame, bp_loc, extra_args, intern_dict):
"""Intercept NOTIFY_DEBUGGER_ABOUT_RX_PAGES and touch the pages."""
base = frame.register["x0"].GetValueAsAddress()
page_len = frame.register["x1"].GetValueAsUnsigned()
# Note: NOTIFY_DEBUGGER_ABOUT_RX_PAGES will check contents of the
# first page to see if handled it correctly. This makes diagnosing
# misconfiguration (e.g. missing breakpoint) easier.
data = bytearray(page_len)
data[0:8] = b'IHELPED!'
error = lldb.SBError()
frame.GetThread().GetProcess().WriteMemory(base, data, error)
if not error.Success():
print(f'Failed to write into {base}[+{page_len}]', error)
return
def __lldb_init_module(debugger: lldb.SBDebugger, _):
target = debugger.GetDummyTarget()
# Caveat: must use BreakpointCreateByRegEx here and not
# BreakpointCreateByName. For some reasons callback function does not
# get carried over from dummy target for the later.
bp = target.BreakpointCreateByRegex("^NOTIFY_DEBUGGER_ABOUT_RX_PAGES$")
bp.SetScriptCallbackFunction('{}.handle_new_rx_page'.format(__name__))
bp.SetAutoContinue(True)
print("-- LLDB integration loaded --")

View File

@@ -0,0 +1,5 @@
#
# Generated file, do not edit.
#
command script import --relative-to-command-file flutter_lldb_helper.py

View File

@@ -0,0 +1,14 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/usr/local/share/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/robin/product/waf-platform/HttpDNSSDK/sdk/flutter/new_httpdns/example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=/Users/robin/product/waf-platform/HttpDNSSDK/sdk/flutter/new_httpdns/example/lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_DEFINES=RkxVVFRFUl9WRVJTSU9OPTMuNDEuNA==,RkxVVFRFUl9DSEFOTkVMPXN0YWJsZQ==,RkxVVFRFUl9HSVRfVVJMPWh0dHBzOi8vZ2l0aHViLmNvbS9mbHV0dGVyL2ZsdXR0ZXIuZ2l0,RkxVVFRFUl9GUkFNRVdPUktfUkVWSVNJT049ZmYzN2JlZjYwMw==,RkxVVFRFUl9FTkdJTkVfUkVWSVNJT049ZTRiOGRjYTNmMQ==,RkxVVFRFUl9EQVJUX1ZFUlNJT049My4xMS4x"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=/Users/robin/product/waf-platform/HttpDNSSDK/sdk/flutter/new_httpdns/example/.dart_tool/package_config.json"

View File

@@ -2,7 +2,7 @@
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/aliyun/aliyun-specs.git'
# Uncomment this line to define a global platform for your project
# platform :ios, '12.0'
# platform :ios, '13.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

View File

@@ -436,7 +436,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
@@ -570,7 +570,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
@@ -621,7 +621,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;

View File

@@ -0,0 +1,19 @@
//
// Generated file. Do not edit.
//
// clang-format off
#ifndef GeneratedPluginRegistrant_h
#define GeneratedPluginRegistrant_h
#import <Flutter/Flutter.h>
NS_ASSUME_NONNULL_BEGIN
@interface GeneratedPluginRegistrant : NSObject
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry;
@end
NS_ASSUME_NONNULL_END
#endif /* GeneratedPluginRegistrant_h */

View File

@@ -0,0 +1,21 @@
//
// Generated file. Do not edit.
//
// clang-format off
#import "GeneratedPluginRegistrant.h"
#if __has_include(<new_httpdns/NewHttpDnsPlugin.h>)
#import <new_httpdns/NewHttpDnsPlugin.h>
#else
@import new_httpdns;
#endif
@implementation GeneratedPluginRegistrant
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
[NewHttpDnsPlugin registerWithRegistrar:[registry registrarForPlugin:@"NewHttpDnsPlugin"]];
}
@end

View File

@@ -4,7 +4,7 @@ import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
import 'net/httpdns_http_client_adapter.dart';
import 'package:TrustAPP_httpdns/TrustAPP_httpdns.dart';
import 'package:new_httpdns/new_httpdns.dart';
void main() {
runApp(const MyApp());
@@ -13,7 +13,6 @@ void main() {
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
@@ -63,18 +62,20 @@ class _MyHomePageState extends State<MyHomePage> {
if (_httpdnsReady || _httpdnsIniting) return;
_httpdnsIniting = true;
try {
// 使用官方测试参数
await TrustAPPHttpdns.init(
appId: 'app1f1ndpo9', // 请替换为您的应用 AppId
primaryServiceHost: 'httpdns-a.example.com', // 请替换为主服务域<E58AA1><E59F9F>? backupServiceHost: 'httpdns-b.example.com', // 可选备服务域<E58AA1><E59F9F>? servicePort: 443,
secretKey: 'your_sign_secret_here', // 可选仅验签开启时需<E697B6><E99C80>? );
appId: 'app1flndpo9',
apiUrl: 'https://httpdns.deepwaf.xyz:8445',
secretKey: 'ss_67fb8471a45b',
);
await TrustAPPHttpdns.setHttpsRequestEnabled(true);
await TrustAPPHttpdns.setLogEnabled(true);
await TrustAPPHttpdns.setPersistentCacheIPEnabled(true);
await TrustAPPHttpdns.setReuseExpiredIPEnabled(true);
await TrustAPPHttpdns.build();
// 先build再执行解析相关动<EFBFBD><EFBFBD>?
final preResolveHosts = 'www.TrustAPP.com';
// 先 build 再执行解析相关动
final preResolveHosts = 'demo.cloudxdr.com';
await TrustAPPHttpdns.setPreResolveHosts([preResolveHosts], ipType: 'both');
debugPrint('[httpdns] pre-resolve scheduled for host=$preResolveHosts');
_httpdnsReady = true;
@@ -88,13 +89,13 @@ class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
// 设置默认的API URL用于演示
_urlController.text = 'https://www.TrustAPP.com';
// 设置默认的 API URL 用于演示
_urlController.text = 'https://demo.cloudxdr.com';
// 仅首次进入页面时初始<EFBFBD><EFBFBD>?HTTPDNS
// 仅首次进入页面时初始HTTPDNS
_initHttpDnsOnce();
// 先初始化HTTPDNS再初始化Dio
// 先初始化 HTTPDNS 再初始化 Dio
_dio = Dio();
_dio.httpClientAdapter = buildHttpdnsHttpClientAdapter();
_dio.options.headers['Connection'] = 'keep-alive';
@@ -124,7 +125,7 @@ class _MyHomePageState extends State<MyHomePage> {
_responseText = 'Sending request...';
});
final uri = Uri.parse(_urlController.text);
final uri = Uri.parse(_urlController.text.trim());
try {
final String libraryName = _selectedLibrary.displayName;
@@ -215,7 +216,6 @@ class _MyHomePageState extends State<MyHomePage> {
}
}
// 使用 HTTPDNS 解析当前 URL <20><>?host 并显示结<E7A4BA><E7BB93>?
Future<void> _testHttpDnsResolve() async {
final text = _urlController.text.trim();
if (text.isEmpty) {
@@ -241,7 +241,6 @@ class _MyHomePageState extends State<MyHomePage> {
});
try {
// 确保只初始化一<E58C96><E4B880>?
await _initHttpDnsOnce();
final res = await TrustAPPHttpdns.resolveHostSyncNonBlocking(
uri.host,
@@ -278,12 +277,11 @@ class _MyHomePageState extends State<MyHomePage> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// URL输入<E8BE93><E585A5>?
TextField(
controller: _urlController,
decoration: const InputDecoration(
labelText: 'Enter URL',
hintText: 'https://www.TrustAPP.com',
hintText: 'https://demo.cloudxdr.com',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.link),
),
@@ -346,7 +344,6 @@ class _MyHomePageState extends State<MyHomePage> {
),
const SizedBox(height: 16),
// HTTPDNS 解析按钮
ElevatedButton.icon(
onPressed: _isLoading ? null : _testHttpDnsResolve,
icon: const Icon(Icons.dns),
@@ -357,10 +354,8 @@ class _MyHomePageState extends State<MyHomePage> {
),
const SizedBox(height: 16),
// 保留空白分隔
const SizedBox(height: 16),
// 响应文本显示区域
Expanded(
child: Container(
width: double.infinity,

View File

@@ -0,0 +1,9 @@
import 'dart:io';
import 'package:dio/io.dart';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'package:http/io_client.dart';
import 'package:new_httpdns/new_httpdns.dart';
/* *

View File

@@ -4,7 +4,7 @@ import 'package:dio/io.dart';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'package:http/io_client.dart';
import 'package:TrustAPP_httpdns/TrustAPP_httpdns.dart';
import 'package:new_httpdns/new_httpdns.dart';
/* *
* 构建<E69E84><E5BBBA>?HTTPDNS 能力<E883BD><E58A9B>?IOHttpClientAdapter

View File

@@ -1,13 +1,6 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
new_httpdns:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "1.0.0"
async:
dependency: transitive
description:
@@ -28,10 +21,10 @@ packages:
dependency: transitive
description:
name: characters
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
url: "https://pub.dev"
source: hosted
version: "1.4.0"
version: "1.4.1"
clock:
dependency: transitive
description:
@@ -126,26 +119,26 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0"
sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de"
url: "https://pub.dev"
source: hosted
version: "10.0.9"
version: "11.0.2"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573
sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1"
url: "https://pub.dev"
source: hosted
version: "3.0.9"
version: "3.0.10"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
version: "3.0.2"
lints:
dependency: transitive
description:
@@ -158,26 +151,26 @@ packages:
dependency: transitive
description:
name: matcher
sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2
sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861
url: "https://pub.dev"
source: hosted
version: "0.12.17"
version: "0.12.19"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
url: "https://pub.dev"
source: hosted
version: "0.11.1"
version: "0.13.0"
meta:
dependency: transitive
description:
name: meta
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
url: "https://pub.dev"
source: hosted
version: "1.16.0"
version: "1.17.0"
mime:
dependency: transitive
description:
@@ -186,6 +179,13 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.0"
new_httpdns:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "1.0.0"
path:
dependency: transitive
description:
@@ -251,10 +251,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd
sha256: "8161c84903fd860b26bfdefb7963b3f0b68fee7adea0f59ef805ecca346f0c7a"
url: "https://pub.dev"
source: hosted
version: "0.7.4"
version: "0.7.10"
typed_data:
dependency: transitive
description:
@@ -267,10 +267,10 @@ packages:
dependency: transitive
description:
name: vector_math
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b
url: "https://pub.dev"
source: hosted
version: "2.1.4"
version: "2.2.0"
vm_service:
dependency: transitive
description:
@@ -288,5 +288,5 @@ packages:
source: hosted
version: "1.1.1"
sdks:
dart: ">=3.7.0-0 <4.0.0"
dart: ">=3.9.0-0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"

View File

@@ -6,9 +6,11 @@ import CommonCrypto
public class NewHttpDnsPlugin: NSObject, FlutterPlugin {
private var appId: String?
private var secretKey: String?
private var apiUrl: String?
private var primaryServiceHost: String?
private var backupServiceHost: String?
private var servicePort: Int = 443
private var serviceScheme: String = "https"
private var desiredLogEnabled: Bool?
private var desiredHttpsEnabled: Bool?
@@ -20,7 +22,7 @@ public class NewHttpDnsPlugin: NSObject, FlutterPlugin {
}()
public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "new_httpdns", binaryMessenger: registrar.messenger())
let channel = FlutterMethodChannel(name: "TrustAPP_httpdns", binaryMessenger: registrar.messenger())
let instance = NewHttpDnsPlugin()
registrar.addMethodCallDelegate(instance, channel: channel)
}
@@ -29,26 +31,46 @@ public class NewHttpDnsPlugin: NSObject, FlutterPlugin {
switch call.method {
case "initialize":
let options = call.arguments as? [String: Any] ?? [:]
guard let rawAppId = options["appId"] as? String,
let rawPrimaryHost = options["primaryServiceHost"] as? String else {
guard let rawAppId = options["appId"] as? String else {
result(false)
return
}
let normalizedAppId = rawAppId.trimmingCharacters(in: .whitespacesAndNewlines)
let normalizedPrimaryHost = rawPrimaryHost.trimmingCharacters(in: .whitespacesAndNewlines)
if normalizedAppId.isEmpty || normalizedPrimaryHost.isEmpty {
if normalizedAppId.isEmpty {
result(false)
return
}
appId = normalizedAppId
primaryServiceHost = normalizedPrimaryHost
apiUrl = (options["apiUrl"] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines)
primaryServiceHost = (options["primaryServiceHost"] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines)
backupServiceHost = (options["backupServiceHost"] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines)
secretKey = (options["secretKey"] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines)
if let p = options["servicePort"] as? Int, p > 0 {
servicePort = p
}
if let urlStr = apiUrl, !urlStr.isEmpty {
var normalized = urlStr
if !urlStr.lowercased().hasPrefix("http://") && !urlStr.lowercased().hasPrefix("https://") {
normalized = "https://" + urlStr
}
if let url = URL(string: normalized) {
primaryServiceHost = url.host
if let p = url.port {
servicePort = p
}
serviceScheme = url.scheme ?? "https"
}
} else if let host = primaryServiceHost {
// Keep as is, using defaults
} else {
result(false)
return
}
result(true)
case "setLogEnabled":
@@ -180,7 +202,7 @@ public class NewHttpDnsPlugin: NSObject, FlutterPlugin {
let serviceHost = hosts[index]
var components = URLComponents()
components.scheme = "https"
components.scheme = serviceScheme
components.host = serviceHost
components.port = servicePort
components.path = "/resolve"

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,
};