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:
co-authored by
Claude Opus 4.7
parent
a2baf742b6
commit
1d7e258130
@@ -2,14 +2,18 @@
|
||||
// WechatShare.swift
|
||||
// ylgamehall
|
||||
//
|
||||
// 微信分享 SharePlatform 实现 stub。
|
||||
// 微信分享 SharePlatform 实现。
|
||||
//
|
||||
// Phase 4.E 阶段为 stub(等项目方提供微信 SDK + AppID + Universal Links);
|
||||
// 完整实现见 Design §8.2 ShareKit + §8.5 微信 / QQ 多发起方派发。
|
||||
// ⚠️ canImport(WechatOpenSDK) 守卫:SDK 未链接前 isInstalled = true / share = .success
|
||||
// 让 SharePanel 按钮可点;项目方在 Xcode Embed & Sign 后真实路径激活。
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
#if canImport(WechatOpenSDK)
|
||||
import WechatOpenSDK
|
||||
#endif
|
||||
|
||||
@MainActor
|
||||
public final class WechatShare: SharePlatform {
|
||||
|
||||
@@ -17,15 +21,44 @@ public final class WechatShare: SharePlatform {
|
||||
|
||||
public let name = "WeChat"
|
||||
|
||||
/// Stub: 微信 SDK 未接入前永远返回 true,让 SharePanel 按钮可点;
|
||||
/// 真实接入 SDK 后改为 `WXApi.isWXAppInstalled()`
|
||||
public var isInstalled: Bool { true }
|
||||
public var isInstalled: Bool {
|
||||
#if canImport(WechatOpenSDK)
|
||||
return WXApi.isWXAppInstalled()
|
||||
#else
|
||||
return true // 未链接 SDK 时让按钮可点,share 也只是 stub success
|
||||
#endif
|
||||
}
|
||||
|
||||
public init() {}
|
||||
|
||||
public func share(_ content: ShareContent, scene: ShareScene) async -> ShareResult {
|
||||
// Phase 4.E 阶段 stub:仅返回 success,不真实调起微信
|
||||
// 完整实现:WXApi.send + SendMessageToWXResp 回调 + 多发起方 state 配对
|
||||
#if canImport(WechatOpenSDK)
|
||||
guard WXApi.isWXAppInstalled() else {
|
||||
return .notInstalled(platform: name)
|
||||
}
|
||||
let wxScene: WeChatManager.ShareScene = (scene == .timeline) ? .timeline : .session
|
||||
// 当前仅链接分享(type == "1")走真实 SDK;截图 / 远端图分享待 Phase 4.F 接入
|
||||
// WXImageObject + WXMediaMessage.thumbData
|
||||
do {
|
||||
try await WeChatManager.shared.shareLink(
|
||||
.init(
|
||||
url: content.webpageUrl,
|
||||
title: content.title,
|
||||
desc: content.desc,
|
||||
thumbnailURL: nil // type=2/3 缩略图待 Phase 4.F
|
||||
),
|
||||
scene: wxScene
|
||||
)
|
||||
return .success
|
||||
} catch let WeChatError.shareFailed(errCode) {
|
||||
if errCode == -2 { return .cancelled }
|
||||
return .failed(reason: "WeChat errCode \(errCode)")
|
||||
} catch {
|
||||
return .failed(reason: "\(error)")
|
||||
}
|
||||
#else
|
||||
// SDK 未链接:维持 Phase 4.B 的 stub 行为(让 SharePanel 流程能跑通)
|
||||
return .success
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user