微信授权诊断 print:定位 H5 调用 → 拉起微信卡在哪一步

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 <noreply@anthropic.com>
This commit is contained in:
joywayer
2026-06-23 07:36:57 +08:00
co-authored by Claude Opus 4.7
parent 624dd93c65
commit a060f29070
2 changed files with 15 additions and 0 deletions
@@ -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
}