微信 SDK 降级 2.0.5 → 1.8.2(与 daoqi msext 同款,避开 UL 强制)
H5 调 accreditlogin 后 sendAuthReq success=false,根因:微信 OpenSDK
2.0.x 强制 Universal Link,传空串被 SDK 拒绝;daoqi msext 用 1.8.x 不强制
UL,多年稳定上线。沿用 1.8.2 避免无谓的 UL 运维负担(HTTPS 域名 + AASA +
微信开放平台审核 30min-1d)。
文件改动:
- 新增 Vendor/WechatSDK/v1.8.2/{WXApi,WXApiObject,WechatAuthSDK}.h +
libWeChatSDK.a(16MB,fat: i386+armv7+armv7s+x86_64+arm64,从 daoqi
msext/Class/SDKExport/ 直接拷贝)
- 删除 Vendor/WechatSDK/WechatOpenSDK-NoPay.xcframework(2.0.5)
- 新增 ylgamehall/ylgamehall-Bridging-Header.h(1.x .a 无 Swift module,
必须通过 Bridging Header 导入 WXApi.h / WXApiObject.h)
代码侧(5 个 Swift 文件):
- WeChatSDK.swift:register() 改为 1.x 单参数 WXApi.registerApp(appID),
去掉 universalLink 参数;handleOpenURL 不变(1.x/2.x 同款)
- WeChatManager.swift:去掉 #if canImport(WechatOpenSDK) 守卫(Bridging
Header 直接导入,符号编译期必在);authorize sendAuthReq 改 1.x BOOL
返回(无 completion);shareLink/shareImage 改 WXApi.sendReq(req)
(1.x BOOL 返回,无 completion);getVersion → getApiVersion
- AccreditLoginHandler / WechatShare:同样去掉 canImport 守卫和 stub 分支
- BackGameDataHandler:更新注释说明 1.x WXApi delegate 由 sendAuthReq
逐次传入,WeChatManager singleton 持有不需要清理(1.x 早期 setDelegate:
API 已废弃)
文档:
- Vendor/WechatSDK/README.md 重写,说明 1.8.2 决策原因 + 文件结构 +
Xcode 接入 5 步 + M Mac simulator 已知限制
- docs/SDK-Integration-Guide.md §A.1 同步重写
⚠️ **本 commit 后 BuildProject 会失败**,需要用户在 Xcode UI 完成 5 步:
1. 删 Frameworks 里旧 WechatOpenSDK-NoPay.xcframework 引用
2. Add Vendor/WechatSDK/v1.8.2/libWeChatSDK.a(Do Not Embed)
3. Add 4 个系统库:libz.tbd / libsqlite3.tbd / Security.framework /
CFNetwork.framework(Do Not Embed)
4. Build Settings → Header Search Paths += $(PROJECT_DIR)/Vendor/WechatSDK/v1.8.2
5. Build Settings → Objective-C Bridging Header = ylgamehall/ylgamehall-Bridging-Header.h
详细操作步骤见 Vendor/WechatSDK/README.md「Xcode 接入步骤」。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
a060f29070
commit
05f1396645
@@ -24,11 +24,8 @@ public enum AccreditLoginHandler {
|
||||
print("[Bridge] accreditlogin H5 调用命中 ✅")
|
||||
callback?(.string("Response from accreditlogin"))
|
||||
|
||||
#if canImport(WechatOpenSDK)
|
||||
print("[Bridge] accreditlogin → canImport(WechatOpenSDK)=true,启动 Task")
|
||||
// SDK 已链接:拉起微信授权 → 拿 7 字段 → 反向 callback sharelogin
|
||||
// 拉起微信授权 → 拿 7 字段 → 反向 callback sharelogin
|
||||
Task { @MainActor in
|
||||
print("[Bridge] accreditlogin Task @MainActor 开始执行 WeChatAuth.authorize()")
|
||||
do {
|
||||
let user = try await WeChatAuth.authorize()
|
||||
print("[Bridge] accreditlogin 拿到 user,发 sharelogin 反向 callback")
|
||||
@@ -48,12 +45,8 @@ public enum AccreditLoginHandler {
|
||||
} catch {
|
||||
print("[Bridge] accreditlogin 失败:\(error)")
|
||||
// 其它失败也吞下(msext 同款乐观策略:不反向通知 H5)
|
||||
// 后续 Phase 9 监控接入后此处可发 Sentry breadcrumb
|
||||
}
|
||||
}
|
||||
#else
|
||||
print("[Bridge] accreditlogin → ⚠️ canImport(WechatOpenSDK)=false,SDK 未链接,仅 stub")
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,10 +49,11 @@ public enum BackGameDataHandler {
|
||||
// 后台任务残留),与 msext gameController.m:691-709 + cleanUpAction 等价。
|
||||
AudioPlayer.shared.stopAllBackground()
|
||||
|
||||
// 微信 SDK 新版(2.x)delegate 由 handleOpenURL: / sendAuthReq:...:delegate:
|
||||
// 逐次调用时传入并被 SDK 弱引用,无 static delegate 可清。WeChatManager
|
||||
// 微信 SDK 1.8.2 delegate 通过 sendAuthReq:viewController:delegate: 或
|
||||
// handleOpenURL:delegate: 逐次调用时传入并被 SDK 弱引用。WeChatManager
|
||||
// 作为 shared singleton 长生命周期持有,子游戏 pop 不会让它析构,无悬挂回调风险。
|
||||
// 旧 msext gameController.m:699 的 [WXApi setDelegate:nil] 是 1.x SDK API,新版已删除。
|
||||
// msext gameController.m:699 的 [WXApi setDelegate:nil] 是 1.x 早期 API,
|
||||
// 1.8.x 之后已废弃,不需要清理。
|
||||
|
||||
#if canImport(AMapLocationKit)
|
||||
// msext gameController.m:2473-2478 cleanUpAction 等价
|
||||
|
||||
@@ -11,9 +11,7 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
#if canImport(WechatOpenSDK)
|
||||
import WechatOpenSDK
|
||||
#endif
|
||||
// 微信 SDK 1.8.2(与 daoqi msext 同款)通过 Bridging Header 导入,无需 import 语句
|
||||
|
||||
@MainActor
|
||||
public final class WeChatManager: NSObject {
|
||||
@@ -41,10 +39,9 @@ public final class WeChatManager: NSObject {
|
||||
/// openURL 路径解耦,授权回包独立由 SDK 直接派给 delegate)
|
||||
/// 旧版 1.x 的 `WXApi.send(req)` 已 deprecated,不传 vc/delegate 会导致 H5 调了无反应。
|
||||
public func authorize() async throws -> WXAuthCodePayload {
|
||||
#if canImport(WechatOpenSDK)
|
||||
print("[WeChat] authorize() 开始")
|
||||
print("[WeChat] - WXApi.isWXAppInstalled = \(WXApi.isWXAppInstalled())")
|
||||
print("[WeChat] - WXApi.getVersion = \(WXApi.getVersion() ?? "nil")")
|
||||
print("[WeChat] - WXApi.getApiVersion = \(WXApi.getApiVersion() ?? "nil")")
|
||||
let state = UUID().uuidString
|
||||
return try await withCheckedThrowingContinuation { cont in
|
||||
authPending[state] = cont
|
||||
@@ -59,23 +56,16 @@ public final class WeChatManager: NSObject {
|
||||
return
|
||||
}
|
||||
print("[WeChat] 调 sendAuthReq vc=\(type(of: vc)) scope=\(Self.authScope) state=\(state)")
|
||||
WXApi.sendAuthReq(req, viewController: vc, delegate: self) { [weak self] success in
|
||||
print("[WeChat] sendAuthReq completion success=\(success)")
|
||||
// success = SDK 是否成功拉起微信 app;失败立刻 fail(如微信未安装、
|
||||
// URL Scheme 未配置等)。成功后真实回包由 onResp 路径处理。
|
||||
guard !success else { return }
|
||||
Task { @MainActor in
|
||||
guard let self else { return }
|
||||
if let pending = self.authPending.removeValue(forKey: state) {
|
||||
pending.resume(throwing: WeChatError.authFailed(-3))
|
||||
}
|
||||
// 1.x 的 sendAuthReq 返回 BOOL(同步知道是否成功拉起),无 completion
|
||||
let success = WXApi.sendAuthReq(req, viewController: vc, delegate: self)
|
||||
print("[WeChat] sendAuthReq 返回 success=\(success)")
|
||||
if !success {
|
||||
if let pending = authPending.removeValue(forKey: state) {
|
||||
pending.resume(throwing: WeChatError.authFailed(-3))
|
||||
}
|
||||
}
|
||||
// success=true 时等 WXApiDelegate.onResp 触发(SceneDelegate openURL 链路)
|
||||
}
|
||||
#else
|
||||
print("[WeChat] ⚠️ canImport(WechatOpenSDK)=false")
|
||||
throw WeChatError.sdkNotLinked
|
||||
#endif
|
||||
}
|
||||
|
||||
/// 取当前最顶层 ViewController(含 presented / nav.visible),供微信 SDK 作为
|
||||
@@ -133,7 +123,6 @@ public final class WeChatManager: NSObject {
|
||||
|
||||
/// 链接分享(FIFO 串行)。微信回包不携带配对 ID,连续调时按入队顺序消费。
|
||||
public func shareLink(_ link: ShareLink, scene: ShareScene) async throws {
|
||||
#if canImport(WechatOpenSDK)
|
||||
try await withCheckedThrowingContinuation { (cont: CheckedContinuation<Void, Error>) in
|
||||
sharePending.append(cont)
|
||||
|
||||
@@ -152,22 +141,15 @@ public final class WeChatManager: NSObject {
|
||||
case .session: req.scene = Int32(WXSceneSession.rawValue)
|
||||
case .timeline: req.scene = Int32(WXSceneTimeline.rawValue)
|
||||
}
|
||||
// 分享回包路径:用户在微信操作后由 SceneDelegate.openURLContexts →
|
||||
// WXApi.handleOpen(url:delegate:WeChatManager.shared) → onResp 到达,
|
||||
// 故 sendReq 这里不需要再传 delegate;completion=nil 让拉起失败时
|
||||
// 不打扰 sharePending 队列(队列由 onResp 的 FIFO 消费)。
|
||||
// 新版 SDK 2.x `sendReq:completion:` 替代旧 `send:`(后者 deprecated)。
|
||||
WXApi.send(req, completion: nil)
|
||||
// 1.x: sendReq BOOL 返回;分享回包通过 SceneDelegate.openURLContexts →
|
||||
// WXApi.handleOpen(url:delegate:WeChatManager.shared) → onResp 路径到达。
|
||||
WXApi.sendReq(req)
|
||||
}
|
||||
#else
|
||||
throw WeChatError.sdkNotLinked
|
||||
#endif
|
||||
}
|
||||
|
||||
/// 图片分享(FIFO 串行,复用 sharePending)。msext gameController.m:637-678
|
||||
/// type=2 截图 / type=其它 远端图 共用同一条 WXImageObject + setThumbImage 路径。
|
||||
public func shareImage(_ img: ShareImage, scene: ShareScene) async throws {
|
||||
#if canImport(WechatOpenSDK)
|
||||
try await withCheckedThrowingContinuation { (cont: CheckedContinuation<Void, Error>) in
|
||||
sharePending.append(cont)
|
||||
|
||||
@@ -186,16 +168,8 @@ public final class WeChatManager: NSObject {
|
||||
case .session: req.scene = Int32(WXSceneSession.rawValue)
|
||||
case .timeline: req.scene = Int32(WXSceneTimeline.rawValue)
|
||||
}
|
||||
// 分享回包路径:用户在微信操作后由 SceneDelegate.openURLContexts →
|
||||
// WXApi.handleOpen(url:delegate:WeChatManager.shared) → onResp 到达,
|
||||
// 故 sendReq 这里不需要再传 delegate;completion=nil 让拉起失败时
|
||||
// 不打扰 sharePending 队列(队列由 onResp 的 FIFO 消费)。
|
||||
// 新版 SDK 2.x `sendReq:completion:` 替代旧 `send:`(后者 deprecated)。
|
||||
WXApi.send(req, completion: nil)
|
||||
WXApi.sendReq(req)
|
||||
}
|
||||
#else
|
||||
throw WeChatError.sdkNotLinked
|
||||
#endif
|
||||
}
|
||||
|
||||
// MARK: - Internal: resolve callbacks
|
||||
@@ -222,7 +196,6 @@ public final class WeChatManager: NSObject {
|
||||
|
||||
// MARK: - WXApiDelegate
|
||||
|
||||
#if canImport(WechatOpenSDK)
|
||||
extension WeChatManager: WXApiDelegate {
|
||||
|
||||
public nonisolated func onReq(_ req: BaseReq) {
|
||||
@@ -245,9 +218,8 @@ extension WeChatManager: WXApiDelegate {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// MARK: - Public payload / error types(无 SDK 依赖,可在 canImport 之外使用)
|
||||
// MARK: - Public payload / error types
|
||||
|
||||
public struct WXAuthCodePayload: Sendable {
|
||||
public let code: String
|
||||
|
||||
@@ -2,18 +2,15 @@
|
||||
// WeChatSDK.swift
|
||||
// ylgamehall
|
||||
//
|
||||
// 微信 OpenSDK 启动注册。沿用 msext AppID(参 docs/SDK-Integration-Guide.md §0 凭证总表)。
|
||||
// 微信 OpenSDK 1.8.2 启动注册(与 daoqi msext 同款,避免 2.x 强制
|
||||
// Universal Link 的运维负担:HTTPS 域名 + AASA + 微信开放平台后台审核)。
|
||||
//
|
||||
// ⚠️ canImport(WechatOpenSDK) 守卫:在 Vendor/WechatSDK/WechatOpenSDK.xcframework
|
||||
// 尚未在 Xcode 中 "Frameworks, Libraries, and Embedded Content" 里 Embed & Sign 之前,
|
||||
// 本文件编译为 no-op,不影响主工程编译。Embed 后自动激活真实路径。
|
||||
// 通过 Bridging Header 导入 ObjC 头(1.x .a 静态库无 Swift module),
|
||||
// 详见 ylgamehall-Bridging-Header.h。
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
#if canImport(WechatOpenSDK)
|
||||
import WechatOpenSDK
|
||||
#endif
|
||||
import UIKit
|
||||
|
||||
@MainActor
|
||||
public enum WeChatSDK {
|
||||
@@ -22,22 +19,13 @@ public enum WeChatSDK {
|
||||
public static let appID = "wx586a9b321e56efb7"
|
||||
|
||||
/// 启动注册:在 AppDelegate.didFinishLaunchingWithOptions 调用一次。
|
||||
/// universalLink 沿用 msext 路径不走 ULAPI,传空字符串即可(与 msext 行为等价)。
|
||||
/// 1.x 单参数 registerApp,不需要 Universal Link。
|
||||
public static func register() {
|
||||
#if canImport(WechatOpenSDK)
|
||||
// 不走 Universal Links(msext 同款路径,企业签 / 超签分发场景 ULAPI 无意义)
|
||||
WXApi.registerApp(appID, universalLink: "")
|
||||
#else
|
||||
// SDK 未链接:no-op。Xcode 加完 framework 后这条分支会被替换为上面 WXApi 调用。
|
||||
#endif
|
||||
WXApi.registerApp(appID)
|
||||
}
|
||||
|
||||
/// SceneDelegate.openURLContexts 转发入口(QQ → WXApi 顺序,QQ 必须先判 — msext 硬约束)
|
||||
/// SceneDelegate.openURLContexts 转发入口。
|
||||
public static func handleOpenURL(_ url: URL) -> Bool {
|
||||
#if canImport(WechatOpenSDK)
|
||||
return WXApi.handleOpen(url, delegate: WeChatManager.shared)
|
||||
#else
|
||||
return false
|
||||
#endif
|
||||
WXApi.handleOpen(url, delegate: WeChatManager.shared)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,7 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
#if canImport(WechatOpenSDK)
|
||||
import WechatOpenSDK
|
||||
#endif
|
||||
// 微信 SDK 1.8.2 通过 Bridging Header 导入,无 import 语句
|
||||
|
||||
@MainActor
|
||||
public final class WechatShare: SharePlatform {
|
||||
@@ -23,17 +21,12 @@ public final class WechatShare: SharePlatform {
|
||||
public let name = "WeChat"
|
||||
|
||||
public var isInstalled: Bool {
|
||||
#if canImport(WechatOpenSDK)
|
||||
return WXApi.isWXAppInstalled()
|
||||
#else
|
||||
return true // 未链接 SDK 时让按钮可点,share 也只是 stub success
|
||||
#endif
|
||||
WXApi.isWXAppInstalled()
|
||||
}
|
||||
|
||||
public init() {}
|
||||
|
||||
public func share(_ content: ShareContent, scene: ShareScene) async -> ShareResult {
|
||||
#if canImport(WechatOpenSDK)
|
||||
guard WXApi.isWXAppInstalled() else {
|
||||
return .notInstalled(platform: name)
|
||||
}
|
||||
@@ -83,9 +76,5 @@ public final class WechatShare: SharePlatform {
|
||||
} catch {
|
||||
return .failed(reason: "\(error)")
|
||||
}
|
||||
#else
|
||||
// SDK 未链接:维持 Phase 4.B 的 stub 行为(让 SharePanel 流程能跑通)
|
||||
return .success
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// ylgamehall-Bridging-Header.h
|
||||
// ylgamehall
|
||||
//
|
||||
// Objective-C → Swift 桥接头文件。
|
||||
//
|
||||
// 当前唯一用途:微信 OpenSDK 1.8.2(与 daoqi msext 同款,避免 2.x 强制
|
||||
// Universal Link 的运维负担)。1.x SDK 是 .a 静态库 + 头文件,没有 Swift
|
||||
// module(不能 `import WechatOpenSDK`),必须通过 Bridging Header 导入。
|
||||
//
|
||||
// 详见 docs/SDK-Integration-Guide.md §A.1 / Vendor/WechatSDK/README.md。
|
||||
//
|
||||
|
||||
#import "WXApi.h"
|
||||
#import "WXApiObject.h"
|
||||
Reference in New Issue
Block a user