管理端全部功能跑通

This commit is contained in:
robin
2026-02-27 10:35:22 +08:00
parent 4d275c921d
commit 150799f41d
263 changed files with 22664 additions and 4053 deletions

View File

@@ -1,73 +1,58 @@
# Alicloud HTTPDNS iOS SDK
# HTTPDNS iOS SDK (SNI Hidden v1.0.0)
面向 iOS 的 HTTP/HTTPS DNS 解析 SDK提供鉴权与可选 AES 加密、IPv4/IPv6 双栈解析、缓存与调度、预解析等能力。最低支持 iOS 12.0。
## 1. Init
## 功能特性
- 鉴权请求与可选 AES 传输加密
- IPv4/IPv6 双栈解析,支持自动/同时解析
- 内存 + 持久化缓存与 TTL 控制,可选择复用过期 IP
- 预解析、区域路由、网络切换自动刷新
- 可定制日志回调与会话追踪 `sessionId`
## 安装CocoaPods
`Podfile` 中添加:
```ruby
platform :ios, '12.0'
target 'YourApp' do
pod 'AlicloudHTTPDNS', '~> 3.4.1'
end
```
执行 `pod install` 安装依赖。
## 快速开始
ObjectiveC
```objc
#import <AlicloudHttpDNS/AlicloudHttpDNS.h>
#import <AlicloudHTTPDNS/AlicloudHTTPDNS.h>
// 使用鉴权初始化(单例);密钥请勿硬编码到仓库
HttpDnsService *service = [[HttpDnsService alloc] initWithAccountID:1000000
secretKey:@"<YOUR_SECRET>"];
[service setPersistentCacheIPEnabled:YES];
[service setPreResolveHosts:@[@"www.aliyun.com"] byIPType:HttpdnsQueryIPTypeAuto];
// 同步解析(会根据网络自动选择 v4/v6
HttpdnsResult *r = [service resolveHostSync:@"www.aliyun.com" byIpType:HttpdnsQueryIPTypeAuto];
NSLog(@"IPv4: %@", r.ips);
HttpdnsEdgeService *service = [[HttpdnsEdgeService alloc]
initWithAppId:@"app1f1ndpo9"
primaryServiceHost:@"httpdns-a.example.com"
backupServiceHost:@"httpdns-b.example.com"
servicePort:443
signSecret:@"your-sign-secret"]; // optional if sign is enabled
```
Swift
```swift
import AlicloudHttpDNS
## 2. Resolve
_ = HttpDnsService(accountID: 1000000, secretKey: "<YOUR_SECRET>")
let svc = HttpDnsService.sharedInstance()
let res = svc?.resolveHostSync("www.aliyun.com", byIpType: .auto)
print(res?.ips ?? [])
```objc
[service resolveHost:@"api.business.com" queryType:@"A" completion:^(HttpdnsEdgeResolveResult * _Nullable result, NSError * _Nullable error) {
if (error != nil) {
return;
}
NSLog(@"requestId=%@ ipv4=%@ ipv6=%@ ttl=%ld", result.requestId, result.ipv4s, result.ipv6s, (long)result.ttl);
}];
```
提示
- 启动时通过 `setPreResolveHosts(_:byIPType:)` 预热热点域名。
- 如需在刷新期间容忍 TTL 过期,可开启 `setReuseExpiredIPEnabled:YES`
- 使用 `getSessionId()` 并与选用 IP 一同记录,便于排障。
## 3. Official Request Adapter (IP + Host)
## 源码构建
执行 `./build_xc_framework.sh` 生成 XCFramework。脚本会从 `gitlab.alibaba-inc.com` 克隆内部构建工具;外部环境建议优先使用 CocoaPods 引入。
```objc
NSURL *url = [NSURL URLWithString:@"https://api.business.com/v1/ping"];
[service requestURL:url method:@"GET" headers:@{@"Accept": @"application/json"} body:nil completion:^(NSData * _Nullable data, NSHTTPURLResponse * _Nullable response, NSError * _Nullable error) {
if (error != nil) {
return;
}
NSLog(@"status=%ld", (long)response.statusCode);
}];
```
## 测试
- 在 Xcode 使用 Scheme `AlicloudHttpDNSTests` 运行。
- 含 OCMock 的用例批量执行可能出现内存问题,请单个运行。
- 非 Mock 用例使用预置参数AccountID `1000000`,测试域名 `*.onlyforhttpdnstest.run.place`(每年需续期)。
Behavior is fixed:
- Resolve by `/resolve`.
- Connect to resolved IP over HTTPS.
- Keep `Host` header as business domain.
- No fallback to domain direct request.
## 依赖与链接
- iOS 12.0+;需链接 `CoreTelephony``SystemConfiguration`
- 额外库:`sqlite3.0``resolv``OTHER_LDFLAGS` 包含 `-ObjC -lz`
## 4. Public Errors
## 安全说明
- 切勿提交真实的 AccountID/SecretKey請通过本地安全配置或 CI 注入。
- 若担心设备时间偏差影响鉴权,可用 `setInternalAuthTimeBaseBySpecifyingCurrentTime:` 校正。
- `NO_IP_AVAILABLE`
- `TLS_EMPTY_SNI_FAILED`
- `HOST_ROUTE_REJECTED`
- `RESOLVE_SIGN_INVALID`
## Demo 与贡献
- 示例应用:`AlicloudHttpDNSTestDemo/`
- 贡献与提交流程请参见 `AGENTS.md`(提交信息与 PR 规范)。
## 5. Removed Public Params
Do not expose legacy public parameters:
- `accountId`
- `serviceDomain`
- `endpoint`
- `aesSecretKey`