微信授权链路诊断 print 清理
授权链路已跑通(commit 625f504),撤掉 a060f29 加的临时诊断 print
+ 本次 shim 的 install 成功日志。AccreditLoginHandler / WeChatManager /
WXOpenURLShim 三处共 13 行 print 一次性清干净,行为不变。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
625f504b85
commit
053232ed26
@@ -21,14 +21,12 @@ public enum AccreditLoginHandler {
|
|||||||
|
|
||||||
public static func register(on bridge: any BridgeProtocol) {
|
public static func register(on bridge: any BridgeProtocol) {
|
||||||
bridge.register("accreditlogin") { _, callback in
|
bridge.register("accreditlogin") { _, callback in
|
||||||
print("[Bridge] accreditlogin H5 调用命中 ✅")
|
|
||||||
callback?(.string("Response from accreditlogin"))
|
callback?(.string("Response from accreditlogin"))
|
||||||
|
|
||||||
// 拉起微信授权 → 拿 7 字段 → 反向 callback sharelogin
|
// 拉起微信授权 → 拿 7 字段 → 反向 callback sharelogin
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
do {
|
do {
|
||||||
let user = try await WeChatAuth.authorize()
|
let user = try await WeChatAuth.authorize()
|
||||||
print("[Bridge] accreditlogin 拿到 user,发 sharelogin 反向 callback")
|
|
||||||
bridge.call("sharelogin", data: .object([
|
bridge.call("sharelogin", data: .object([
|
||||||
// 字段名严格 1:1 contract §3.2 表 [10] / msext NewRootVC.m:2428
|
// 字段名严格 1:1 contract §3.2 表 [10] / msext NewRootVC.m:2428
|
||||||
"openid": .string(user.openid),
|
"openid": .string(user.openid),
|
||||||
@@ -40,10 +38,8 @@ public enum AccreditLoginHandler {
|
|||||||
"unionid": .string(user.unionid)
|
"unionid": .string(user.unionid)
|
||||||
]), callback: nil)
|
]), callback: nil)
|
||||||
} catch WeChatAuthError.userCancelled {
|
} catch WeChatAuthError.userCancelled {
|
||||||
print("[Bridge] accreditlogin 用户取消授权(errCode -2)")
|
|
||||||
// msext 行为:用户取消不弹 alert、不触发 sharelogin
|
// msext 行为:用户取消不弹 alert、不触发 sharelogin
|
||||||
} catch {
|
} catch {
|
||||||
print("[Bridge] accreditlogin 失败:\(error)")
|
|
||||||
// 其它失败也吞下(msext 同款乐观策略:不反向通知 H5)
|
// 其它失败也吞下(msext 同款乐观策略:不反向通知 H5)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,10 +33,7 @@ public enum WXOpenURLShim {
|
|||||||
installed = true
|
installed = true
|
||||||
|
|
||||||
let sel = NSSelectorFromString("openURL:")
|
let sel = NSSelectorFromString("openURL:")
|
||||||
guard let method = class_getInstanceMethod(UIApplication.self, sel) else {
|
guard let method = class_getInstanceMethod(UIApplication.self, sel) else { return }
|
||||||
print("[WXOpenURLShim] ⚠️ openURL: method not found, skip")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let block: @convention(block) (UIApplication, URL) -> Bool = { app, url in
|
let block: @convention(block) (UIApplication, URL) -> Bool = { app, url in
|
||||||
app.open(url, options: [:], completionHandler: nil)
|
app.open(url, options: [:], completionHandler: nil)
|
||||||
@@ -44,6 +41,5 @@ public enum WXOpenURLShim {
|
|||||||
}
|
}
|
||||||
let imp = imp_implementationWithBlock(block as Any)
|
let imp = imp_implementationWithBlock(block as Any)
|
||||||
method_setImplementation(method, imp)
|
method_setImplementation(method, imp)
|
||||||
print("[WXOpenURLShim] ✅ swizzled -[UIApplication openURL:] → open(_:options:completionHandler:)")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,11 +39,6 @@ public final class WeChatManager: NSObject {
|
|||||||
/// openURL 路径解耦,授权回包独立由 SDK 直接派给 delegate)
|
/// openURL 路径解耦,授权回包独立由 SDK 直接派给 delegate)
|
||||||
/// 旧版 1.x 的 `WXApi.send(req)` 已 deprecated,不传 vc/delegate 会导致 H5 调了无反应。
|
/// 旧版 1.x 的 `WXApi.send(req)` 已 deprecated,不传 vc/delegate 会导致 H5 调了无反应。
|
||||||
public func authorize() async throws -> WXAuthCodePayload {
|
public func authorize() async throws -> WXAuthCodePayload {
|
||||||
print("[WeChat] authorize() 开始")
|
|
||||||
print("[WeChat] - WXApi.isWXAppInstalled = \(WXApi.isWXAppInstalled())")
|
|
||||||
// ObjC 端 selector 是 +getApiVersion,但 Swift 编译器自动简化为 getVersion()
|
|
||||||
// (Swift 3+ ObjC name 简化规则;运行时仍调 +[WXApi getApiVersion])
|
|
||||||
print("[WeChat] - WXApi.getVersion = \(WXApi.getVersion() ?? "nil")")
|
|
||||||
let state = UUID().uuidString
|
let state = UUID().uuidString
|
||||||
return try await withCheckedThrowingContinuation { cont in
|
return try await withCheckedThrowingContinuation { cont in
|
||||||
authPending[state] = cont
|
authPending[state] = cont
|
||||||
@@ -52,15 +47,12 @@ public final class WeChatManager: NSObject {
|
|||||||
req.state = state
|
req.state = state
|
||||||
|
|
||||||
guard let vc = Self.topmostViewController() else {
|
guard let vc = Self.topmostViewController() else {
|
||||||
print("[WeChat] ⚠️ topmostViewController() 返回 nil,无 present 上下文")
|
|
||||||
authPending.removeValue(forKey: state)
|
authPending.removeValue(forKey: state)
|
||||||
cont.resume(throwing: WeChatError.authFailed(-3))
|
cont.resume(throwing: WeChatError.authFailed(-3))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
print("[WeChat] 调 sendAuthReq vc=\(type(of: vc)) scope=\(Self.authScope) state=\(state)")
|
|
||||||
// 1.x 的 sendAuthReq 返回 BOOL(同步知道是否成功拉起),无 completion
|
// 1.x 的 sendAuthReq 返回 BOOL(同步知道是否成功拉起),无 completion
|
||||||
let success = WXApi.sendAuthReq(req, viewController: vc, delegate: self)
|
let success = WXApi.sendAuthReq(req, viewController: vc, delegate: self)
|
||||||
print("[WeChat] sendAuthReq 返回 success=\(success)")
|
|
||||||
if !success {
|
if !success {
|
||||||
if let pending = authPending.removeValue(forKey: state) {
|
if let pending = authPending.removeValue(forKey: state) {
|
||||||
pending.resume(throwing: WeChatError.authFailed(-3))
|
pending.resume(throwing: WeChatError.authFailed(-3))
|
||||||
|
|||||||
Reference in New Issue
Block a user