Phase 4.E + Phase 5 + Phase 3.C 七牛上传:代码侧 SDK 接入(SPM 优先 / Vendor 兜底)

选型(CLAUDE.md ADR-006「SPM 优先 + Vendor xcframework 兜底」):
- 微信 → SPM(Tencent 官方 https://github.com/Tencent/WechatOpenSDK-XCFramework);
  项目方下载的 WechatOpenSDK-NoPay.xcframework 已撤出 Vendor,docs/res 内副本作离线备份
- 高德 → Vendor 手动(官方未提供 SPM;Vendor/AMap/{AMapFoundationKit,AMapLocationKit}.framework
  随仓库分发,fat .framework 同时含 x86_64 + arm64,Do Not Embed)
- 七牛 → SPM(https://github.com/qiniu/objc-sdk v8.9.x)

代码侧(全部 #if canImport 守卫,Xcode 加 SDK 前编译为 no-op):
- Source/SDK/WeChat/WeChatSDK.swift:WXApi.registerApp + handleOpenURL(沿用 msext AppID
  wx586a9b321e56efb7,universalLink 空字符串走非 ULAPI 路径)
- Source/SDK/WeChat/WeChatManager.swift:WXApiDelegate + state UUID 配对的 authorize +
  FIFO 串行 share async/await wrapper
- Source/Login/WeChatAuth.swift:客户端直拼 sns/oauth2/access_token + sns/userinfo →
  7 字段(Province 大写 P / city 经 danbian 去单引号),沿用 msext 同款路径
- Source/SDK/AMap/AMapWrapper.swift:iOS 14+ 隐私合规 3 步 + apiKey 注入
- Source/Location/LocationService.swift:actor + AMapLocationManager 异步包装 + 9 字段
- Source/Network/QiniuConfig.swift:4 项常量沿用 msext(AccessKey/SecretKey/Bucket/Domain)
- Source/Network/QiniuTokenSigner.swift:纯 Swift CryptoKit HMAC-SHA1 + Base64URL 自签
  token(与 msext QiniuManager.m:200-230 等价,不依赖 Qiniu SDK 工作)
- Source/Network/QiniuUploader.swift:actor 包 QNUploadManager async/await

Handler 升级:
- AccreditLoginHandler:拉起授权 → 反向 callback sharelogin 7 字段
- WechatShare:真实链接分享(type=2/3 截图待 Phase 4.F)
- StartLocationHandler:真实定位 → 9 字段(latitude/longitude string, province 小写 p)

生命周期:
- AppDelegate.didFinishLaunchingWithOptions:WeChatSDK.register + AMapWrapper.bootstrap
- SceneDelegate.openURLContexts:WeChatSDK.handleOpenURL 接入回调
- BackGameDataHandler:子游戏 backgameData pop 时 WXApi.delegate=nil + LocationService.stop()

Info.plist:CFBundleURLTypes 加 wx586a9b321e56efb7;LSApplicationQueriesSchemes 追加
weixin/weixinULAPI/weixinURLParamsAPI;NSLocationWhenInUseUsageDescription +
NSMicrophoneUsageDescription(gamehallname 中文文案)。

.gitignore:排除 docs/res/{AMap_iOS_Loc_ALL,objc-sdk-8.9.2}/(235MB 项目方下载副本,
已走 SPM/Vendor 接入不需要副本)。

文档:docs/SDK-Integration-Guide.md 重写 §A 用户手动 Xcode UI 三步(SPM × 2 +
Add Files × 2);Vendor/{AMap,WechatSDK}/README.md 记录各自接入路径选型。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
joywayer
2026-06-22 22:22:23 +08:00
co-authored by Claude Opus 4.7
parent a2baf742b6
commit 1d7e258130
47 changed files with 3226 additions and 273 deletions
@@ -2,18 +2,17 @@
// AccreditLoginHandler.swift
// ylgamehall
//
// H5 Native handler stubaccreditlogin
// H5 Native handleraccreditlogin
// docs/H5-Native-Contract.md §3.1 1 + §3.2 10sharelogin
//
// Phase 4.A stub cb Phase 4.B SDK + AppID +
// Universal Links + /wechat/login fallback
// Phase 4.E
// 1. WeChatAuth.authorize() + oauth2 + userinfo
// (msext NewRootVC.m:2415-2428 沿 AppID/AppSecret/scope)
// 2. bridge.call("sharelogin", data: 7 ) callback
// 1:1 `Province` P / `city` danbian
//
// Phase 4.B
// 1. WeChatManager.shared.authorize() WXAuthCodestate UUID
// 2. WeChatAuth.exchangeForUser(code:) /wechat/login
// sns/oauth2/access_token + sns/userinfo
// 3. bridge.call("sharelogin", data: 7 ) callback
// 1:1 Province Pcity danbian:
// canImport(WechatOpenSDK) SDK stub Phase 4.A
// callback sharelogin Xcode Embed & Sign
//
import Foundation
@@ -21,11 +20,32 @@ import Foundation
public enum AccreditLoginHandler {
public static func register(on bridge: any BridgeProtocol) {
// 1accreditlogin
// cb: "Response from accreditlogin"
// sharelogin callbackPhase 4.B
bridge.register("accreditlogin") { _, callback in
callback?(.string("Response from accreditlogin"))
#if canImport(WechatOpenSDK)
// SDK 7 callback sharelogin
Task { @MainActor in
do {
let user = try await WeChatAuth.authorize()
bridge.call("sharelogin", data: .object([
// 1:1 contract §3.2 [10] / msext NewRootVC.m:2428
"openid": .string(user.openid),
"headimgurl": .string(user.headimgurl),
"nickname": .string(user.nickname),
"sex": .number(Double(user.sex)),
"city": .string(user.city),
"Province": .string(user.Province), // P
"unionid": .string(user.unionid)
]), callback: nil)
} catch WeChatAuthError.userCancelled {
// msext alert sharelogin
} catch {
// msext H5
// Phase 9 Sentry breadcrumb
}
}
#endif
}
}
}
@@ -17,29 +17,24 @@
// msext
//
//
// SDK msext backgameData / cleanUpAction
// stub SDK
// MainActor.run
// SDK SDK
//
// - Phase 4.E SDK`WXApi.delegate = nil`
// msext gameController.m:699 pop SubGameVC
//
// - Phase 5 `LocationService.shared.stop()` + delegate nil
// msext gameController.m:2473-2478 cleanUpAction +
//
//
// - Phase 3.B/C/D / `Recorder.shared.cancel()` +
// `Uploader.shared.cancelInFlight()`
// msext ChatVoiceRecorderVC VC
// cancel pop
//
// - Phase 8 Agora`agoraKit.leaveChannel(...)`
// VideoRoomHandlers stub
// Phase 4.E `WXApi.delegate = nil`canImport Xcode Embed
// Phase 5 `LocationService.shared.stop()`canImport
// Xcode Embed AMapLocationKit
// Phase 3.B/C/D / `AudioRecorder.shared.cancel()` opencore-amr
// `QiniuUploader.cancelInFlight()` Task.cancel
// Phase 8 Agora`agoraKit.leaveChannel(...)`
// VideoRoomHandlers stub
//
//
import Foundation
#if canImport(WechatOpenSDK)
import WechatOpenSDK
#endif
public enum BackGameDataHandler {
public static func register(on bridge: any BridgeProtocol) {
@@ -52,7 +47,25 @@ public enum BackGameDataHandler {
// - .string
// - JSON H5
let payload = serialize(data)
// push SDK pop delegate /
// msext gameController.m:691-709 + cleanUpAction
AudioPlayer.shared.stopAllBackground()
#if canImport(WechatOpenSDK)
// msext gameController.m:699 WXApi delegate VC
WXApi.delegate = nil
#endif
#if canImport(AMapLocationKit)
// msext gameController.m:2473-2478 cleanUpAction
LocationService.shared.stop()
#endif
// Phase 3.C / Phase 3.B QiniuUploader.cancelInFlight
// Task.cancel AudioRecorder opencore-amr
// AudioRecorder.shared.cancel() // Phase 3.C
AppCoordinator.shared.popSubGame(returningData: payload)
}
callback?(.string("backgameData"))
@@ -2,15 +2,18 @@
// StartLocationHandler.swift
// ylgamehall
//
// H5 Native handlerstartlocation Phase 5 stub
// H5 Native handlerstartlocation Phase 5 SDK
// docs/H5-Native-Contract.md §3.1 20 + §3.2 6
//
// Stub
// - startlocation cb "startlocation" undefinedH5
// - **** getlocationinfo callback SDK
// - H5 getlocationinfo Phase 5 AMapLocationKit
//
// 1. LocationService.shared.requestOnce()actor AMapLocationManager
// 2. bridge.call("getlocationinfo", 9 ) callback
// - latitude / longitude **string**`String(format: "%f")`
// - province p sharelogin.Province
// 3. getlocationinfo({errorCode:12, errorMsg:""})
//
// CLAUDE.md A H5 使
// canImport(AMapLocationKit) SDK LocationService sdkNotLinked
// stub Phase 2 callback getlocationinfo
//
import Foundation
@@ -19,9 +22,41 @@ public enum StartLocationHandler {
public static func register(on bridge: any BridgeProtocol) {
bridge.register("startlocation") { _, callback in
// Phase 2 stub callback
// Phase 5 LocationKit + AMapLocationKit.xcframework
// msext cb
callback?(.string("startlocation"))
#if canImport(AMapLocationKit)
// SDK callback 9
// data == 1 Phase 5.4
Task { @MainActor in
do {
let payload = try await LocationService.shared.requestOnce()
bridge.call("getlocationinfo", data: .object([
"address": .string(payload.address),
"city": .string(payload.city),
"cityCode": .string(payload.cityCode),
"country": .string(payload.country),
"district": .string(payload.district),
"latitude": .string(payload.latitude), // string
"longitude": .string(payload.longitude), // string
"province": .string(payload.province), // p
"street": .string(payload.street)
]), callback: nil)
} catch LocationError.authorizationDenied {
// msext gameController.m:2507
bridge.call("getlocationinfo", data: .object([
"errorCode": .number(12),
"errorMsg": .string("缺少定位权限")
]), callback: nil)
} catch {
// 12msext
bridge.call("getlocationinfo", data: .object([
"errorCode": .number(12),
"errorMsg": .string("缺少定位权限")
]), callback: nil)
}
}
#endif
}
}
}