Files
youle_app_ios_v2/ylgamehall/Source/Bridge/Handlers/AccreditLoginHandler.swift
T
joywayerandClaude Opus 4.7 053232ed26 微信授权链路诊断 print 清理
授权链路已跑通(commit 625f504),撤掉 a060f29 加的临时诊断 print
+ 本次 shim 的 install 成功日志。AccreditLoginHandler / WeChatManager /
WXOpenURLShim 三处共 13 行 print 一次性清干净,行为不变。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-23 17:24:59 +08:00

49 lines
2.1 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// AccreditLoginHandler.swift
// ylgamehall
//
// H5 → Native handleraccreditlogin — 微信授权登录
// 契约:docs/H5-Native-Contract.md §3.1 1 + §3.2 10sharelogin
//
// 完整链路(Phase 4.E):
// 1. WeChatAuth.authorize() → 拉起微信授权 + 客户端直拼 oauth2 + userinfo
// (msext NewRootVC.m:2415-2428 等价路径,沿用 AppID/AppSecret/scope)
// 2. bridge.call("sharelogin", data: 7 字段) 反向 callback
// 字段名严格 1:1 含历史包袱:`Province` 大写 P / `city` 经 danbian 去单引号
//
// ⚠️ canImport(WechatOpenSDK) 守卫:SDK 未链接前走 stub(与 Phase 4.A 一致),
// 仅响应 callback 不触发 sharelogin;项目方在 Xcode Embed & Sign 后真实路径激活。
//
import Foundation
public enum AccreditLoginHandler {
public static func register(on bridge: any BridgeProtocol) {
bridge.register("accreditlogin") { _, callback in
callback?(.string("Response from accreditlogin"))
// 拉起微信授权 → 拿 7 字段 → 反向 callback sharelogin
Task { @MainActor in
do {
let user = try await WeChatAuth.authorize()
bridge.call("sharelogin", data: .object([
// 字段名严格 1:1 contract §3.2 表 [10] / msext NewRootVC.m:2428
"openid": .string(user.openid),
"headimgurl": .string(user.headimgurl),
"nickname": .string(user.nickname),
"sex": .number(Double(user.sex)),
"city": .string(user.city),
"Province": .string(user.Province), // ← 大写 P
"unionid": .string(user.unionid)
]), callback: nil)
} catch WeChatAuthError.userCancelled {
// msext 行为:用户取消不弹 alert、不触发 sharelogin
} catch {
// 其它失败也吞下(msext 同款乐观策略:不反向通知 H5)
}
}
}
}
}