From a060f290704c8aa317270c372865b7f502b0798b Mon Sep 17 00:00:00 2001 From: joywayer Date: Tue, 23 Jun 2026 07:36:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=8E=88=E6=9D=83=E8=AF=8A?= =?UTF-8?q?=E6=96=AD=20print=EF=BC=9A=E5=AE=9A=E4=BD=8D=20H5=20=E8=B0=83?= =?UTF-8?q?=E7=94=A8=20=E2=86=92=20=E6=8B=89=E8=B5=B7=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E5=8D=A1=E5=9C=A8=E5=93=AA=E4=B8=80=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit H5 调 accreditlogin 仍无反应。加临时 print 排查链路: AccreditLoginHandler: - 入口"H5 调用命中 ✅" → 确认 WVJB 协议握手 + handler 注册 OK - canImport(WechatOpenSDK) 真值 → 确认 SDK 是否真链接进了 binary - Task @MainActor 入口 → 确认 actor hop 没卡死 - 失败分支区分用户取消(errCode -2)/ 其它 WeChatManager.authorize(): - isWXAppInstalled() → 用户手机是否真装了微信 - getVersion() → 加载的 SDK 版本字符串(验证链接的 framework) - topmostViewController() nil 检测 → present 上下文是否拿到 - sendAuthReq completion success=true/false → SDK 是否成功拉起微信 app 跑一次 H5 调 accreditlogin 看 Xcode console 输出序列,按 print 出现/缺失 精确定位卡点(H5 没调进来 / SDK 未链接 / VC 拿不到 / SDK 拉起失败)。 排查完成后可删除 print。 Co-Authored-By: Claude Opus 4.7 --- .../Source/Bridge/Handlers/AccreditLoginHandler.swift | 8 ++++++++ ylgamehall/Source/SDK/WeChat/WeChatManager.swift | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/ylgamehall/Source/Bridge/Handlers/AccreditLoginHandler.swift b/ylgamehall/Source/Bridge/Handlers/AccreditLoginHandler.swift index 2df8147..da557d8 100644 --- a/ylgamehall/Source/Bridge/Handlers/AccreditLoginHandler.swift +++ b/ylgamehall/Source/Bridge/Handlers/AccreditLoginHandler.swift @@ -21,13 +21,17 @@ public enum AccreditLoginHandler { public static func register(on bridge: any BridgeProtocol) { bridge.register("accreditlogin") { _, callback in + print("[Bridge] accreditlogin H5 调用命中 ✅") callback?(.string("Response from accreditlogin")) #if canImport(WechatOpenSDK) + print("[Bridge] accreditlogin → canImport(WechatOpenSDK)=true,启动 Task") // SDK 已链接:拉起微信授权 → 拿 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") bridge.call("sharelogin", data: .object([ // 字段名严格 1:1 contract §3.2 表 [10] / msext NewRootVC.m:2428 "openid": .string(user.openid), @@ -39,12 +43,16 @@ public enum AccreditLoginHandler { "unionid": .string(user.unionid) ]), callback: nil) } catch WeChatAuthError.userCancelled { + print("[Bridge] accreditlogin 用户取消授权(errCode -2)") // msext 行为:用户取消不弹 alert、不触发 sharelogin } catch { + print("[Bridge] accreditlogin 失败:\(error)") // 其它失败也吞下(msext 同款乐观策略:不反向通知 H5) // 后续 Phase 9 监控接入后此处可发 Sentry breadcrumb } } + #else + print("[Bridge] accreditlogin → ⚠️ canImport(WechatOpenSDK)=false,SDK 未链接,仅 stub") #endif } } diff --git a/ylgamehall/Source/SDK/WeChat/WeChatManager.swift b/ylgamehall/Source/SDK/WeChat/WeChatManager.swift index 34cf52b..a5897a9 100644 --- a/ylgamehall/Source/SDK/WeChat/WeChatManager.swift +++ b/ylgamehall/Source/SDK/WeChat/WeChatManager.swift @@ -42,6 +42,9 @@ public final class WeChatManager: NSObject { /// 旧版 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")") let state = UUID().uuidString return try await withCheckedThrowingContinuation { cont in authPending[state] = cont @@ -50,11 +53,14 @@ public final class WeChatManager: NSObject { req.state = state guard let vc = Self.topmostViewController() else { + print("[WeChat] ⚠️ topmostViewController() 返回 nil,无 present 上下文") authPending.removeValue(forKey: state) cont.resume(throwing: WeChatError.authFailed(-3)) 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 } @@ -67,6 +73,7 @@ public final class WeChatManager: NSObject { } } #else + print("[WeChat] ⚠️ canImport(WechatOpenSDK)=false") throw WeChatError.sdkNotLinked #endif }